Jump to content
Developer Wiki and Function Reference Links ×

Script to add or modify selected objects records


Recommended Posts

I made this script to apply a record to items selected.  The goal is the following:

If object in wall is selected add and change record to the object in the wall only. (works as designed)

If wall is selected add and change record to the wall and all objects inserted in the wall. (Only changes the wall not the inserted objects)

#set global variable
container = 'none'

def SetPIOAttribute(h):   
		global container #declare global variable to be retained
		vs.SetRecord(h,'Construction Phase') #add record to inserted object
		vs.SetRField(h,'Construction Phase','Phase','New') #modify record to inserted object
		itChild = vs.GetTypeN(h) #Get Child type (not necessary)
		hParent = vs.GetParent(h) #Get Parent handle
		itParent = vs.GetTypeN(hParent)#Get Parent type 
		if itParent == 68: #If Parent type is a wall set container to state PIOinwallwasdetected
			container = 'PIOinwallwasdetected'

#Add and change record of wall and inserted items (only changes wall at this time) 
def SetAttribute(h):
	vs.SetRecord(h,'Construction Phase')
	vs.SetRField(h,'Construction Phase','Phase','New')


vs.ForEachObject(SetPIOAttribute, "((NOTINDLVP & NOTINREFDLVP & ((PON='Door')|(T=SYMBOL)|(PON='Window')) & (V) & (SEL=TRUE)))")
#If PIO was selected and wall was not then container var PIOinwallwasdetected is true then script will end if not then wall was selected and script will continue to def SetAttribute
if container != 'PIOinwallwasdetected': 
	vs.ForEachObject(SetAttribute, "((NOTINDLVP & NOTINREFDLVP & (V) & (SEL=TRUE)))")
	

 

Edited by The Hamma
Link to comment

Just to make this more fun, I am going to throw some Vectorscript in here.  ;-)

 

I think you need to approach this from the other direction. If the selected object is a wall, then you need to use Fin3D to find the objects in the wall and then attach the records to them.

 

Create a new file with a single wall and a door (or multiple doors/windows/symbols) and leave the wall selected and run the following script.

 

After a "few" (I think it will depend on the wall styles how many object you will see), eventually you will come up with an object of Type 86 (Plug-in Object) or 15 (Symbol). You may need to check more thoroughly if they are doors or windows, but at least you will have a handle to the PIOs in the wall and can determine if you want to attach your record or not.

 

Ask again if you need more help.

 

Procedure Test;

Var	H1: Handle;

Begin
	H1:=Fin3D(FSActLayer);
	While H1 <> Nil do
		Begin
			ALrtDialog(Concat(GetTypeN(H1)));
			H1:=NextObj(H1);
		End;
End;

Run(Test);

 

Link to comment
19 hours ago, Pat Stanford said:

Just to make this more fun, I am going to throw some Vectorscript in here. 😉

 

I added your script to mine and it works great but I think I found a Vectorworks bug. 

 

This is a view of a wall with objects after running the script on the symbol in the wall.  As you can see in the record the phase has been changed to Existing but the appearance still shows as New. 

image.thumb.png.2c015dd18a9ae0280d0d3e407e29c926.png

 

Now if I change the Object Criteria in the Data Visualization or close and reopen the drawing the symbol in wall will appear correctly.  I have set my graphic settings up and down with no change.  PIO object change fine, I only have this issue with symbols in wall and the issue is not isolated to the script.  If I change the phase manually I have the same issue. 

image.thumb.png.d4efe36f278815fd671e8442e2cd4239.png

 

container = 'none' #set global variable
phase = 'Existing'

def SetPIOAttribute(h):   
		global container #declare global variable to be retained
		vs.SetRecord(h,'Construction Phase') #add record to inserted object
		vs.SetRField(h,'Construction Phase','Phase', phase) #modify record to inserted object
		itChild = vs.GetTypeN(h) #Get Child type (not necessary)
		hParent = vs.GetParent(h) #Get Parent handle
		itParent = vs.GetTypeN(hParent) #Get Parent type 
		#If Parent type is a wall set container to state PIOinwallwasdetected
		if itParent == 68: 
			container = 'PIOinwallwasdetected'

