Create representation view in assembly

Create representation view in assembly

manu.marjanen
Advocate Advocate
747 Views
3 Replies
Message 1 of 4

Create representation view in assembly

manu.marjanen
Advocate
Advocate

Is it possible to make code that create view representation in assembly level? 

For example,

View representation name "Test" including parts "Part:1, Part:2, Part:3" are visibility.

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

JMGunnar
Collaborator
Collaborator

 

here one exampel  @manu.marjanen  -> 

Start with all component visibility , Default design view 

 

Best Regards Johan G

 

 

Class ThisRule
	Sub Main()
	
	Dim refs As New List(Of String)
		refs.Add("Part1:1")
		refs.Add("Part2:2")
		refs.Add("Part:3")
		
		
	CreateDesignViewWithComponents(refs, "Test", False)
	
	refs.Clear()
	
	refs.Add("Part:1")

	CreateDesignViewWithComponents(refs, "Test2", False)
	
	
	End Sub
	
	Public Sub CreateDesignViewWithComponents(RefChainList As List(Of String), nameOfDesignView As String, Optional createLoD As Boolean = False)
			Dim odoc As AssemblyDocument = ThisDoc.Document
			Dim oAssDef As AssemblyComponentDefinition = odoc.ComponentDefinition
			Dim dvrs As DesignViewRepresentations = oAssDef.RepresentationsManager.DesignViewRepresentations
			
			Dim currentDvrName As String = oAssDef.RepresentationsManager.ActiveDesignViewRepresentation.Name

			Dim dvr As DesignViewRepresentation
			Try
				dvrs.Item(nameOfDesignView).Delete
				dvr = dvrs.Add(nameOfDesignView)
			Catch

				dvr = dvrs.Add(nameOfDesignView)
			End Try
			
			Dim ReturnedOcc As Inventor.ComponentOccurrence
			Dim occColl As ObjectCollection 
		
			If ThisApplication Is Nothing Then
				occColl = ThisServer.TransientObjects.CreateObjectCollection
			Else
				occColl = ThisApplication.TransientObjects.CreateObjectCollection
			End If
			
			Dim item As String
			
			Dim oCompDef As Inventor.ComponentDefinition = odoc.ComponentDefinition
			'define the first level components collection
			Dim oCompOcc As Inventor.ComponentOccurrence

			'Turn off the visibility of parts in the top level assembly that don't contain the specified text string (StrInput1)
			For Each oCompOcc In oCompDef.Occurrences
				
					For Each item In RefChainList
						If oCompOcc.Name = item Then
							oCompOcc.Visible = True	
							Try 
								oCompOcc.SetDesignViewRepresentation("Drawing")
							Catch
								
							End Try
							
						  	Exit For 	
						Else
							oCompOcc.Visible = False	
						End If 
					Next
			Next
			
			dvr.Locked = True
			
			Dim LoDrs As LevelOfDetailRepresentations = oAssDef.RepresentationsManager.LevelOfDetailRepresentations
			Dim LoDr As LevelOfDetailRepresentation
			If createLoD = True Then
				Try
					LoDrs.Item(nameOfDesignView).Delete
					LoDr = dvr.CopyToLevelOfDetail
				Catch
	
					LoDr = dvr.CopyToLevelOfDetail
				End Try
			End If


			dvrs.Item(currentDvrName).Activate

	End Sub
	
End Class

 

0 Likes
Message 3 of 4

manu.marjanen
Advocate
Advocate
I do not quite understand everything. Can that be done somehow more simply?
0 Likes
Message 4 of 4

TomaszDąbrowski
Enthusiast
Enthusiast
Accepted solution
Dim oDoc As AssemblyDocument = ThisDoc.Document
Dim oRef1 As String = "Part:1"
Dim oRef2 As String = "Part:2"
Dim oRef3 As String = "Part:3"

Try
oDoc.ComponentDefinition.RepresentationsManager.DesignViewRepresentations.Item("test").Activate
Catch
oDoc.ComponentDefinition.RepresentationsManager.DesignViewRepresentations.Add("test")
End Try

For Each oOcu As ComponentOccurrence In oDoc.ComponentDefinition.Occurrences
	If oOcu.Name <> oRef1 And oOcu.Name <> oRef2 And oOcu.Name <> oRef3 Then
		oOcu.Visible = False
	Else
		oOcu.Visible = True
	End if
	Next
0 Likes