- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello Inventor Community,
I have following situation:
Assembly1:
- 2 x Part1 --> Has AttributeSet with Name = "ANSYS_NS_COLLECTION"
- Item1.Name = "S_" , 2 Faces
- Item2.Name = "W_", 2 Faces
- 2 x Part2 --> Has AttributeSet with Name = "ANSYS_NS_COLLECTION"
- Item1.Name = "S_", 3 Faces
- Item2.Name = "W_", 3 Faces
I added the attributes over the Ansys Addin (named selection manager)
Part 1: 2 faces for "S_" and 2 faces for "W_"
Part 2: 3 faces for "S_" and 3 faces for "W_"
In the Assembly I want to check if there are parts with AttributeSet Name = "ANSYS_NS_COLLECTION".
If so, create new attribute on assembly level with the same faces as in part level but the item name must be renamed to "S_count" respectively "W_count". ("S_1", W_1"). The AttributeSet Name should remain "ANSYS_NS_COLLECTION".
In the end the Assembly should have 8 attributesets:
- Attribute Set Name: "ANSYS_NS_COLLECTION"
- Item 1 Name: "S_1" , 2 Faces
- Item 2 Name: "W_1", 2 Faces
- Item 3 Name: "S_2", 2 Faces
- ...
- Item 7 Name: "S_7", 3 Faces
- Item 8 Name: "W_8, 3 Faces
Attached is the sample CAD File of the assembly as described here.
What I have so far is to get all the Attributes from the parts. But I dont know how to create new one in the Assembly?
Public Sub AssemblyAttribute()
'check that the active document is an assembly file
If ThisApplication.ActiveDocument.DocumentType <> kAssemblyDocumentObject Then
MsgBox ("Please run this rule from the assembly document file.")
Exit Sub
End If
' Get the active assembly document
Dim oDoc As AssemblyDocument
Set oDoc = ThisApplication.ActiveDocument
Debug.Print "Active Document: " + oDoc.DisplayName
With oDoc
For i = 1 To .ComponentDefinition.Occurrences.Count
Dim oOcc As ComponentOccurrence
Set oOcc = .ComponentDefinition.Occurrences(i)
Debug.Print "NS for Part: " + oOcc.Name
Dim oAttMgr As AttributeManager
Dim oAttsetsEnum As AttributeSetsEnumerator
Set oAttMgr = oOcc.Definition.Document.AttributeManager
Set oAttsetsEnum = oAttMgr.FindAttributeSets("ANSYS_NS_COLLECTION")
Dim oAttSet As AttributeSet
Dim oAtt As Inventor.Attribute
For Each oAttSet In oAttsetsEnum
For Each oAtt In oAttSet
If InStr(oAtt.Name, "S_") Or InStr(oAtt.Name, "W_") Then
Debug.Print oAtt.Name
End If
Next
Next
Next
End With
End Sub
Produces following output:
Active Document: Assembly1.iam
NS for Part: Part2:1
W_
W_
W_
S_
S_
S_
NS for Part: Part2:2
W_
W_
W_
S_
S_
S_
NS for Part: Part1:1
W_
W_
S_
S_
NS for Part: Part1:2
W_
W_
S_
S_
Solved! Go to Solution.