#Add and change record of wall and inserted items (only changes wall at this time) 
def SetAttribute(h):
	vs.SetRecord(h,'Construction Phase')
	vs.SetRField(h,'Construction Phase','Phase', phase)

vs.ForEachObject(SetPIOAttribute, "((NOTINDLVP & NOTINREFDLVP & ((PON='Door')|(T=SYMBOL)|(PON='Window')) & (V) & (SEL=TRUE)))")
#If PIO was selected and wall was not then container var PIOinwallwasdetected is true then script will end if not then wall was selected and script will continue to def SetAttribute
if container != 'PIOinwallwasdetected': 
	h1 = vs.FIn3D(vs.FSActLayer())
	while h1 != ():
		if vs.GetTypeN(h1) == 15:
			vs.SetRecord(h1,'Construction Phase')
			vs.SetRField(h1,'Construction Phase','Phase', phase)
		if vs.GetTypeN(h1) == 86:
			vs.SetRecord(h1,'Construction Phase')
			vs.SetRField(h1,'Construction Phase','Phase', phase)
		h1=vs.NextObj(h1)
	vs.ForEachObject(SetAttribute, "((NOTINDLVP & NOTINREFDLVP & (V) & (SEL=TRUE)))")	

 

 

Edited by The Hamma
Link to comment

That is the way symbols work. They are always drawn the same as the definition.

 

Three possible ways to overcome this:

 

1. Make all the attributes in they symbol By Class and when you change the phase also change the class that the symbol (and the component parts) are in.

 

2. Create your symbols as "Blue" symbols by checking the Convert to Group button in the Symbol Insertion Options. Then you have a symbol so it can be accessed from the Resource Manager, but it converts to a group when inserted in the drawing so that you can change the attributes. The down side to this is that it is a group and not a symbol and you can't change every instance in the drawing by editing the symbol.

 

3. Make Plug-in Objects instead of symbols and have them change attributes when the phase changes.

 

 

Link to comment

Not inserting the symbol in the wall or using PIO seems to be the best course of action.  The symbols visualization works fine if is not nested in a wall.  If it is nested I can remove it and re-nest it and the visualization works fine.   I still think this is a glitch since it just takes some sort of refresh to make it work.  That being said vs.redrawall() does not work (it actually causes every item changed not to refresh).  For the most part I think I can work around it but it a bit aggravating. 

Link to comment

I thought it was working perfectly but it does if I select one wall at a time.  In that instance it will change the wall and all the PIO objects within but If I select several walls it does not edit all of the PIO objects, it only edits the PIO in the first item selected. 

 

container = 'none' #set global variable
phase = 'Existing'

def SetPIOAttribute(h):   
		global container #declare global variable to be retained
		vs.SetRecord(h,'Construction Phase') #add record to inserted object
		vs.SetRField(h,'Construction Phase','Phase', phase) #modify record to inserted object
		itChild = vs.GetTypeN(h) #Get Child type (not necessary)
		hParent = vs.GetParent(h) #Get Parent handle
		itParent = vs.GetTypeN(hParent) #Get Parent type 
		#If Parent type is a wall set container to state PIOinwallwasdetected
		if itParent == 68: 
			container = 'PIOinwallwasdetected'


#Add and change record of wall and inserted items (only changes wall at this time) 
def SetAttribute(h):
	vs.SetRecord(h,'Construction Phase')
	vs.SetRField(h,'Construction Phase','Phase', phase)
	h1 = vs.FIn3D(vs.FSActLayer())
	while h1 != ():
		vs.SetRecord(h1,'Construction Phase')
		vs.SetRField(h1,'Construction Phase','Phase', phase)
		h1=vs.NextObj(h1)



vs.ForEachObject(SetPIOAttribute, "((NOTINDLVP & NOTINREFDLVP & ((PON='Door')|(T=SYMBOL)|(PON='Window')) & (V) & (SEL=TRUE)))")
#If PIO was selected and wall was not then container var PIOinwallwasdetected is true then script will end if not then wall was selected and script will continue to def SetAttribute
if container != 'PIOinwallwasdetected': 
	vs.ForEachObject(SetAttribute, "((NOTINDLVP & NOTINREFDLVP & (V) & (SEL=TRUE)))")	

 

