Jump to content
Jesse Cogswell

Creating Drawing Label with Script

Recommended Posts

Good morning.

 

I am working on a menu command that creates a series of viewports.  I decided that I wanted to add an option to drop in a Drawing Label object into the annotation layer of these viewports but have run in to a couple of snags particular to the Drawing Label PIO.

 

The first thing that I noticed was that when using CreateCustomObject to drop a Label in, the incoming label would ignore the defaults set in the Plug-in Manager.  So I added some SetRField commands to set make the label fit my defaults, namely setting the "Num Config" field to "Drawing Only" and "LineMode" to "Auto-Fit," but these didn't seem to work, either.  If I used an external script to change these later, they would change as intended.

 

I did a little digging and found the hidden field "Config," changing this to "Config 4" would set the "Num Config" to "Drawing Only," but I can't seem to find a way to get "Auto-Fit" to work on a newly placed Drawing Label.

 

I tried first setting the "Length" field to 0, using GetBBox to determine what the length needed to be and resetting the "Length" field to match, but the GetBBox only returns the coordinates of the Label's ControlPoint01 instead of the actual bounding box.

 

My guess is the the Drawing Label object has some things buried in its code using IsNewCustomObject that prevents me from changing the needed fields until after the initial script completes.  There must be some way of doing it, as the Create Viewport menu command has an option of adding a Drawing Label and it does so while following the Drawing Label defaults.

 

Any ideas?

 

- Jesse

Share this post


Link to post

IsNewCustomObject is not true when objects are placed via CreateCustomObject. 
 

I recommend exporting as script to check for hidden field settings. Also, make sure that you are doing a ResetObject after the SetRField calls. 

Share this post


Link to post

Also, new objects are not actually drawn until the script ends. That is why you can't get the bounding box because that object you are trying to get does not yet exist.

 

Also here is an old thread talking about the drawing label

 

And another

And Another one.

 

Share this post


Link to post

@Pat Stanford , all of this makes sense in terms of the use of CreateCustomObject.  Good to know that the object isn't drawn until script completion.  My issue is specific to the Drawing Label object in that it uses "hidden" parameters to set the Num Config and LineMode on object creation and ignores the PIO defaults.  I was able to find which hidden parameter affects the Num Config field, but I could not for the life of me find how to set the Line Mode to Auto-fit without having a second script run after the initial script creating the object.

 

In the end, I just set the object to have a 2" fixed length.  This is almost exactly the length needed to get the line to the end of the label's scale text, which is where the auto-fit would land anyway.  At this point, it's more of a curiosity about whether it's possible to get auto-fit to work in the object creation script.  The fact that it works if you check the "Create Drawing Label" box in the Create Viewport dialog suggests that it is indeed possible, but I don't know what kind of magic Vectorworks uses to make it happen.

Share this post


Link to post

Have you looked at my script to create a worksheet of all of the fields of a PIO? It might help you find the fields that you need. Place a pio on the design layer, leave it selected, and run the script. You will get a worksheet showing each field, the field type, and the copyable version of the record.field names that you need to use to access the fields.

 

 

 

 

Share this post


Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


 

7150 Riverwood Drive, Columbia, Maryland 21046, USA   |   Contact Us:   410-290-5114

 

© 2018 Vectorworks, Inc. All Rights Reserved. Vectorworks, Inc. is part of the Nemetschek Group.

×
×
  • Create New...