Message 1 of 7
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello all,
I am trying to create an iLogic rule that access to every part within an assembly, look for a specific sketch, where a text box is created, and replace the text in it with the standard Part Number iProperty.
I tried using AI help and it managed to do by access to the Part Number iProperty value and copying it into the text box as a text (like manually written).
Private Sub Main()
Dim oDoc As AssemblyDocument
oDoc = ThisDoc.Document
' Loop through all components in the assembly
Dim oOccurrence As ComponentOccurrence
For Each oOccurrence In oDoc.ComponentDefinition.Occurrences
SearchForSketch(oOccurrence)
Next
' Ensure updates happen after all modifications
iLogicVb.UpdateWhenDone = True
End Sub
Private Sub SearchForSketch(ByVal oOccurrence As ComponentOccurrence)
If TypeOf oOccurrence.Definition Is PartComponentDefinition Then
Dim oPartDoc As PartDocument
oPartDoc = oOccurrence.Definition.Document
' Ensure the document is open
If oPartDoc Is Nothing Then Exit Sub
' Loop through sketches to find "Part_Number"
Dim oSketch As PlanarSketch
For Each oSketch In oPartDoc.ComponentDefinition.Sketches
If oSketch.Name = "Part_Number" Then
Dim oTextBox As TextBox
For Each oTextBox In oSketch.TextBoxes
' Access the custom property "Part Number" using PropertySets
Dim oProperty As [Property]
oProperty = oPartDoc.PropertySets.Item("Design Tracking Properties").Item("Part Number")
' Link the text box to the custom "Part Number" property
oTextBox.Text = oProperty.Value
Next
End If
Next
ElseIf TypeOf oOccurrence.Definition Is AssemblyComponentDefinition Then
' If it's an assembly, iterate through subcomponents
Dim oSubOccurrence As ComponentOccurrence
For Each oSubOccurrence In oOccurrence.Definition.Occurrences
SearchForSketch(oSubOccurrence)
Next
End If
End Sub
I was wondering if there is some way to, instead of insert text, insert the actual link of the iProperty, like it can be done when editing the text manually.
Solved! Go to Solution.