Link to comment

 

13 hours ago, Pat Stanford said:

You need to change the FSActLayer to a loop that will step through each wall and do the FIn3D on each wall.

 

 

 

LOL or just change FSActLayer to h.  I didn't even stop to think about that.  I was assuming that FSActLayer was passing the handle from :

def SetAttribute(h):

 

container = 'none' #set global variable
phase = 'Demo'

def SetPIOAttribute(h):   
		global container #declare global variable to be retained
		vs.SetRecord(h,'Construction Phase') #add record to inserted object
		vs.SetRField(h,'Construction Phase','Phase', phase) #modify record to inserted object
		itChild = vs.GetTypeN(h) #Get Child type (not necessary)
		hParent = vs.GetParent(h) #Get Parent handle
		itParent = vs.GetTypeN(hParent) #Get Parent type 
		#If Parent type is a wall set container to state PIOinwallwasdetected
		if itParent == 68: 
			container = 'PIOinwallwasdetected'


#Add and change record of wall and PIO or symbols inserted in wall  
def SetAttribute(h):
	vs.SetRecord(h,'Construction Phase')
	vs.SetRField(h,'Construction Phase','Phase', phase)
	h1 = vs.FIn3D(h)
	while h1 != ():
		if vs.GetTypeN(h1) == 15:
			vs.SetRecord(h1,'Construction Phase')
			vs.SetRField(h1,'Construction Phase','Phase', phase)
		if vs.GetTypeN(h1) == 86:
			vs.SetRecord(h1,'Construction Phase')
			vs.SetRField(h1,'Construction Phase','Phase', phase)
		h1=vs.NextObj(h1)

vs.ForEachObject(SetPIOAttribute, "((NOTINDLVP & NOTINREFDLVP & ((PON='Door')|(T=SYMBOL)|(PON='Window')) & (V) & (SEL=TRUE)))")
#If PIO was selected and wall was not then container var PIOinwallwasdetected is true then script will end if not then wall was selected and script will continue to def SetAttribute
if container != 'PIOinwallwasdetected': 

	vs.ForEachObject(SetAttribute, "((NOTINDLVP & NOTINREFDLVP & (V) & (SEL=TRUE)))")	

 

Edited by The Hamma
Link to comment

Below are the final results:

Three scripts to assigns selected objects to class "1_Exist-(original class)", "2_Demo-(original class)" , or original class and set Construction Phase Existing, Demo, or New

 

"""
This script assigns selected objects to class "1_Exist-(original class)" and set Construction Phase to Existing.

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')  # 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) & (SEL=TRUE)))")

vs.NameClass(ACName)  # Return active class
"""
This script assigns selected objects to class "2_Demo-(original class)" and set Construction Phase to Demo.

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 CNameE == '1_Exist-':  # Check if first 8 letters equal '1_Exist-'
        CName = vs.Copy(CName, 9, CLen)  # if true grab root name of class
    if CNameD == '2_Demo-':  # Check if first 7 letters equal '2_Demo-' if so retain name
        CNameN = CName
    else:
        CNameN = vs.Concat('2_Demo-', CName)  # If not add '2_Demo-' 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', 'Demo')  # 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) & (SEL=TRUE)))")

