Jump to content
The Hamma

pref # for Automatic Drawing Coordination

Recommended Posts

Does anyone know what the Pref # is for Automatic Drawing Coordination?  I can't seem to find it in the appendix. 

Share this post


Link to post

Thanks that was it but for some reason when I turn it off in the script it still acts like it is on.  I checked and it is setting the preference off and then back to the prescript state at the end. 

#script to renumber drawing labels contained within VP annotations in order picked by mouse. 

autocoord = vs.GetPref(544)
vs.SetPref(544, 0)
hVP = []
numberStr = vs.StrDialog('Enter and INTEGER to start numbering:','1')
vs.Message('Click in empty space to end Label Numbering')
h = 1
while h != 0:
	click = False
	while not(click):
		click, pt = vs.MouseDown()
	h = vs.PickObject(pt)
	anno = vs.GetVPGroup(h, 2)
	h1 = vs.FInGroup(anno)
	objs = [h1]
	h1 = vs.NextObj(h1)
	while h1 != vs.Handle(0):
		if vs.GetObjectVariableString(h1, 1166) == 'Drawing Label':
			hVP.append(h1)
		h1 = vs.NextObj(h1)

for DL in hVP:
	vs.SetRField(DL,'Drawing Label','Drawing',numberStr)
	vpNumber = vs.Str2Num(numberStr) # {convert number string to number}
	numberStr = vs.Num2Str(0, vpNumber + 1) #{increment number then convert number to string}

vs.SetPref(544, autocoord)
vs.ClrMessage()

 

Share this post


Link to post

To date I have only ever read this value and never tried to write to it. That said, this seems to work for toggling the setting on or off using Vectorscript:

 

SetPref(544, NOT GetPref(544));

 

Perhaps someone else with Python knowledge can spot something in your script.

Share this post


Link to post

SetPref is looking for a Boolean not an integer. Is it possible that your SetPref(544,0) is not being interpreted as a boolean? Maybe SetPref(544, False) or the Python equivalent?

Share this post


Link to post
Posted (edited)

In this instance 1=true and 0=false.  This simple script will turn if off the Automatic Drawing Coordination. 

 

vs.SetPref(544, 0)

This one will turn it on.

vs.SetPref(544, 1)

 

If I run the first script prior to running the script mentioned in the previous post I have no issue but if I try to disable it during the script it does not register as being off. 
 

Edited by The Hamma

Share this post


Link to post

Perhaps it is because the DrawingLabels update after your script finishes, in which case you have already reset the Automatic Drawing Coordination back before any DrawingLabel code runs. If this is the case, I don't know of a way to get around it in one script.

 

Raymond 

Share this post


Link to post

Raymond: 

I think you are right.  I guess there is no way to run a script that calls another script and lets it finish then finishes the script that called it. The only other option I suppose is to have three scripts. One to turn off Auto DC, this script, and one script to turn it back on.  It wouldn't be a problem if it was just the confirmation message you get at the end of the script.  The issue is that some of the labels do not display correctly after modifying the number and you have to edit the annotations and move them so they refresh.  And since the issue arises after the script I can't fix them in the script.  I could possibly right a script to refresh the Drawing labels that could be run after this script.  

Share this post


Link to post

Below are the before and after images of what the script above does.  As you can see in picture two not all of the drawing labels redraw correctly after running the script. The third picture is after running the "Reset All Plug-ins" command under tools/Utilities.   The following script does not work to reset the drawing labels.  Is there  a script command that works like the "Reset All Plug-ins" command but only on the plugins that you select or call by the script?

 

def redraweachobj(h):
	vs.ResetObject(h)
	

vs.ForEachObjectInLayer(redraweachobj, 0, 1, 4)

1457719221_Annotation2020-07-19093833.thumb.png.0fc44646d29770618cab37884c6ecda3.png2006771014_Annotation2020-07-19093900.thumb.png.9ee0e87bc1b42adb5c3f4a33d515f6cf.png804317597_Annotation2020-07-19094010.thumb.png.c4f30eaa569776346702c67834b0e377.png

Share this post


Link to post

The first thing I would try is to run your script twice and see if that solved the problem.

 

My complete WAG is that things are getting reset out of order with your script and so when the "container" PIO resets, the data for the "contained" PIO has not yet been reset and is passing bad data.

 

You could also use a version of your script by use ForEachObject and specify the criteria instead of ForEachObjectInLayer.

Share this post


Link to post
19 hours ago, Pat Stanford said:

getting reset out of order

I was really exited when I read this.  I edited the script so it would number the drawing labels in reverse order but no luck same bug.  I also tried a script version where it would run the "for DL in hVP" twice and set a dummy number the first run through and then set the specified number on the second run through but yet again same bug.  It seems that it is setting them in its own order when it exits the script and if it the number is being used by another viewport when it sets the current viewport then it bugs out. 

 

#script to renumber drawing labels contained within VP annotations in order picked by mouse. 

