Jump to content
Developer Wiki and Function Reference Links ×

pref # for Automatic Drawing Coordination


Recommended Posts

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()

 

Link to comment

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
Link to comment

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 

Link to comment

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.  

Link to comment

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

Link to comment

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.

Link to comment
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

 

Link to comment

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 'VPRenumb_A'
'VPRenumb_A' script needs to be added to the active workspace for 'VP Label (Consecutive)' to work properly

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

Revised for VW 2021

David Hamer, 2020 revision 09-19-2020
"""
hVP = []
numberStr = ''
vs.SetPref(544, 0) #turns of Auto Drawing coordination
vs.DoMenuTextByName('VPRenumb_A', 0)
#vs.Rpstr_RemoveValues()
#import VPRenumb_A
#from VPRenumb_A import hVP, numberStr

for DL in hVP: #defines handle DL as object of group hVP in order. 
    #vs.SetRField(DL,'Drawing Label','Drawing',numberStr) #VW 2020 Version sets the drawing label to the current active number in sequence
    vs.SetRField(DL,'Drawing Label2','Drawing',numberStr) #VW 2021 Version 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 "VPRenumb_A"

"""
Script Name: VPRenumb_A

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
"""
import vs
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
vs.SetCursor(1307)
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
	if vs.GetTypeN(h) == 122: #if h is a viewport
		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
Link to comment
  • 2 weeks later...

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.

×
×
  • Create New...