vs.NameClass(ACName)  # Return active class
"""
This script assigns selected objects to class "(original class)" and set Construction Phase to New

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)
	CNameN = 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-'
		CNameN=vs.Copy(CName,8,CLen) # if true grab root name of class
	if CNameE=='1_Exist-': #Check if first 8 letters equal '1_Exist-'
		CNameN=vs.Copy(CName,9,CLen) # if true grab root name of class
	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', 'New') #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) & (SEL=TRUE)))")

vs.NameClass(ACName)  # Return active class

 

DataVisualizationsInfo.vwx

1 Existing Object.vsm 2 Demo Object.vsm 3 New Object.vsm

Edited by The Hamma
Link to comment
  • The Hamma changed the title to Script to add or modify selected objects records
  • 2 years later...
On 5/4/2020 at 8:19 AM, Pat Stanford said:

Just to make this more fun, I am going to throw some Vectorscript in here. 😉

 

I think you need to approach this from the other direction. If the selected object is a wall, then you need to use Fin3D to find the objects in the wall and then attach the records to them.

 

Create a new file with a single wall and a door (or multiple doors/windows/symbols) and leave the wall selected and run the following script.

 

After a "few" (I think it will depend on the wall styles how many object you will see), eventually you will come up with an object of Type 86 (Plug-in Object) or 15 (Symbol). You may need to check more thoroughly if they are doors or windows, but at least you will have a handle to the PIOs in the wall and can determine if you want to attach your record or not.

 

Ask again if you need more help.

 

Procedure Test;

Var	H1: Handle;

Begin
	H1:=Fin3D(FSActLayer);
	While H1 <> Nil do
		Begin
			ALrtDialog(Concat(GetTypeN(H1)));
			H1:=NextObj(H1);
		End;
End;

Run(Test);

 

 

Hi @Pat Stanford

 

I'm currently making a tool similar to the Select Similar tool, but with more options to select sub-types. I'm struggling to get a handle to a selected symbol in the wall. With your script I can loop trough all the objects within a wall. But when there are multiple objects hosted in the wall I can't get a handle to only the selected object within a wall. 

 

Is this even possible with Fin3D or do I need another approach? 

Link to comment

After you get a handle inside the wall, with FIn3D, loop through all objects in the wall and test each object for being Selected, and either a Symbol, or a PIO. Use GetTypeN(H) for the type. I use a while loop, but you can use ForEachObjectInList(), too. Quit when Found is true.

 

where H is a handle of an object inside a wall...

SymType = 15;        { Symbol Instance type }
PIOType = 86;        { PIO type }
Found := Selected(H) & ((ObjTyp = SymType) | (ObjTyp = PIOType));        { selected Symbol | PIO }

 

Raymond

  • Like 2
Link to comment

Made it work with a simple script below that displays the type number of the selected object in a wall. Will integrated it in my Select Similar Sub-Type tool another day. Thanks for the help.

 

Procedure Test;

Var	
H1, H2		:Handle;

Begin
	Locus(0, 0);				{ drop a bread crumb }
	H1 := PrevSObj(LNewObj);	{ use PrevSObj or PrevObj, as required }
	DelObject(LNewObj);			{ remove bread crumb }
	H2:=Fin3D(H1);
	While H2 <> Nil do
		Begin
			IF (Selected(H2)=true) & ((GetTypeN(H2) = 15) | ( GetTypeN(H2) = 86)) THEN 
			H1 := H2;
			H2:=NextObj(H2);
		End;
	ALrtDialog(Concat(GetTypeN(H1)));
End;

Run(Test);

 

  • Like 1
Link to comment

Hi, @MarcelP102,

   Well done.

 

   Just a thought. Though it may be easier to read, it is not necessary to compare a boolean function to a boolean value. More simply said, Selected(H2)=true is the same as Selected(H2). It is akin to writing the expression If (True=True) then {do something}, which could simply be written If True then {do something}.

 

   Likewise, in <criteria> statements people very often write (SEL=True) when they could simply write SEL. The only advantage I can see is that for people who don't program much, writing (SEL=True), or (Selected(H2)=true), it maybe easier to follow the program's logic. It's not wrong, it's just redundant.

 

HTH,

Raymond

  • Like 2
Link to comment
56 minutes ago, Pat Stanford said:

Or at least I hope there is an optimization pass of the compiler that removed things like True=True.

 

Hey Pat,

   On some compilers there may be, but I don't think VS is one of them. But I'm guessing, so please don't take my word for it. Ask someone who knows. 


   As it applies to runtime issues, I doubt a user would ever see a difference. You would have to be processing hundreds of thousands of objects until a statement like True=True would become noticeable. I have a hard time putting 30K+ 2D objects on one layer. VS can run through them quickly enough, but redraw becomes the crippling issue. Most scripts will probably never get loaded that heavily.

 

   Actually, I have been amazed more than once at how fast VS will run through 100,000 objects, or even 1,000,000 – like counting them, or changing a single attribute. In many areas Python and VS are on fairly even ground, but in some things Python can seriously outperform VS. This could be the seed for an entirely new Geek-Out thread.

 

Raymond

  • Like 2
Link to comment

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