vs.SetPref(544, 0) #turns of Auto Drawing coordination
hVP = [] #defines list hVP
numberStr = vs.StrDialog('Enter and INTEGER to start numbering:','1') #ask user for starting number
vs.Message('Click in empty space to end Label Numbering') #displays message
vpNumber = vs.Str2Num(numberStr) #convert number string to text. 
vpNumber = (vpNumber-1) #Subtract one number from the starting number as it will be added back in while command
h = 1 #defines h as 1 so while command will start
while h != 0: #waits for h to have no handle
    click = False #define click variable
    pt = 0 # define pt variable
    while not click: #waits for click
        click, pt = vs.MouseDown() #assigns coordinates to pt
    h = vs.PickObject(pt) #selects the viewport at the click point
    anno = vs.GetVPGroup(h, 2) #creates group from annotations of selected viewport
    h1 = vs.FInGroup(anno) #selects the first object in the anno group
    h1 = vs.NextObj(h1) #selects the next object in the anno group
    while h1 != vs.Handle(0): # steps through every object in the viewport selected by the click
        if vs.GetObjectVariableString(h1, 1166) == 'Drawing Label': #if veiwport object is a drawing label
            hVP.append(h1) #if step 1 - add to hVP list
            vpNumber = (vpNumber+1) #if step 2 - Add a number to the numbering sequence. 
        h1 = vs.NextObj(h1) #get next object in viewport

numberStr = vs.Num2Str(0, vpNumber) #converts the number sequence back to a string

for DL in reversed(hVP): #defines handle DL as object of group hVP in reverse order. 
    vs.SetRField(DL,'Drawing Label','Drawing',numberStr) #sets the drawing label to the current active number in sequence
    vpNumber = vs.Str2Num(numberStr) # convert number string to number.
    numberStr = vs.Num2Str(0, vpNumber - 1) #subtract number from sequence then convert number to string.

vs.SetPref(544, 1) #turns on Auto Drawing coordination
vs.ClrMessage() #clears the message

 

Share this post


Link to post
Posted (edited)

Ok so it appears if you run a second script from within a first script using the "vs.DoMenuTextByName('Name', 0)" command the variables from the first script are not passed to the second script called but the variables in the second script are passed to the first script.  So what I did was create two scripts. The first script renumbers the viewports that were pick selected by the second script.   To make this work you have to add the second script to the workspace.  This works with no errors. 

 

First script named "VP Label (Consecutive)"

"""
Script Name: VP Label (Consecutive)

This script will renumber drawing labels contained within VP annotations in order picked by mouse. 
This script is dependent on pytyon script 'TempDLNo(DoNotRun)'
'TempDLNo(DoNotRun)' script needs to be added to the active workspace for 'VP Label (Consecutive)' to work properly

'TempDLNo(DoNotRun)' passes variables 'hVP' and 'numberStr' to 'VP Label (Consecutive)'

David Hamer, 2020 revision 07-20-2020
"""

vs.SetPref(544, 0) #turns of Auto Drawing coordination
vs.DoMenuTextByName('TempDLNo(DoNotRun)', 0)
numberStr = vs.Num2Str(0, vpNumber) #converts the number sequence back to a string


for DL in hVP: #defines handle DL as object of group hVP in order. 
    vs.SetRField(DL,'Drawing Label','Drawing',numberStr) #sets the drawing label to the current active number in sequence
    vpNumber = vs.Str2Num(numberStr) # convert number string to number.
    numberStr = vs.Num2Str(0, vpNumber + 1) #subtract number from sequence then convert number to string.


vs.SetPref(544, 1) #turns on Auto Drawing coordination
vs.ClrMessage() #clears the message

Second script named "TempDLNo(DoNotRun)"

"""
Script Name: TempDLNo(DoNotRun)

This is a dependent pytyon script for 'VP Label (Consecutive)'
This script needs to be added to the active workspace for 'VP Label (Consecutive)' to work properly

This script should not be run on its own. 

variables 'hVP' and 'numberStr' are required by 'VP Label (Consecutive)'

David Hamer, 2020 revision 07-20-2020
"""

numberStr = vs.StrDialog('Enter and INTEGER to start numbering:','1') #ask user for starting number
vs.Message('Click in empty space to end Label Numbering') #displays message
vpNumber = vs.Str2Num(numberStr) #convert number string to text. 
hVP = [] #defines list hVP
h = 1 #defines h as 1 so while loop will start
while h != 0: #loops until h has no handle
    click = False #define click variable
    pt = 0 # define pt variable
    while not click: #waits for click
        click, pt = vs.MouseDown() #assigns coordinates to pt
    h = vs.PickObject(pt) #selects the viewport at the click point
    anno = vs.GetVPGroup(h, 2) #creates group from annotations of selected viewport
    h1 = vs.FInGroup(anno) #selects the first object in the anno group
    while h1 != vs.Handle(0): # steps through every object in the viewport selected by the click
        if vs.GetObjectVariableString(h1, 1166) == 'Drawing Label': #if veiwport object is a drawing label
            hVP.append(h1) #if step 1 - add to hVP list
        h1 = vs.NextObj(h1) #get next object in viewport

 

Edited by The Hamma

Share this post


Link to post

I was able to modify the script to use the second script as an external script that does not need to be added to the menu.   See attached. 

 

Add both of the following files to your plugin folder and add the "VP Label (Consecutive).vsm" script to your workspace. 

VP Label (Consecutive).vsm

TempDLNo_DoNotRun.py

 

BTW when writing an external python script you do need to us the 'import vs' in the beginning of the script. 

 

 

 

Viewport Drawing Label Renumbering Script.zip

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...