Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Create representation view in assembly

3 REPLIES 3
SOLVED
Reply
Message 1 of 4
manu.marjanen
542 Views, 3 Replies

Create representation view in assembly

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.

3 REPLIES 3
Message 2 of 4
JMGunnar
in reply to: manu.marjanen

 

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

 

Message 3 of 4
manu.marjanen
in reply to: JMGunnar

I do not quite understand everything. Can that be done somehow more simply?
Message 4 of 4

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

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Technology Administrators


Autodesk Design & Make Report