Get appearance at part level from Assembly

Get appearance at part level from Assembly

SharkDesign
Mentor Mentor
795 Views
4 Replies
Message 1 of 5

Get appearance at part level from Assembly

SharkDesign
Mentor
Mentor

I'm using this to go through all occurences

 

Sub Main

Dim oDoc As AssemblyDocument = ThisApplication.ActiveDocument
	Dim oCompDef As AssemblyComponentDefinition = oDoc.ComponentDefinition
	Dim oOcc_s As ComponentOccurrences = oCompDef.Occurrences

	'look at each occurrence in the assembly
	For Each oOcc As ComponentOccurrence In oOcc_s
		ListOccurences(oOcc)
	Next
	
End Sub

Sub ListOccurences(oOcc)
	
	If Not oOcc.Name.Contains("Weldbead")
		Try 'Prevents Weldment and simulation file errors
			
			'Do stuff Here!
	
		For Each subOcc As ComponentOccurrence In oOcc.SubOccurrences
			ListOccurences(subOcc)
		Next
		Catch'Weldment
		End Try
	End If
		
End Sub

 

In the do stuff here, I want to get the appearance of the occurrence at part level.  i.e. "anodise"

I've tried the following:

Component.Color("part1:2")

 And also

iProperties.PartColor("part1:2")

But they all just bring back 'As Material' which I assume is actually getting the appearance at assembly level (unless there's an override.)

 

I feel like it should be pretty simple, but everything I've found about appearances online for other tasks are lines and lines of code.

  Inventor Certified Professional
0 Likes
Accepted solutions (2)
796 Views
4 Replies
Replies (4)
Message 2 of 5

JhoelForshav
Mentor
Mentor

Hi @SharkDesign 

Are you trying to get the active appearance of the actual part document and not the occurrence in assembly environment? See example below:

'Get an occurrence
Dim oOcc As ComponentOccurrence = ThisDoc.Document.ComponentDefinition.Occurrences(1)
'Get the part document of occurrence
Dim oDoc As Document = oOcc.Definition.Document
'Get the active appearance and display its name in messagebox
MsgBox(oDoc.ActiveAppearance.DisplayName)
0 Likes
Message 3 of 5

SharkDesign
Mentor
Mentor

I'm wanting the actual appearance contained in the part, not an overridden value. 

 

Using the same code for looping above, I use this line and it gets the material perfectly, but was trying to do the same for appearance. 

 

oMatPick = iProperties.MaterialOfComponent(oOcc.Name)

I'm basically doing, if that appearance matches (anodised for instance) write iproperty. 

Just couldn't work out how to get it to read the actual appearance. 

  Inventor Certified Professional
0 Likes
Message 4 of 5

nmunro
Collaborator
Collaborator
Accepted solution

You need to examine the active appearance at the part level. A short vba macro below should help.

 

 

 

Public Sub GetAppearance()

    Dim doc As AssemblyDocument
    Set doc = ThisDocument
    
    Dim occurs As ComponentOccurrences
    Set occurs = doc.ComponentDefinition.Occurrences
    
    Dim occur As ComponentOccurrence
    Dim partDoc As PartDocument
    
    For Each occur In occurs
        If occur.DefinitionDocumentType = kPartDocumentObject Then
            Set partDoc = occur.Definition.Document
            MsgBox occur.Name & " - " & partDoc.ActiveAppearance.DisplayName
        End If
    Next occur
    
End Sub

 

 

        


https://c3mcad.com

0 Likes
Message 5 of 5

SharkDesign
Mentor
Mentor
Accepted solution

Thanks, I don't use VBA, but I was able to use your code. 

 

The bit I needed was this, which I slightly modified. 

Dim partDoc As PartDocument
partDoc = oOcc.Definition.Document
mystring = partDoc.ActiveAppearance.DisplayName

 

  Inventor Certified Professional
0 Likes