Jesse Cogswell Posted July 14, 2020 Share Posted July 14, 2020 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 Quote Link to comment
JBenghiat Posted July 14, 2020 Share Posted July 14, 2020 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. Quote Link to comment
Pat Stanford Posted July 16, 2020 Share Posted July 16, 2020 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. Quote Link to comment
Jesse Cogswell Posted July 16, 2020 Author Share Posted July 16, 2020 @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. Quote Link to comment
Pat Stanford Posted July 17, 2020 Share Posted July 17, 2020 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. Quote Link to comment
Recommended Posts
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.