Syntax to get Appearance of first component in browser

Syntax to get Appearance of first component in browser

steveh3
Advisor Advisor
253 Views
2 Replies
Message 1 of 3

Syntax to get Appearance of first component in browser

steveh3
Advisor
Advisor

Gang...attempting to get the appearance of the first component in an assembly/weldt and then turn the welds to that same appearance so that they visually appear accurate in next level.

 

This video illustrates what I am looking to do...

 

https://www.screencast.com/t/fIAL7wsn92ME

 

Best,

Steve H.

Steve Hilvers
Inventor Certified User / Vault Professional Influencer
0 Likes
Accepted solutions (1)
254 Views
2 Replies
Replies (2)
Message 2 of 3

WCrihfield
Mentor
Mentor
Accepted solution

Hi @steveh3.  Here is something that should at least point you in the right direction, if not be immediately useful.  In testing, I found that I could not simply get the appearance from the component, then set that immediately to the welds, because it was throwing an error.  So, I had to add in the bit of code for ensuring it is working with a 'local' (saved within the assembly document) version of the appearance.  Then it worked as planned.

If ThisDoc.Document.DocumentType <> DocumentTypeEnum.kAssemblyDocumentObject Then
	MsgBox("An Assembly Document must be active for this rule to work. Exiting.", vbCritical, "")
	Exit Sub
End If
Dim oADoc As AssemblyDocument = ThisDoc.Document
If Not TypeOf oADoc.ComponentDefinition Is WeldmentComponentDefinition Then Exit Sub
Dim oWDef As WeldmentComponentDefinition = oADoc.ComponentDefinition
Dim oOccs As ComponentOccurrences = oWDef.Occurrences
Dim oWeldsOcc = oOccs.Item(1) '.Defintion is usually a WeldsComponentDefinition
Dim oOcc1 As ComponentOccurrence = oOccs.Item(2)
'MsgBox("oOcc1.Name = " & oOcc1.Name,,"")
Dim oOcc1App As Asset = oOcc1.Appearance
'make sure we are working with a local copy (saved within the assembly)
Dim oFound As Boolean = False
For Each oApAsset As Asset In oADoc.AppearanceAssets
	If oApAsset.Name = oOcc1App.Name Or _
		oApAsset.DisplayName = oOcc1App.DisplayName Then
		oOcc1App = oApAsset
		oFound = True
		Exit For
	End If
Next
If Not oFound Then oOcc1App = oOcc1App.CopyTo(oADoc)
'oWDef.WeldBeadAppearanceSourceType = AppearanceSourceTypeEnum.kOverrideAppearance
oWDef.WeldBeadAppearance = oOcc1App
'oWDef.WeldEndFillAppearanceSourceType =  AppearanceSourceTypeEnum.kOverrideAppearance
'oWDef.WeldBeadMaterial
oWDef.WeldEndFillAppearance = oOcc1App
'oWDef.Welds.WeldBeads.Item(1).BeadFaces

If this solved your problem, or answered your question, please click ACCEPT SOLUTION .
Or, if this helped you, please click (LIKE or KUDOS) 👍.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 3

steveh3
Advisor
Advisor

@WCrihfield 

Awesome...that will do the trick. It works.

Owe you another one 😁

Thank you,

Steve H.

Steve Hilvers
Inventor Certified User / Vault Professional Influencer
0 Likes