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 View Representations on Component Occurrence

2 REPLIES 2
SOLVED
Reply
Message 1 of 3
David.Berken
541 Views, 2 Replies

Create View Representations on Component Occurrence

Hello, I am trying to create an iLogic code that can create an associative view representation in an assembly. Right now I am stuck on just getting the view representations created in each component of my assembly. I continue to get the error Public member 'RepresentationsManager' on type 'ComponentOccurence' not found. Any help would be greatly appreciated.

 

Dim oDoc As Document
Dim oCompDef As ComponentDefinition
oDoc = ThisApplication.ActiveDocument
oCompDef = oDoc.ComponentDefinition

For Each oOcc In oCompDef.Occurrences
	 If Component.IsActive(oOcc.Name)
		If oOcc.DefinitionDocumentType = DocumentTypeEnum.kPartDocumentObject

			Dim oviewrep As DesignViewRepresentation

			Try
				MsgBox("Got Here")
				oOcc.SetDesignViewRepresentation("Custom",, True)
			Catch
				MsgBox("Got Here")
				oviewrep = oOcc.RepresentationsManager.DesignViewRepresentations.Add("Custom",True)
				oviewrep.activate
			End Try
		End If
	End If
Next

iLogicVb.UpdateWhenDone = True

 

2 REPLIES 2
Message 2 of 3
WCrihfield
in reply to: David.Berken

Hi @David.Berken.  The RepresentationsManager is a property of either the PartComponentDefinition or the AssemblyComponentDefinition objects.  So from the component's perspective this would be under the oOcc.Definition, but it's a bit tricky, because that returns a generic ComponentDefinition object which doesn't have the RepresentationsManager as one of its properties.  So you could check the Type of the oOcc.Definition using the TypeOf operator, then create a variable of the needed specific Type and set oOcc.Definition as its value.  Then you could access this properly, with support from the Intellisense type system (pop-up suggestions & info).

Here is some example iLogic code along the same lines as a pointer:

 

'Set or Create DesignViewRepresentations In Assembly Components
Dim oADoc As AssemblyDocument = ThisApplication.ActiveDocument
oADef = oADoc.ComponentDefinition
For Each oOcc As ComponentOccurrence In oADef.Occurrences
	If Not oOcc.Suppressed Then
		If TypeOf oOcc.Definition Is PartComponentDefinition Then
			'If oOcc.IsAssociativeToDesignViewRepresentation Then
			'Dim oPDoc As PartDocument = oOcc.Definition.Document
			'oRepsMgr = oPDoc.ComponentDefinition.RepresentationsManager
			Dim oPDef As PartComponentDefinition = oOcc.Definition
			oDVRepName = "My DVRep"
			oDVReps = oPDef.RepresentationsManager.DesignViewRepresentations
			For Each oDVRep As DesignViewRepresentation In oDVReps
				If oDVRep.Name = oDVRepName Then
					'Found it'
					oOcc.SetDesignViewRepresentation(oDVRepName, , True)
				End If
			Next
		End If
	End If
Next

 

If this solved your problem, or answered your question, please click ACCEPT SOLUTION.
Or, if this helped you, please click (LIKE or KUDOS) 👍.

If you want and have time, I would appreciate your Vote(s) for My IDEAS :light_bulb: or you can Explore My CONTRIBUTIONS

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 3 of 3
David.Berken
in reply to: WCrihfield

Thank you! This got me close enough to do what I needed to do!

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

Post to forums  

Technology Administrators


Autodesk Design & Make Report