Help finding all attribute "locations"

Help finding all attribute "locations"

pball
Mentor Mentor
189 Views
6 Replies
Message 1 of 7

Help finding all attribute "locations"

pball
Mentor
Mentor

I'm playing with attributes and I've run into a wall of finding where some of them are located. I think I've found every property in part files that can have an attribute but I know I'm missing some at the assembly level. At the assembly level I cannot figure out how to access attributes attached to the proxy whatever it's actually called that is an extruded surface inside of a part. Unlike what chatgpt thinks, I do not want attributes from the part level.

 

I have a test assembly and part attached. I know Nifty Attributes is a thing (and it's sweet), but this is a learning experience and a foundation for future things so I can't just rely on that. If I'm missing any other attributes please let me know.

 

    Private Sub LoadAttributes()
        Dim oDoc As Document = ThisApplication.ActiveEditDocument
        Dim oCompDef As ComponentDefinition = oDoc.ComponentDefinition

        AttributeAdd(oDoc.AttributeSets, "Document")
        AttributeAdd(oCompDef.AttributeSets, "Component Definition")

        If oDoc.DocumentType = DocumentTypeEnum.kPartDocumentObject Then
            For Each oBody As SurfaceBody In oCompDef.SurfaceBodies
                AttributeAdd(oBody.AttributeSets, "Surface Body")

                AttributeProcess(oBody, "Surface Body")
            Next

            For Each oWorkSurface As WorkSurface In oCompDef.worksurfaces
                AttributeAdd(oWorkSurface.AttributeSets, "Work Surface")

                For Each oBody As SurfaceBody In oWorkSurface.SurfaceBodies
                    AttributeAdd(oBody.AttributeSets, "Work Surface: Surface Body")

                    AttributeProcess(oBody, "Work Surface")
                Next
            Next
        ElseIf oDoc.DocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then
            For Each oCompOccur As ComponentOccurrence In oCompDef.Occurrences
                AttributeAdd(oCompOccur.AttributeSets, "Component Occurance")

                For Each oBody As SurfaceBody In oCompOccur.SurfaceBodies
                        AttributeAdd(oBody.AttributeSets, "Surface Body")

                        AttributeProcess(oBody, "Surface Body")
                    Next

                Next
        End If
    End Sub

    Private Sub AttributeAdd(AttribSets As AttributeSets, Type As String)
        If AttribSets Is Nothing OrElse AttribSets.Count = 0 Then Exit Sub

        Dim TypeSetNode As TreeNode = TV_Attributes.Nodes.Add(Type)
        TypeSetNode.Tag = AttribSets
        For Each AttribSet As AttributeSet In AttribSets
            Dim AttribSetNode As TreeNode = TypeSetNode.Nodes.Add(AttribSet.Name)
            AttribSetNode.Tag = AttribSet
            For Each Attrib As Attribute In AttribSet
                Dim AttribNode As TreeNode
                If Attrib.ValueType = ValueTypeEnum.kByteArrayType Then
                    AttribNode = AttribSetNode.Nodes.Add(Attrib.Name & " = (Byte Array)")
                Else
                    AttribNode = AttribSetNode.Nodes.Add(Attrib.Name & " = " & If(Attrib.Value.ToString.Length > 31, Attrib.Value.ToString.Substring(0, 30) & "...", Attrib.Value.ToString))
                End If
                AttribNode.Tag = Attrib
            Next
        Next
    End Sub

    Private Sub AttributeProcess(oBody As SurfaceBody, ParentType As String)
        For Each oFace As Face In oBody.Faces
            AttributeAdd(oFace.AttributeSets, ParentType & ": Face")
        Next

        For Each oEdge As Edge In oBody.Edges
            AttributeAdd(oEdge.AttributeSets, ParentType & ": Edge")
        Next

        For Each oVertex As Vertex In oBody.Vertices
            AttributeAdd(oVertex.AttributeSets, ParentType & ": Vertex")
        Next
    End Sub

 

pball_1-1779367779006.png

 

 

Check out my style edits for the Autodesk forums
pball's Autodesk Forum Style

Userscript to edit forum links to jump to first unread post
Jump To First Post Userscript
0 Likes
Accepted solutions (1)
190 Views
6 Replies
Replies (6)
Message 2 of 7

JhoelForshav
Mentor
Mentor

Hi @pball 
Going through the occurrence to access faces (not the actual part documents component definition) gives you the face proxies. So within the loop you already have for surfacebodies in the assembly contoxt you can loop through their faces (FaceProxies). Quick example just accessing these propertysets and writing out their names:

Dim oDoc As Document = ThisApplication.ActiveEditDocument
Dim oCompDef As ComponentDefinition = oDoc.ComponentDefinition


If oDoc.DocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then
	For Each oCompOccur As ComponentOccurrence In oCompDef.Occurrences
		For Each oBody As SurfaceBody In oCompOccur.SurfaceBodies
			For Each oFaceProx As FaceProxy In oBody.Faces
				For Each oSet As AttributeSet In oFaceProx.AttributeSets
					MsgBox(oSet.Name)
				Next
			Next
		Next
	Next
End If

I would also change the occurrences I'm looping through to this:

For Each oCompOccur As ComponentOccurrence In oCompDef.Occurrences.AllReferencedOccurrences(oDoc.ComponentDefinition)

To make sure I get all levels of occurrences 🙂

0 Likes
Message 3 of 7

WCrihfield
Mentor
Mentor

Just adding that there are still TONS of other Inventor API object types which have the AttributeSets property.  A few others in the non-transient geometry category are:  Sketch objects, 2D & 3D sketch entities (including TextBox & sketch pattern objects), Profile objects, PointCloud, Path, work [plane / axis / point], UCS, features, and so on.  Lots of stuff unique to drawings to like Sheet, and some of the 'definitions' for things like title blocks, borders, symbols, and such.  And of course there are plenty of non-geometry objects with that property too, like dimensional and geometric constraint objects within sketches, Parameter objects, and so on.  Lots of potential ground to cover in an attributes manager type tool.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 4 of 7

JhoelForshav
Mentor
Mentor

@WCrihfield is right, and there's actually a pretty simple way to get all attributed objects using the attributemanager. Here's a simple example that populates an objectcollection with all attributed objects and writes out the name of the attributed object type (like the top nodes in Nifty Attributes).
You can access all attributesets and attributes from these objects.

Dim oDoc As Document = ThisApplication.ActiveDocument
Dim attMgr As AttributeManager = oDoc.AttributeManager
Dim attEnts As ObjectCollection = attMgr.FindObjects("*", "*")

For Each attEnt As Object In attEnts
	Dim objName As String = Microsoft.VisualBasic.TypeName(attEnt)
	MsgBox(objName)
Next



0 Likes
Message 5 of 7

pball
Mentor
Mentor

@JhoelForshav I'm already going down to .Faces in the AttributeProcess subroutine and that is not picking up the attributes located on the extruded surface. Going by the script you shared it's called a WorkSurfaceProxy.

 

At the part level to get the WorkSurface attributes I have to use the below code to traverse through .WorkSurfaces and their .SurfaceBodies. But at the assembly level .WorkSurfaces doesn't seem to exist. So either I'm missing something or this is missing from the API.

 

            For Each oWorkSurface As WorkSurface In oPartCompDef.WorkSurfaces
                AttributeAdd(oWorkSurface.AttributeSets, "Work Surface")

                For Each oBody As SurfaceBody In oWorkSurface.SurfaceBodies
                    AttributeAdd(oBody.AttributeSets, "Work Surface: Surface Body")

                    AttributeProcess(oBody, "Work Surface")
                Next
            Next

 

The method for finding all attributes is nice, but I prefer traversing things like I am. Since the FindObjects method returns what appears to be the creation order, where as my method is ordering things by type.

@WCrihfield I realized shortly after I posted that I was missing quite a few attributes and your post names even more. I'll likely limit this to the big common things I have so far.

Check out my style edits for the Autodesk forums
pball's Autodesk Forum Style

Userscript to edit forum links to jump to first unread post
Jump To First Post Userscript
0 Likes
Message 6 of 7

JhoelForshav
Mentor
Mentor
Accepted solution

Sorry for misunderstanding. Yeah worksurfaces are really tricky in general and the path to access them is anything but clear. You can however get the worksurface through the documents definition, get its faces from there and then use the ComponentOccurrence to get the proxy. See example:

Dim oDoc As Document = ThisApplication.ActiveEditDocument
Dim oCompDef As ComponentDefinition = oDoc.ComponentDefinition


If oDoc.DocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then
	For Each oCompOccur As ComponentOccurrence In oCompDef.Occurrences.AllReferencedOccurrences(oDoc.ComponentDefinition)
		If TypeOf oCompOccur.Definition Is PartComponentDefinition
			For Each oSurf As WorkSurface In oCompOccur.Definition.WorkSurfaces
				For Each oBody As SurfaceBody In oSurf.SurfaceBodies
					For Each oFace As Face In oBody.Faces
						Dim faceProx As FaceProxy
						oCompOccur.CreateGeometryProxy(oFace, faceProx)
						For Each oSet As AttributeSet In faceProx.AttributeSets
							MsgBox(oSet.Name)
						Next
					Next
				Next
			Next
		End If
	Next
End If

You could also use the method I mentioned earlier, and just sort the result by object type if you want to. It is way easier and less error prone IMO.
Example:

Dim oDoc As Document = ThisApplication.ActiveEditDocument
Dim attMgr As AttributeManager = oDoc.AttributeManager
Dim attEnts As ObjectCollection = attMgr.FindObjects("*", "*")

Dim SortedList As New List(Of Object)
For Each item As Object In attEnts
	SortedList.Add(item)
Next
SortedList.Sort(Function(x, y) _
    String.Compare(Microsoft.VisualBasic.TypeName(x), Microsoft.VisualBasic.TypeName(y)))


For Each attEnt As Object In SortedList
	Dim objName As String = Microsoft.VisualBasic.TypeName(attEnt)
	MsgBox(objName)
Next
0 Likes
Message 7 of 7

pball
Mentor
Mentor

@JhoelForshav Thanks for that. I started down the .Definition route but I wouldn't have gotten anywhere useful without your example showing the use of oCompOccur.CreateGeometryProxy.

I'll probably switch over to the FindObjects method and sorting, but I'm happy to have figured out my original goal before changing direction even if it would have been smarter to give up and do something better.

Check out my style edits for the Autodesk forums
pball's Autodesk Forum Style

Userscript to edit forum links to jump to first unread post
Jump To First Post Userscript