Help to create automatically a view representation

Help to create automatically a view representation

johan.degreef
Advisor Advisor
302 Views
2 Replies
Message 1 of 3

Help to create automatically a view representation

johan.degreef
Advisor
Advisor

Hello,

Could anyone help me to create an ilogic button that would create or update a "View Representation" on the current "Model State". The button is used in an assembly.

- The view representation's name should be "PF_<modelstatename>" (model state: primary - view representation: PF_primary)

- The view representation should only show parts which custom iproperty "PTN_CODE",  does contain the values "FITT" or "VINK" or "BEND". (other parts uncheck visibility)

- It should not cycle through subassemblies

 

I think it is not that large code, but I don't know where to start.

Many Thanks if someone finds the time, Johan

Inventor 2025, Vault Professional 2025, Autocad Plant 3D 2025
0 Likes
Accepted solutions (1)
303 Views
2 Replies
Replies (2)
Message 2 of 3

jnowel
Advocate
Advocate
Accepted solution

Not sure if this is what you're looking for.
You should activate the specific ModelState for the ViewRepresentation to properly show.


Sub Main
	
    Dim oDoc As AssemblyDocument
    oDoc = ThisApplication.ActiveDocument
	
	For Each oModelState As ModelState In oDoc.ComponentDefinition.ModelStates
		
		Dim oViewRepName As String
		oViewRepName = "PF_" & oModelState.Name
		
		Dim oViewRep As DesignViewRepresentation
		Try
			oViewRep = oDoc.ComponentDefinition.RepresentationsManager.DesignViewRepresentations(oViewRepName)
		Catch
			oViewRep = oDoc.ComponentDefinition.RepresentationsManager.DesignViewRepresentations.Add(oViewRepName)
		End Try
		
		oModelState.Activate
		oViewRep.Activate
		
		'oViewRep.Locked = False
		
		For Each oOcc As ComponentOccurrence In oDoc.ComponentDefinition.Occurrences
			
			If oOcc.Suppressed = True Then Continue For
			
			Dim oOccDoc As Document
			oOccDoc = oOcc.Definition.Document
			
			Dim PTN_CODE As String
			PTN_CODE = GetCustomiPropValue(oOccDoc, "PTN_CODE")
			
			'Logger.Info(oOccDoc.DisplayName & " - " & PTN_CODE)
					
			Select Case PTN_CODE
				Case "FITT", "VINK", "BEND"
					oOcc.Visible = True
				Case Else
					oOcc.Visible = False
			End Select
		Next
		
		'oViewRep.Locked = True
		
		ThisApplication.ActiveView.GoHome	
		ThisApplication.ActiveView.Fit

	Next
	
End Sub

Function GetCustomiPropValue(oRefDoc As Document, iProp As String) As String
	
	Try
		Return oRefDoc.PropertySets.Item("User Defined Properties").Item(iProp).Value
	Catch
		Return String.Empty
	End Try
		
End Function

		
0 Likes
Message 3 of 3

johan.degreef
Advisor
Advisor

@jnowel Many thanks for this quick solution!

Inventor 2025, Vault Professional 2025, Autocad Plant 3D 2025
0 Likes