Create/Link Design View Representation for an Assembly(.iam) from Part(.ipt)

Create/Link Design View Representation for an Assembly(.iam) from Part(.ipt)

ngdnam88
Advocate Advocate
453 Views
3 Replies
Message 1 of 4

Create/Link Design View Representation for an Assembly(.iam) from Part(.ipt)

ngdnam88
Advocate
Advocate

Dears,

I'm trying creating the Design View Representations for active an Assembly, I wanna copy/link them from Part (.ipt) files that I already done before:

ngnam1988_0-1691144917364.png

Could you please help me! Thanks you!

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

Andrii_Humeniuk
Advisor
Advisor

Hi @ngdnam88 . This code takes ViewRepresentations from the first component (line 11).

Sub main()
	Dim oIvnApp As Inventor.Application = ThisApplication
	Dim oDoc As Document = oIvnApp.ActiveDocument
	If Not TypeOf oDoc Is AssemblyDocument Then Exit Sub
	Dim oAsmDoc As AssemblyDocument = oDoc
	Dim oOccs As ComponentOccurrences = oAsmDoc.ComponentDefinition.Occurrences
	If oOccs.Count = 0 Then Exit Sub
	Dim oRepMng As RepresentationsManager = oAsmDoc.ComponentDefinition.RepresentationsManager
	Dim oActView As DesignViewRepresentation = oRepMng.ActiveDesignViewRepresentation
	Dim oAsmViewReps As DesignViewRepresentations = oRepMng.DesignViewRepresentations
	Dim oOcc As ComponentOccurrence = oOccs(1)
	Dim oPartDef As PartComponentDefinition = oOcc.Definition
	Dim oViewReps As DesignViewRepresentations = oPartDef.RepresentationsManager.DesignViewRepresentations
	For Each oViewRep As DesignViewRepresentation In oViewReps
		Dim oAsmViewRep As DesignViewRepresentation
		Try
			oAsmViewRep = oAsmViewReps(oViewRep.Name)
		Catch
			oAsmViewRep = oAsmViewReps.Add(oViewRep.Name)
		End Try
		oAsmViewRep.Activate()
		oViewRep.Activate()
	Next
	oActView.Activate()
End Sub

 

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

Message 3 of 4

ngdnam88
Advocate
Advocate

Thanks @Andrii_Humeniuk 
I'm tried your code but seem as the result not correct. Code returns Design View Representation name from part to working assembly but missed Design View Representation properties that setting in part. I think we need some code to control this properties.

ngnam1988_0-1691251294115.png

Please help me. Thanks!

0 Likes
Message 4 of 4

ngdnam88
Advocate
Advocate
Accepted solution

Hi @Andrii_Humeniuk 
I got the correct result now. Here's the addition to your code:

 

 

Sub Main()
	Dim oIvnApp As Inventor.Application = ThisApplication
	Dim oDoc As Document = oIvnApp.ActiveDocument
	If Not TypeOf oDoc Is AssemblyDocument Then Exit Sub
	Dim oAsmDoc As AssemblyDocument = oDoc
	Dim oOccs As ComponentOccurrences = oAsmDoc.ComponentDefinition.Occurrences
	If oOccs.Count = 0 Then Exit Sub
	Dim oRepMng As RepresentationsManager = oAsmDoc.ComponentDefinition.RepresentationsManager
	Dim oActView As DesignViewRepresentation = oRepMng.ActiveDesignViewRepresentation
	Dim oAsmViewReps As DesignViewRepresentations = oRepMng.DesignViewRepresentations
	Dim oOcc As ComponentOccurrence = oOccs(1)
	Dim oPartDef As PartComponentDefinition = oOcc.Definition
	Dim oViewReps As DesignViewRepresentations = oPartDef.RepresentationsManager.DesignViewRepresentations
	For Each oViewRep As DesignViewRepresentation In oViewReps
		Dim oAsmViewRep As DesignViewRepresentation
		Try
			oAsmViewRep = oAsmViewReps(oViewRep.Name)
		Catch
			oAsmViewRep = oAsmViewReps.Add(oViewRep.Name)
		End Try
	Next
	For Each cActView As DesignViewRepresentation In oAsmViewReps
		Dim oAsmViewRep As DesignViewRepresentation = oAsmViewReps(cActView.Name)
		oAsmViewRep.Activate()
		Try
			oOcc.SetDesignViewRepresentation(cActView.Name,, True)
		Catch
		End Try
		oDoc.Save()
	Next
End Sub

Thank you very much! 

0 Likes