How to change kReferenceBOMStructure appearance occurence

How to change kReferenceBOMStructure appearance occurence

gustavo.cassel
Advocate Advocate
408 Views
3 Replies
Message 1 of 4

How to change kReferenceBOMStructure appearance occurence

gustavo.cassel
Advocate
Advocate

Hello, i want a way to change every appearance of a occurence that is in kReferenceBOMStructure, and disable the appearance substitution when its on kNormalBOMStructure.

Here is a code that I made to loop through all document occurences and test his BOMStructure type.

Sub Change_Reference_Color
	Dim Assembly_Doc As AssemblyDocument = ThisApplication.ActiveDocument
	Dim oAsmCompDef As AssemblyComponentDefinition = Assembly_Doc.ComponentDefinition
	Dim oRefDocs As DocumentsEnumerator = Assembly_Doc.AllReferencedDocuments	
	Dim oRefDoc As Document
	
	'Dim MainAssetDoc As Assets = Assembly_Doc.Assets
	'Dim Reference_Asset As Asset = MainAssetDoc.Item("Azul - Tinta de Parede - Com Brilho")
	
	Dim oCompOcc As ComponentOccurrence
	For Each oRefDoc In oRefDocs
		For Each oCompOcc In oAsmCompDef.Occurrences.AllReferencedOccurrences(oRefDoc)
			If oCompOcc.BOMStructure = BOMStructureEnum.kReferenceBOMStructure Then				
				MsgBox("reference: " & oCompOcc.Name)
			Else
				MsgBox("normal: " & oCompOcc.Name)
			End If
		Next oCompOcc
    Next oRefDoc
	
	Assembly_Doc.Update2(True)
End Sub

Now I need a way to change this:

gustavocassel_0-1659551287362.png

Of every part in reference, and 

gustavocassel_1-1659551403245.png

remove every appearance changes to the kNormalBOMStrucure occurences.

Thanks for the attention

0 Likes
Accepted solutions (1)
409 Views
3 Replies
Replies (3)
Message 2 of 4

A.Acheson
Mentor
Mentor

To assign appearance to the occurrence that is in the assembly document. Just reinstate your previous declaration of Reference_Asset. 

' Assign the asset to the occurrence.
		  Try
			oOcc.Appearance = Reference_Asset
Catch
End Try

 

 

Remove the overide by setting the source type back to the part. Api sample showing its use here

 

oOcc.AppearanceSourceType = kPartAppearance
    

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes
Message 3 of 4

gustavo.cassel
Advocate
Advocate

Hi, i've created a new asset for referenced parts

gustavocassel_0-1659989744068.png

But when i try to assign it to the occurence it gives me a error called "wrong paramenter" (err.number = 5).

	Dim Assembly_Doc As AssemblyDocument = ThisApplication.ActiveDocument
	Dim oAsmCompDef As AssemblyComponentDefinition = Assembly_Doc.ComponentDefinition
	Dim oRefDocs As DocumentsEnumerator = Assembly_Doc.AllReferencedDocuments
	Dim oRefDoc As Document

	Dim Reference_Asset As Asset = ThisApplication.ActiveMaterialLibrary.AppearanceAssetCategories.Item("Padrão").Assets.Item("REFERÊNCIA")
	
	Dim oCompOcc As ComponentOccurrence
	For Each oRefDoc In oRefDocs
		For Each oCompOcc In oAsmCompDef.Occurrences.AllReferencedOccurrences(oRefDoc)
			If oCompOcc.BOMStructure = BOMStructureEnum.kReferenceBOMStructure Then
				oCompOcc.Appearance = Reference_Asset
			Else
				oCompOcc.AppearanceSourceType = kPartAppearance
			End If
		Next oCompOcc
	Next oRefDoc
	
	Assembly_Doc.Update2(True)

If you could help me i would be grateful!

0 Likes
Message 4 of 4

A.Acheson
Mentor
Mentor
Accepted solution

Here is the API sample for appearances. It could be the case that you haven't copied the appearance asset to the assembly. Here is how to copy an asset to assembly.

Dim assetLib As AssetLibrary = ThisApplication.AssetLibraries.Item("Autodesk Appearance Library")
	Dim libAsset As Asset = assetLib.AppearanceAssets.Item("Bamboo")
	Dim localAsset As Asset
	Try
		localAsset = Assembly_Doc.Assets.Item("Bamboo")
	Catch
		localAsset = libAsset.CopyTo(Assembly_Doc)
	End Try

 

 

Also you can loop through the assembly occurrences using 

For Each oCompOcc As ComponentOccurrence In oAsmCompDef.Occurrences.AllReferencedOccurrences(oAsmCompDef)

No need for the loop through documents also. 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes