Jump to content

The Hamma

Member
  • Content Count

    153
  • Joined

  • Last visited

Posts posted by The Hamma


  1. Ok, I can use

    from VPRename_A import hVP, numberStr

    to retrieve hVP and numberStr from VPRenumb_A

     

    Now that I have that solved It does not seem to fix my issue with the script.  

     

    If I run script "VP Label (Consecutive)" from the workspace and I place "VPRenumb_A.vsm"  in the workspace and call it via "vs.DoMenuTextByName('VPRenumb_A', 0)" it actually leaves my script to run the second script and this completes without giving me any messages about renumbering the drawing labels.  

     

    If I run script "VP Label (Consecutive)" from the workspace and I place "VPRenumb_A.py"  in the plugins folder and call it via "from VPRename_A import hVP, numberStr" it actually imports the "VPRenumb_A.py" into the first script to run and this completes giving me a warning messages about renumbering the drawing labels.  

     

    Is there a way to call an external python script without running it within the first script like "vs.DoMenuTextbyName" does? Note I still need to receive or send variables to or from the second script and not all of the labels redraw correctly.

     606774933_Annotation2020-08-05101109.thumb.png.bdaa6d650ea9f4be025a1e86ceadc9cf.png1352412360_Annotation2020-08-05093443.thumb.png.c5177bd8cf75339e4ec592c7a1bcd23e.png

     

    I have attached the two versions. 

     

     

    VP Label (Consecutive) (DoMenubytextName).zip VP Label (Consecutive) (import).zip


  2. """
    This a global script that affects all sheet layers.  It classes all objects on sheet layers as follows.
    Viewport Drawing labels to class = Sheet-Label
    Viewport Annoatations to class = Sheet-Anno
    Viewports and sheet items = Sheet-Main
    Redlines remain on Notes-Redlines or A-ANNO-REDL
    
    All classes listed above are turned on on all viewports. 
    
    This Python Script may be freely distributed. No warranty provided.
    Use at your own risk.
    
    David Hamer, 2020 revision 07-31-2020
    """
    
    # collect handles of selected VPs on active layer
    def GetHandle(h):
    	if vs.GetObjectVariableInt(vs.GetLayer(h), 154) == 2:
    		if vs.GetObjectVariableString(h, 1166) != 'Redline Object':
    			vs.SetClass(h, 'Sheet-Main')
    		if vs.GetTypeN(h) == 122:
    			hVP.append(h)
    
    ACName = vs.ActiveClass()  # Record name of active class
    
    ClassCount = vs.ClassNum()  # determine number of classes in drawing
    vs.NameClass('Sheet-Main')  # Creates class if it does not exist and sets properties
    if ClassCount + 1 == vs.ClassNum(): 
    	vs.NameClass('Sheet-Main')
    	vs.SetClFillFore('Sheet-Main',0,0,0)
    	vs.SetClFillBack('Sheet-Main',0,0,0)
    	vs.SetClPenFore('Sheet-Main',65535,65535,65535)
    	vs.SetClPenBack('Sheet-Main',65535,65535,65535)
    	vs.SetClFPat('Sheet-Main',1)
    	vs.SetClLSN('Sheet-Main',2)
    	vs.SetClLW('Sheet-Main',10)
    	vs.EnableCLDropShadow('Sheet-Main',False)
    	vs.SetClUseGraphic('Sheet-Main',True)
    
    ClassCount = vs.ClassNum()  # determine number of classes in drawing	
    vs.NameClass('Sheet-Label')  # Creates class if it does not exist and sets properties
    if ClassCount + 1 == vs.ClassNum():  
    	vs.NameClass('Sheet-Label')
    	vs.ShowClass('Sheet-Label')
    	vs.SetClFillFore('Sheet-Label',0,0,0)
    	vs.SetClFillBack('Sheet-Label',0,0,0)
    	vs.SetClPenFore('Sheet-Label',65535,65535,65535)
    	vs.SetClPenBack('Sheet-Label',65535,65535,65535)
    	vs.SetClFPat('Sheet-Label',1)
    	vs.SetClLSN('Sheet-Label',2)
    	vs.SetClLW('Sheet-Label',28)
    	vs.EnableCLDropShadow('Sheet-Label',False)
    	vs.SetClUseGraphic('Sheet-Label',True)
    
    ClassCount = vs.ClassNum()  # determine number of classes in drawing	
    vs.NameClass('Sheet-Anno')  # Creates class if it does not exist and sets properties
    if ClassCount + 1 == vs.ClassNum():  
    	vs.NameClass('Sheet-Anno')
    	vs.ShowClass('Sheet-Anno')
    	vs.SetClFillFore('Sheet-Anno',0,0,0)
    	vs.SetClFillBack('Sheet-Anno',0,0,0)
    	vs.SetClPenFore('Sheet-Anno',65535,65535,65535)
    	vs.SetClPenBack('Sheet-Anno',65535,65535,65535)
    	vs.SetClFPat('Sheet-Anno',1)
    	vs.SetClLSN('Sheet-Anno',2)
    	vs.SetClLW('Sheet-Anno',10)
    	vs.EnableCLDropShadow('Sheet-Anno',False)
    	vs.SetClUseGraphic('Sheet-Anno',True)
    	
    vs.NameClass(ACName)  # Return active class
    
    hVP = []
    vs.ForEachObjectInLayer(GetHandle, 0, 2, 1)
    
    # Traverse into the annotations group of selected VPs and set classes
    for VP in hVP:
    	vs.SetVPClassVisibility(VP,'Sheet-Anno',0)
    	vs.SetVPClassVisibility(VP,'Sheet-Label',0)
    	vs.SetVPClassVisibility(VP,'Sheet-Main',0)
    	vs.SetVPClassVisibility(VP,'Notes-Redlines',0)	
    	vs.SetVPClassVisibility(VP,'A-ANNO-REDL',0)
    	anno = vs.GetVPGroup(VP, 2)
    	h = vs.FInGroup(anno)
    	objs = [h]
    	h = vs.NextObj(h)
    	while h != vs.Handle(0):
    		if vs.GetObjectVariableString(h, 1166) == 'Drawing Label':
    			vs.SetClass(h, 'Sheet-Label')
    			vs.SetLWByClass(h)
    			vs.SetFPatByClass(h)
    			vs.SetLSByClass(h)
    			vs.SetFillColorByClass(h)
    			vs.SetOpacityByClass(h)
    			vs.SetPenColorByClass(h)
    		else:
    			if vs.GetObjectVariableString(h, 1166) != 'Redline Object':
    				vs.SetClass(h, 'Sheet-Anno')
    				if vs.GetTypeN(h) == 11:
    					gobj = vs.FInGroup(h)
    					while gobj != []:
    						vs.SetClass(gobj, 'Sheet-Anno')
    						gobj = vs.NextObj(gobj)
    		h = vs.NextObj(h)

     

    • Like 1

  3. The script creates several classes at once and would not know which class to assign the selected object to. I will think about it and if any ideas come to mind I will script them down.  On another note the script above would change the settings of previously created classes created by this script when running it a second time.  I have modified the script to only create a new class if it does not exist and to give you a list of all the newly created classes when it is finished. 

     

    """
    This script identifies the name of a texture in the drawing and creates a new class with identified 
    texture assigned to the newly created class.
    This is useful so that objects can be textured by assigning them to the appropriate class. 
    
    This Python Script may be freely distributed. No warranty provided.
    Use at your own risk.
    
    If the name of the texture and the prefix exceeds 63 characters the class name will be shortened to 63 
    characters.  This is a Vectorworks class name limitation. 
    
    David Hamer, 2020 Revised 2020-07-31
    """
    
    ClassPrefix ='I-FNSH-' #Newly created classes prefix
    runtimes = 0
    
    TextureList, NumItems = vs.BuildResourceList(97, 0, '') 
    while NumItems != 0:
    	TextureName = vs.GetNameFromResourceList(TextureList, NumItems) 
    	TextureClassNameW = vs.Concat(ClassPrefix,TextureName)
    	TextureClassName = vs.Copy(TextureClassNameW, 1, 63) 
    	ClassCount = vs.ClassNum()  # determine number of classes in drawing
    	vs.NameClass(TextureClassName)
    	if ClassCount + 1 == vs.ClassNum():
    		runtimes = runtimes + 1
    		if runtimes == 1:
    			allclasses = TextureClassName
    		else:
    			allclasses = vs.Concat(allclasses, ', ', TextureClassName)
    		vs.SetClFillFore(TextureClassName,0,0,0)
    		vs.SetClFillBack(TextureClassName,0,0,0)
    		vs.SetClPenFore(TextureClassName,65535,65535,65535)
    		vs.SetClPenBack(TextureClassName,65535,65535,65535)
    		vs.SetClFPat(TextureClassName,1)
    		vs.SetClLSN(TextureClassName,2)
    		vs.SetClLW(TextureClassName,10)
    		vs.EnableCLDropShadow(TextureClassName,False)
    		vs.SetClUseGraphic(TextureClassName,True)
    		TextureIndex = vs.Name2Index(TextureName)
    		vs.SetClTextureC(TextureClassName, TextureIndex)
    		vs.SetClTextureD(TextureClassName, TextureIndex)
    		vs.SetClTextureG(TextureClassName, TextureIndex)
    		vs.SetClTextureL(TextureClassName, TextureIndex)
    		vs.SetClTextureR(TextureClassName, TextureIndex)
    		vs.SetClTextureT(TextureClassName, TextureIndex)
    		vs.SetClUseTexture(TextureClassName, True)
    	NumItems = NumItems -1
    
    if runtimes != 0:	
    	vs.AlrtDialog('New Classes Created: ', allclasses)
    else:
    	vs.AlrtDialog('No new Classes created')

     


  4. On 7/29/2020 at 12:22 PM, Pat Stanford said:

    I thought that import vs is needed to allow Python to see all of the vectroscript commands.

     

    I figured it out, if you run the python script as an external script that is imported via another script the "import vs" is needed, but when run directly from within vectorworks it is not.  

    • Like 1

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


  6. This will display each for two seconds although the watch cursor does not appear to work on windows. 

    CrossInteger = 1307
    Crossconfig = 'LgCrossC'
    vs.AlrtDialog('Hit ok to see ', CrossInteger , ' = ' , Crossconfig, ' for 2 seconds')
    vs.SetCursor(CrossInteger)
    vs.Wait(2)
    CrossInteger = 1308
    Crossconfig = 'HandC'
    vs.AlrtDialog('Hit ok to see ', CrossInteger , ' = ' , Crossconfig, ' for 2 seconds')
    vs.SetCursor(CrossInteger)
    vs.Wait(2)
    CrossInteger = 1309
    Crossconfig = 'ArrowC'
    vs.AlrtDialog('Hit ok to see ', CrossInteger , ' = ' , Crossconfig, ' for 2 seconds')
    vs.SetCursor(CrossInteger)
    vs.Wait(2)
    CrossInteger = 1310
    Crossconfig = 'SmCross'
    vs.AlrtDialog('Hit ok to see ', CrossInteger , ' = ' , Crossconfig, ' for 2 seconds')
    vs.SetCursor(CrossInteger)
    vs.Wait(2)
    CrossInteger = 1311
    Crossconfig = 'WatchC'
    vs.AlrtDialog('Hit ok to see ', CrossInteger , ' = ' , Crossconfig, ' for 2 seconds')
    vs.SetCursor(CrossInteger)
    vs.Wait(2)
    CrossInteger = 1312
    Crossconfig = 'TextBarC'
    vs.AlrtDialog('Hit ok to see ', CrossInteger , ' = ' , Crossconfig, ' for 2 seconds')
    vs.SetCursor(CrossInteger)
    vs.Wait(2)

     


  7. Yes that works. 

    Thanks for the tip.  I downloaded the SDK.  Seems like this info should be written down in a better format thank looking through an XML file. 


  8. 1 hour ago, Pat Stanford said:

    SetCursor(LgCrossC)

    The python script it does not seem to accept the variable "LgCrossC" or "ArrowC" in python 

    1 hour ago, Peter Vandewalle said:

    I would try with 0, 1, and so on

    I tried with numbers and I did not see any change in the cursor appearance. 

     

    import vs
    integer = 6
    down =False
    while integer != 0:
    	click = False #define click variable
    	pt = 0 # define pt variable
    	while not click: #waits for click
    		click, pt = vs.MouseDown() #assigns coordinates to pt
    	vs.SetCursor(integer)
    	vs.Wait(2)
    	vs.AlrtDialog(integer)
    	integer = integer - 1
    	

    Also what does the "import vs" command do?  I can't find any documentation. It doesn't seem necessary for the script to work. 


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

     


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

     


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


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


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


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

     


  15. Great Idea.  Now I can isolate it and now I can get it to run in sheet layers or veiwport annotations if they are the active layer. 

     

    """
    This script assigns selected objects to class "1_Exist-(original class)" and set Construction Phase to 'EXISTING TO REMAIN'.
    
    If a in wall object is selected without selecting the wall the script will only change those in wall objects.
    If a wall is selected it will change the wall and all objects inserted in that wall.
    If New class does not exist objects original class is duplicated to retain class attributes.
    
    To take full advantage of this script use "Data Visualization" to display the "Construction Phase"
      record objects as desired.
         1. Set "Data Visualization" to modify drawings per "Construction Phase" record
         2. To make a "Construction Phase" invisible set the attributes of that phase to:
               Line settings to Fill "Solid White" and Line weight "0"
    
    This Python Script may be freely distributed. No warranty provided.
    Use at your own risk.
    
    Vectorworks bug does not show changes to symbols inserted in wall until either:
       Drawing is saved and reopened.
       Setting in Data Visualization dialog is changed.
       Symbol is removed from wall, can then be reinserted
    
    David Hamer, 2020
    """
    
    
    # Modifications to any objects happen here
    def assign(h):
        CName = vs.GetClass(h)
        CLen = vs.Len(CName)
        CNameE = vs.Copy(CName, 1, 8)  # Grab First 8 letters of handle's class
        CNameD = vs.Copy(CName, 1, 7)  # Grab First 7 letters of handle's class
        if CNameD == '2_Demo-':  # Check if first 7 letters equal '2_Demo-'
            CName = vs.Copy(CName, 8, CLen)  # if true grab root name of class
        # check if the class is new, if so delete new class and duplicate objects class and rename.
        if CNameE == '1_Exist-':
            CNameN = CName
        else:
            CNameN = vs.Concat('1_Exist-', CName)  # If not add '1_Exist-' to name
        ClassCount = vs.ClassNum()  # determine number of classes in drawing
        vs.NameClass(CNameN)  # set the name of the class to be applied to handle if new class will be created
        if ClassCount + 1 == vs.ClassNum():  # check if the class is new and if delete new class and duplicate source
            vs.ReDraw()
            vs.DelClass(CNameN)  # Delete new class
            CHandle = vs.GetObject(CName)  # get handle to source class
            NDCHandle = vs.CreateDuplicateObject(CHandle, vs.GetParent(CHandle))  # duplicate source class
            vs.SetName(NDCHandle, CNameN)  # rename duplicate class to name to be applied to handle
            vs.ResetObject(NDCHandle)
            vs.ResetObject(h)
        vs.SetClass(h, CNameN)  # name handle's class
        vs.SetRecord(h, 'Construction Phase')  # add record to inserted object
        vs.SetRField(h, 'Construction Phase', 'Phase', 'EXISTING TO REMAIN')  # modify record to inserted object
    
    
    # Passes Handle to "def assign(h):" of PIO or Symbol selected
    def pio_processing(h):
        global container  # declare global variable to be retained
        if vs.GetObjectVariableInt(vs.GetLayer(h), 154) == activetype:
            assign(h)  # Runs "def assign(h):"
            hParent = vs.GetParent(h)  # Get Parent handle
            itParent = vs.GetTypeN(hParent)  # Get Parent type
            if itParent != []:
                if itParent == 68:  # If Parent type is a wall set container to state PIOinwallwasdetected
                    container = 'PIOinwallwasdetected'
                if itParent == 89:  # If Parent type is a round wall set container to state PIOinwallwasdetected
                    container = 'PIOinwallwasdetected'
    
    
    # Passes Handle to "def assign(h):" of every object except PIO and Symbols outside walls selected
    def object_processing(h):
    	if vs.GetObjectVariableInt(vs.GetLayer(h), 154) == activetype:
    		assign(h)  # Runs "def assign(h):"
    		h1 = vs.FIn3D(h)
    		while h1 != []:
    			if vs.GetObjectVariableInt(vs.GetLayer(h1), 154) == activetype:
    				if vs.GetTypeN(h1) == 15:
    					assign(h1)  # Runs "def assign(h):" on symbol inserted
    				if vs.GetTypeN(h1) == 86:
    					assign(h1)  # Runs "def assign(h):" on PIO inserted
    			h1 = vs.NextObj(h1)
    
    def sl_processing(h): # Omit's Viewports in Sheet Layers
    	if vs.GetTypeN(h) != 122:
    		assign(h) 
    
    
    activetype = 1
    container = 'none'  # Declare container var
    ACName = vs.ActiveClass()  # Record name of active class
    if vs.GetObject('Construction Phase') == ():  # Creates "Construction Phase" record if not present
    	vs.NewField('Construction Phase', 'Phase', '<none>', 4, 0)
    	
    if vs.GetObjectVariableInt(vs.ActLayer(), 154) == 2:
    	activetype = 2
    	vs.ForEachObjectInLayer(sl_processing, 2, 0, 0)
    else:
        # Passes Handle to "def pio_processing(h):" of PIO and Symbols selected
        vs.ForEachObject(pio_processing, "((((T=PLUGINOBJECT)|(T=SYMBOL)) & (V) & (SEL=TRUE)))")
    
        # Passes Handle to "def object_processing(h):" of objects selected except PIO and Symbols outside walls selected
        # Skipped if PIO or Symbol selected was in wall
        if container != 'PIOinwallwasdetected':
            vs.ForEachObject(object_processing, "(((T<>PLUGINOBJECT)&(T<>SYMBOL)&(T<>VIEWPORT) & (V) & (VSEL=TRUE)))")
    
    vs.NameClass(ACName)  # Return active class

     


  16. I need some help.  Apparently this script is editing objects that are selected on sheet layers even though the sheet layer is not active.  Does anyone know how to limit the selection to just the viewable and editable layers.  I thought about using ForEachObjectInLayer but it does not work for symbols and PIO in walls. 

     

    """
    This script assigns selected objects to class "1_Exist-(original class)" and set Construction Phase to 'EXISTING TO REMAIN'.
    
    If a in wall object is selected without selecting the wall the script will only change those in wall objects.
    If a wall is selected it will change the wall and all objects inserted in that wall.
    If New class does not exist objects original class is duplicated to retain class attributes.
    
    To take full advantage of this script use "Data Visualization" to display the "Construction Phase"
      record objects as desired.
         1. Set "Data Visualization" to modify drawings per "Construction Phase" record
         2. To make a "Construction Phase" invisible set the attributes of that phase to:
               Line settings to Fill "Solid White" and Line weight "0"
    
    This Python Script may be freely distributed. No warranty provided.
    Use at your own risk.
    
    Vectorworks bug does not show changes to symbols inserted in wall until either:
       Drawing is saved and reopened.
       Setting in Data Visualization dialog is changed.
       Symbol is removed from wall, can then be reinserted
    
    David Hamer, 2020
    """
    
    
    # Modifications to any objects happen here
    def assign(h):
        CName = vs.GetClass(h)
        CLen = vs.Len(CName)
        CNameE = vs.Copy(CName, 1, 8)  # Grab First 8 letters of handle's class
        CNameD = vs.Copy(CName, 1, 7)  # Grab First 7 letters of handle's class
        if CNameD == '2_Demo-':  # Check if first 7 letters equal '2_Demo-'
            CName = vs.Copy(CName, 8, CLen)  # if true grab root name of class
        # check if the class is new, if so delete new class and duplicate objects class and rename.
        if CNameE == '1_Exist-':
            CNameN = CName
        else:
            CNameN = vs.Concat('1_Exist-', CName)  # If not add '1_Exist-' to name
        ClassCount = vs.ClassNum()  # determine number of classes in drawing
        vs.NameClass(CNameN)  # set the name of the class to be applied to handle if new class will be created
        if ClassCount + 1 == vs.ClassNum():  # check if the class is new and if delete new class and duplicate source
            vs.ReDraw()
            vs.DelClass(CNameN)  # Delete new class
            CHandle = vs.GetObject(CName)  # get handle to source class
            NDCHandle = vs.CreateDuplicateObject(CHandle, vs.GetParent(CHandle))  # duplicate source class
            vs.SetName(NDCHandle, CNameN)  # rename duplicate class to name to be applied to handle
            vs.ResetObject(NDCHandle)
            vs.ResetObject(h)
        vs.SetClass(h, CNameN)  # name handle's class
        vs.SetRecord(h, 'Construction Phase')  # add record to inserted object
        vs.SetRField(h, 'Construction Phase', 'Phase', 'EXISTING TO REMAIN')  # modify record to inserted object
    
    
    # Passes Handle to "def assign(h):" of PIO or Symbol selected
    def pio_processing(h):
        global container  # declare global variable to be retained
        assign(h)  # Runs "def assign(h):"
        hParent = vs.GetParent(h)  # Get Parent handle
        itParent = vs.GetTypeN(hParent)  # Get Parent type
        if itParent != []:
            if itParent == 68:  # If Parent type is a wall set container to state PIOinwallwasdetected
                container = 'PIOinwallwasdetected'
            if itParent == 89:  # If Parent type is a round wall set container to state PIOinwallwasdetected
                container = 'PIOinwallwasdetected'
    
    
    # Passes Handle to "def assign(h):" of every object except PIO and Symbols outside walls selected
    def object_processing(h):
        assign(h)  # Runs "def assign(h):"
        h1 = vs.FIn3D(h)
        while h1 != []:
            if vs.GetTypeN(h1) == 15:
                assign(h1)  # Runs "def assign(h):" on symbol inserted
            if vs.GetTypeN(h1) == 86:
                assign(h1)  # Runs "def assign(h):" on PIO inserted
            h1 = vs.NextObj(h1)
    
    
    container = 'none'  # Declare container var
    ACName = vs.ActiveClass()  # Record name of active class
    
    if vs.GetObject('Construction Phase') == ():  # Creates "Construction Phase" record if not present
        vs.NewField('Construction Phase', 'Phase', '<none>', 4, 0)
    
    # Passes Handle to "def pio_processing(h):" of PIO and Symbols selected
    vs.ForEachObject(pio_processing, "((((T=PLUGINOBJECT)|(T=SYMBOL)) & (V) & (SEL=TRUE)))")
    
    # Passes Handle to "def object_processing(h):" of objects selected except PIO and Symbols outside walls selected
    # Skipped if PIO or Symbol selected was in wall
    if container != 'PIOinwallwasdetected':
        vs.ForEachObject(object_processing, "(((T<>PLUGINOBJECT)&(T<>SYMBOL) & (V) & (VSEL=TRUE)))")
    
    vs.NameClass(ACName)  # Return active class
     

  17. Script has been modified to detect if Design Layers or Sheet Layer is active and Isolate modifications to the active layer type.  Also added the ability to modify objects within a Sheet Layer or Sheet Layer VP annotations.  Note that classes will need to be enabled in VP dialog after running script in VP annotations otherwise they may be hidden.  Only works on objects inserted in walls when design layer is active. 

     

    """
    This script assigns selected objects to class "1_Exist-(original class)" and set Construction Phase to 'EXISTING TO REMAIN'.
    
    If a in wall object is selected without selecting the wall the script will only change those in wall objects.
    If a wall is selected it will change the wall and all objects inserted in that wall.
    If New class does not exist objects original class is duplicated to retain class attributes.
    
    To take full advantage of this script use "Data Visualization" to display the "Construction Phase"
      record objects as desired.
         1. Set "Data Visualization" to modify drawings per "Construction Phase" record
         2. To make a "Construction Phase" invisible set the attributes of that phase to:
               Line settings to Fill "Solid White" and Line weight "0"
    
    This Python Script may be freely distributed. No warranty provided.
    Use at your own risk.
    
    Vectorworks bug does not show changes to symbols inserted in wall until either:
       Drawing is saved and reopened.
       Setting in Data Visualization dialog is changed.
       Symbol is removed from wall, can then be reinserted
    
    David Hamer, 2020 revision 07-15-2020
    """
    
    # Modifications to any objects happen here
    def assign(h):
        CName = vs.GetClass(h)
        CLen = vs.Len(CName)
        CNameE = vs.Copy(CName, 1, 8)  # Grab First 8 letters of handle's class
        CNameD = vs.Copy(CName, 1, 7)  # Grab First 7 letters of handle's class
        if CNameD == '2_Demo-':  # Check if first 7 letters equal '2_Demo-'
            CName = vs.Copy(CName, 8, CLen)  # if true grab root name of class
        # check if the class is new, if so delete new class and duplicate objects class and rename.
        if CNameE == '1_Exist-':
            CNameN = CName
        else:
            CNameN = vs.Concat('1_Exist-', CName)  # If not add '1_Exist-' to name
        ClassCount = vs.ClassNum()  # determine number of classes in drawing
        vs.NameClass(CNameN)  # set the name of the class to be applied to handle if new class will be created
        if ClassCount + 1 == vs.ClassNum():  # check if the class is new and if delete new class and duplicate source
            vs.ReDraw()
            vs.DelClass(CNameN)  # Delete new class
            CHandle = vs.GetObject(CName)  # get handle to source class
            NDCHandle = vs.CreateDuplicateObject(CHandle, vs.GetParent(CHandle))  # duplicate source class
            vs.SetName(NDCHandle, CNameN)  # rename duplicate class to name to be applied to handle
            vs.ResetObject(NDCHandle)
            vs.ResetObject(h)
        vs.SetClass(h, CNameN)  # name handle's class
        vs.SetRecord(h, 'Construction Phase')  # add record to inserted object
        vs.SetRField(h, 'Construction Phase', 'Phase', 'EXISTING TO REMAIN')  # modify record to inserted object
    
     # Passes Handle to "def assign(h):" of PIO or Symbol selected
    def pio_processing(h):
        global container  # declare global variable to be retained
        if vs.GetObjectVariableInt(vs.GetLayer(h), 154) == activetype:
            assign(h)  # Runs "def assign(h):"
            hParent = vs.GetParent(h)  # Get Parent handle
            itParent = vs.GetTypeN(hParent)  # Get Parent type
            if itParent != []:
                if itParent == 68:  # If Parent type is a wall set container to state PIOinwallwasdetected
                    container = 'PIOinwallwasdetected'
                if itParent == 89:  # If Parent type is a round wall set container to state PIOinwallwasdetected
                    container = 'PIOinwallwasdetected'
    
    # Passes Handle to "def assign(h):" of every object except PIO and Symbols outside walls selected
    def object_processing(h):
    	if vs.GetObjectVariableInt(vs.GetLayer(h), 154) == activetype:
    		assign(h)  # Runs "def assign(h):"
    		h1 = vs.FIn3D(h)
    		while h1 != []:
    			if vs.GetObjectVariableInt(vs.GetLayer(h1), 154) == activetype:
    				if vs.GetTypeN(h1) == 15:
    					assign(h1)  # Runs "def assign(h):" on symbol inserted
    				if vs.GetTypeN(h1) == 86:
    					assign(h1)  # Runs "def assign(h):" on PIO inserted
    			h1 = vs.NextObj(h1)
    
    def sl_processing(h): # Omit's Viewports in Sheet Layers
    	if vs.GetTypeN(h) != 122:
    		assign(h) 
    
    activetype = 1
    container = 'none'  # Declare container var
    ACName = vs.ActiveClass()  # Record name of active class
    if vs.GetObject('Construction Phase') == ():  # Creates "Construction Phase" record if not present
    	vs.NewField('Construction Phase', 'Phase', '<none>', 4, 0)
    	
    if vs.GetObjectVariableInt(vs.ActLayer(), 154) == 2:
    	activetype = 2
    	vs.ForEachObjectInLayer(sl_processing, 2, 0, 0)
    else:
        # Passes Handle to "def pio_processing(h):" of PIO and Symbols selected
        vs.ForEachObject(pio_processing, "((((T=PLUGINOBJECT)|(T=SYMBOL)) & (V) & (SEL=TRUE)))")
    
        # Passes Handle to "def object_processing(h):" of objects selected except PIO and Symbols outside walls selected
        # Skipped if PIO or Symbol selected was in wall
        if container != 'PIOinwallwasdetected':
            vs.ForEachObject(object_processing, "(((T<>PLUGINOBJECT)&(T<>SYMBOL)&(T<>VIEWPORT) & (V) & (VSEL=TRUE)))")
    
    vs.NameClass(ACName)  # Return active class

     

 

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