Sub Assemblies don't update representations with any code, only manually it seems.

Sub Assemblies don't update representations with any code, only manually it seems.

cencinaNB2ET
Advocate Advocate
282 Views
3 Replies
Message 1 of 4

Sub Assemblies don't update representations with any code, only manually it seems.

cencinaNB2ET
Advocate
Advocate

With an assembly inside an assembly the colours are only updated if the representation is manually altered ( or just accessed via manual). I have tried looking for a way to do this with code but it does not seem to work.

Please see screen cast video that shows this in more detail.

Is this a bug?

 

 

Dim oAsmDoc As AssemblyDocument = ThisDoc.Document
Dim oAsmDef As AssemblyComponentDefinition = oAsmDoc.ComponentDefinition
Dim oOcc As ComponentOccurrence 
Dim Occurrences As ComponentOccurrences 

Dim oAsmCompDef As AssemblyComponentDefinition
Dim oViewReps As DesignViewRepresentations
Dim oViewRep As DesignViewRepresentation
Dim oViewRepName As String
For Each oOcc In oAsmDef.Occurrences
If oOcc.DefinitionDocumentType = 12291 Then
oAsmCompDef = oOcc.Definition.Document.ComponentDefinition
oViewReps = oAsmCompDef.RepresentationsManager.DesignViewRepresentations
oViewRep = oAsmCompDef.RepresentationsManager.ActiveDesignViewRepresentation
oViewRepName = oViewRep.Name
MessageBox.Show(oOcc.Name & vbCr & oOcc.DefinitionDocumentType & vbCr & oViewRepName)
'oViewReps.Item(ViewRep).Activate
oAsmCompDef.RepresentationsManager.DesignViewRepresentations.Item("Default").Activate
'oOcc.SetDesignViewRepresentation("Default", True)
End If
Next
0 Likes
283 Views
3 Replies
Replies (3)
Message 2 of 4

Andrii_Humeniuk
Advisor
Advisor

Hi @cencinaNB2ET . I made a small change to your code and added line 12 which removes the associativity. Please try it.

Dim oAsmDoc As AssemblyDocument = ThisDoc.Document
Dim oAsmDef As AssemblyComponentDefinition = oAsmDoc.ComponentDefinition
Dim oOcc As ComponentOccurrence 
Dim Occurrences As ComponentOccurrences
Dim oAsmCompDef As AssemblyComponentDefinition
Dim oRepMan As RepresentationsManager
Dim oViewReps As DesignViewRepresentations
Dim oViewRep As DesignViewRepresentation
Dim oViewRepName As String
For Each oOcc In oAsmDef.Occurrences
	If oOcc.DefinitionDocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then
		oOcc.IsAssociativeToDesignViewRepresentation = False
		oAsmCompDef = oOcc.Definition
		oRepMan = oAsmCompDef.RepresentationsManager
		oViewReps = oRepMan.DesignViewRepresentations
		oViewRep = oRepMan.ActiveDesignViewRepresentation
		oViewRepName = oViewRep.Name
		MessageBox.Show(oOcc.Name & vbCr & oOcc.DefinitionDocumentType & vbCr & oViewRepName)
		'oViewReps.Item(ViewRep).Activate
		oViewReps.Item("Default").Activate
		'oOcc.SetDesignViewRepresentation("Default", True)
	End If
Next

  

Andrii Humeniuk - CAD Coordinator, Autodesk Certified Instructor

LinkedIn | My free Inventor Addin | My Repositories

Did you find this reply helpful ? If so please use the Accept as Solution/Like.

EESignature

0 Likes
Message 3 of 4

cencinaNB2ET
Advocate
Advocate

Yes I see it set them to Default, however I noticed I want them set to [Primary], this new option that appeared with the introduction of model states. Do you how to set them to that?

I tried the String "[Primary]" but it does not work.

 

0 Likes
Message 4 of 4

Andrii_Humeniuk
Advisor
Advisor

Hi @cencinaNB2ET . I again changed the rule that read over all components of all levels. If you only need the top level, then comment out lines 21-23.

Sub main
	Dim oAsmDoc As AssemblyDocument = ThisDoc.Document
	Dim oAsmDef As AssemblyComponentDefinition = oAsmDoc.ComponentDefinition
	Call ChangeRepresent(oAsmDef.Occurrences)
	ThisApplication.ActiveView.Fit
End Sub

Private Function ChangeRepresent(oOccs As ComponentOccurrences)
	For Each oOcc As ComponentOccurrence  In oOccs
		If oOcc.DefinitionDocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then
			oOcc.IsAssociativeToDesignViewRepresentation = False
			Dim oAsmCompDef As AssemblyComponentDefinition = oOcc.Definition
			Dim oRepMan As RepresentationsManager = oAsmCompDef.RepresentationsManager
			Dim oViewReps As DesignViewRepresentations = oRepMan.DesignViewRepresentations
			Dim oViewRep As DesignViewRepresentation = oRepMan.ActiveDesignViewRepresentation
			Dim oViewRepName As String = oViewRep.Name
'			MessageBox.Show(oOcc.Name & vbCr & oOcc.DefinitionDocumentType & vbCr & oViewRepName)
			If oViewRepName <> "[Primary]" Then
				oViewReps.Item("[Primary]").Activate()
			End If
			If oOcc.SubOccurrences IsNot Nothing Then
				Call ChangeRepresent(oOcc.SubOccurrences)
			End If
		End If
	Next
End Function

 

Andrii Humeniuk - CAD Coordinator, Autodesk Certified Instructor

LinkedIn | My free Inventor Addin | My Repositories

Did you find this reply helpful ? If so please use the Accept as Solution/Like.

EESignature

0 Likes