- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi,
I'm working on one Layout assembly, This assembly having different type of gate valves mentioned below as well as some other components also.
I want to select only the Gate valves by using the Part name. Please give your suggestions.
Gate valve Part names:
VLV_MAN_3-5.iam
VLV_HYD_3-5.ipt
VLV_HYD_3-10.iam
Above the part names of Gate valves, So I want to select the components which part names start with "VLV_MAN"&"VLV_HYD"
Thanks & Regards,
Manoj Sampath
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi,
Best thing is to probably loop through all occurences in the assembly and then check if the name matches to one of your predefined names.
Then create an object collection which will hold all those items.
After that you can use the SelectMultiple in SelectSet to select them.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi, try the following code, I think it could work.
Dim AssyDoc As AssemblyDocument = ThisDoc.Document For Each oOcc As ComponentOccurrence In AssyDoc.ComponentDefinition.Occurrences oFilename = oOcc.Definition.Document.displayname If InStr(oFilename, "VLV_MAN") <> 0 Then ThisApplication.CommandManager.DoSelect(oOcc) End If If InStr(oFilename, "VLV_HYD") <> 0 Then ThisApplication.CommandManager.DoSelect(oOcc) End If Next
I hope this helps with your problem. regards
Please accept as solution and give likes if applicable.
I am attaching my Upwork profile for specific queries.
Sergio Daniel Suarez
Mechanical Designer
| Upwork Profile | LinkedIn
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi,
The Loop Code is working fine to select the components.
I need to constraint these selected gate valves with respect to Assembly "Y Axis"
So I have created below Loop code by using your suggested Code, But I'm getting error while run the rule.
Can you please help to find the error in below code
Dim oAsm As AssemblyDocument = ThisApplication.ActiveDocument
Dim oAsmCompDef As AssemblyComponentDefinition = oAsm.ComponentDefinition
Dim oAxis1 As WorkAxis
Dim oAxis2 As WorkAxis
Dim oproxyAxis1 As WorkAxisProxy
Dim oAConstraint As AngleConstraint
Dim comps As ObjectCollection
Dim comp As ComponentOccurrence
comps = ThisApplication.TransientObjects.CreateObjectCollection
comp = oAsmCompDef.Occurrences
oFilename = comp.Definition.Document.displayname
If InStr(oFilename, "VLV_MAN") <> 0 Then
ThisApplication.CommandManager.DoSelect(comp)
End If
If InStr(oFilename, "VLV_HYD") <> 0 Then
ThisApplication.CommandManager.DoSelect(comp)
End If
comps.Add(comp)
' If there are selected components we can do something
For Each comp In comps
oAxis1 = oAsmCompDef.WorkAxes.Item ("Y Axis")
oAxis2 = comp.Definition.WorkAxes("Y Axis")
comp.CreateGeometryProxy(oAxis2, oproxyAxis2)
oAConstraint = oAsmCompDef.Constraints.AddAngleConstraint(oproxyAxis2, oAxis1, 0, 78593)
'78594 refers to the undirected angle constraint solution type. 78593 refers to
'directed (which is default), and 78595 is the referenced vector solution
Next
Thanks & Regards,
Manoj Sampath
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
try the following code, I think it could work, I have placed the instruction on error resume next in the last for-next in case errors are generated in this sector, should control this sector of code then, if the previous block works. regards
Dim oAsm As AssemblyDocument = ThisApplication.ActiveDocument Dim oAsmCompDef As AssemblyComponentDefinition = oAsm.ComponentDefinition Dim oAxis1 As WorkAxis Dim oAxis2 As WorkAxis Dim oproxyAxis1 As WorkAxisProxy Dim oAConstraint As AngleConstraint Dim comps As ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection For Each comp As ComponentOccurrence In oAsm.ComponentDefinition.Occurrences oFilename = comp.Definition.Document.displayname If InStr(oFilename, "VLV_MAN") <> 0 Or InStr(oFilename, "VLV_HYD") <> 0 Then comps.Add(comp) End If Next ' If there are selected components we can do something For Each comp In comps On Error Resume Next oAxis1 = oAsmCompDef.WorkAxes.Item ("Y Axis") oAxis2 = comp.Definition.WorkAxes("Y Axis") comp.CreateGeometryProxy(oAxis2, oproxyAxis2) oAConstraint = oAsmCompDef.Constraints.AddAngleConstraint(oproxyAxis2, oAxis1, 0, 78593) '78594 refers to the undirected angle constraint solution type. 78593 refers to 'directed (which is default), and 78595 is the referenced vector solution Next
Please accept as solution and give likes if applicable.
I am attaching my Upwork profile for specific queries.
Sergio Daniel Suarez
Mechanical Designer
| Upwork Profile | LinkedIn
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi Sergio,
I have tried the code, Now the error message box is not coming but Angle constraints are not get creating.
The object collection function codes are fine (I have tried that code separately), I thing " CreateGeometryProxy(oAxis2, oproxyAxis2)" function is not working for "comp".
Previously I have used below function to select the components by using Pick command and the Angle constraint function worked fine
comps = ThisApplication.TransientObjects.CreateObjectCollection
While True
compOcc = ThisApplication.CommandManager.Pick(
SelectionFilterEnum.kAssemblyOccurrenceFilter,
"Select a component")
' If nothing gets selected then we're done
If IsNothing(compOcc) Then Exit While
comps.Add(compOcc)
End While
But Angle constraint function not working for below "comp" function
Dim comps As ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection
For Each comp As ComponentOccurrence In oAsm.ComponentDefinition.Occurrences
oFilename = comp.Definition.Document.displayname
If InStr(oFilename, "VLV_MAN") "Create<> 0 Or InStr(oFilename, "VLV_HYD") <> 0 Then
comps.Add(comp)
End If
Next
Please give me your suggestion for this
Thanks & Regards,
Manoj Sampath
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi Sir,
Can you please check the loop code I have shared and give your idea
Thanks & Regards,
Manoj Sampath
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
@Anonymous,
There is a little confusion about requirement. Are you trying to constrain selected occurrences or all occurrences of assembly?
Can you please re post non confidential source code that need to work on?
Thanks and regards,
CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi Sir,
I wanted to constraint selected occurrences not all occurrences.
After I got few reply for my post I have done little changes to my Loop code and it is working fine now.
But If run the code again it is creating Angle constraints again,
I want to include the condition " If the component already have angle constraint, new Angle constraint shouldn't create", Can you please help how add this condition on below code.
Dim oAsm As AssemblyDocument = ThisApplication.ActiveDocument
Dim oAsmCompDef As AssemblyComponentDefinition = oAsm.ComponentDefinition
Dim oAxis1 As WorkAxis
Dim oAxis2 As WorkAxis
Dim oproxyAxis2 As WorkAxisProxy
Dim oAConstraint As AngleConstraint
Dim comps As New List(Of ComponentOccurrence)
For Each comp As ComponentOccurrence In oAsm.ComponentDefinition.Occurrences
oFilename = comp.Definition.Document.displayname
If InStr(oFilename, "VLV_MAN") <> 0 Or InStr(oFilename, "VLV_HYD") <> 0 Then
comps.Add(comp)
End If
Next
' If there are selected components we can do something
For Each comp In comps
On Error Resume Next
oAxis1 = oAsmCompDef.WorkAxes.Item ("Y Axis")
oAxis2 = comp.Definition.WorkAxes("Y Axis")
comp.CreateGeometryProxy(oAxis2, oproxyAxis2)
oAConstraint = oAsmCompDef.Constraints.AddAngleConstraint(oproxyAxis2, oAxis1, 0, 78593)
'78594 refers to the undirected angle constraint solution type. 78593 refers to
'directed (which is default), and 78595 is the referenced vector solution
If oAConstraint.HealthStatus = oAConstraint.HealthStatus.kInconsistentHealth Then
oAConstraint.Delete
oAxis1 = oAsmCompDef.WorkAxes.Item("Z Axis")
oAxis2 = comp.Definition.WorkAxes("Y Axis")
comp.CreateGeometryProxy(oAxis2, oproxyAxis2)
oAConstraint = oAsmCompDef.Constraints.AddAngleConstraint(oproxyAxis2, oAxis1, 0, 78593)
'78594 refers to the undirected angle constraint solution type. 78593 refers to
'directed (which is default), and 78595 is the referenced vector solution
End If
Next
Thanks & Regards
Manoj Sampath
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
@Anonymous,
For every occurrence, only one angle constraint is used?
Thanks and regards,
CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi Sir,
Yes. While I run the code Angle constraint will create for components which have display name as " VLV_MAN" or "VLV_HYD". I need function code for " If already that component having Angle constraint, Another one shouldn't not create".
Thanks & Regards,
Manoj Sampath
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
@Anonymous,
Try below iLogic code.
Dim oAsm As AssemblyDocument = ThisApplication.ActiveDocument
Dim oAsmCompDef As AssemblyComponentDefinition = oAsm.ComponentDefinition
Dim oAxis1 As WorkAxis
Dim oAxis2 As WorkAxis
Dim oproxyAxis2 As WorkAxisProxy
Dim oAConstraint As AngleConstraint
Dim comps As New List(Of ComponentOccurrence)
For Each comp As ComponentOccurrence In oAsm.ComponentDefinition.Occurrences
oFilename = comp.Definition.Document.displayname
If InStr(oFilename, "VLV_MAN") <> 0 Or InStr(oFilename, "VLV_HYD") <> 0 Then
comps.Add(comp)
End If
Next
' If there are selected components we can do something
For Each comp In comps
On Error Resume Next
Dim oAngle As Boolean
oAngle = False
Dim oConstraint As AssemblyConstraint
For Each oConstraint In comp.Constraints
If oConstraint.Type = kAngleConstraintObject Then
oAngle = True
End If
Next
If oAngle = False Then
oAxis1 = oAsmCompDef.WorkAxes.Item ("Y Axis")
oAxis2 = comp.Definition.WorkAxes("Y Axis")
comp.CreateGeometryProxy(oAxis2, oproxyAxis2)
oAConstraint = oAsmCompDef.Constraints.AddAngleConstraint(oproxyAxis2, oAxis1, 0, 78593)
'78594 refers to the undirected angle constraint solution type. 78593 refers to
'directed (which is default), and 78595 is the referenced vector solution
If oAConstraint.HealthStatus = oAConstraint.HealthStatus.kInconsistentHealth Then
oAConstraint.Delete
oAxis1 = oAsmCompDef.WorkAxes.Item("Z Axis")
oAxis2 = comp.Definition.WorkAxes("Y Axis")
comp.CreateGeometryProxy(oAxis2, oproxyAxis2)
oAConstraint = oAsmCompDef.Constraints.AddAngleConstraint(oproxyAxis2, oAxis1, 0, 78593)
'78594 refers to the undirected angle constraint solution type. 78593 refers to
'directed (which is default), and 78595 is the referenced vector solution
End If
End If
Next
Thanks and regards,
CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network
