Set a component in an assembly with it's active view representation

Set a component in an assembly with it's active view representation

gprimonBVPBY
Explorer Explorer
91 Views
4 Replies
Message 1 of 5

Set a component in an assembly with it's active view representation

gprimonBVPBY
Explorer
Explorer

Hello,

I have a component with different view representations.

I would like to write a rule in i logic  in the assembly file that read the active view representation of the part file and set the view representation of the component. Is that possible?

Thank in advance for any help

0 Likes
Accepted solutions (1)
92 Views
4 Replies
Replies (4)
Message 2 of 5

WCrihfield
Mentor
Mentor

Hi @gprimonBVPBY.  Below is one possible example of an iLogic rule for that type of task.  To keep it simple, this example just asks you to manually select the component with your mouse when you run the rule.  It then attempts to dig down into its definition, representations manager, and get the name of the active DVR (DesignViewRepresentation).  Then it uses a method of the component to set that as the component's active DVR, and set that to 'Associative' at the same time.

Dim oPickedOcc As ComponentOccurrence = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kAssemblyOccurrenceFilter, "Select a Component.")
If oPickedOcc Is Nothing Then Return
Dim oCD As Inventor.ComponentDefinition = oPickedOcc.Definition
Dim oRepsMgr As Inventor.RepresentationsManager = oCD.RepresentationsManager
Dim sDVR As String = oRepsMgr.ActiveDesignViewRepresentation.Name
oPickedOcc.SetDesignViewRepresentation(sDVR,,True)

Some of it will not have any 'Intellisence' hints available when you hover your mouse over it within the iLogic rule editor dialog, but it should still work.  If the component was suppressed, then this code would throw an error though, because we can not do much with a suppressed component by code.  If the component were a 'virtual' one, that might also throw an error, because virtual components are just for BOM purposes, and do not really reference a Document, so it would not have any DVRs.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 5

gprimonBVPBY
Explorer
Explorer

Hello Wesley,

Thank you very much for your help!

The code you sent me works fine. I'm trying to make something that will set all the components in their active view representation without any action needed.

I was thinking at something like that:

Dim oAsmDoc As AssemblyDocument = ThisApplication.ActiveDocument


Dim oOccurrences As ComponentOccurrences = oAsmDoc.ComponentDefinition.Occurrences

For Each oOccurrence As ComponentOccurrences In oOccurrences

	Dim oRepsMgr As Inventor.RepresentationsManager = oOccurrences.RepresentationsManager
	Dim sDVR As String = oRepsMgr.ActiveDesignViewRepresentation.Name
	oOccurrences.SetDesignViewRepresentation(sDVR,,True)
	
Next

But I can't make it work... 

0 Likes
Message 4 of 5

WCrihfield
Mentor
Mentor
Accepted solution

Hi @gprimonBVPBY.  Looks like you are using the wrong variable ('oOccurrences' vs 'oOccurrence') within your iteration, then skipping over the 'Definition' property.  Try the following version.  If your assembly contains any suppressed components, then they must be skipped over, or you will encounter errors that will stop the rule.  Also, if your assembly is a weldment type, and contains any weld beads, then you will have to skip over the component occurrence representing the welds.  If your assembly contains any 'virtual' components, they you will want to skip over those too.  So, I included those lines of code for skipping over those types of occurrences in the example below.

Dim oADoc As AssemblyDocument = TryCast(ThisDoc.Document, Inventor.AssemblyDocument)
If oADoc Is Nothing Then Return
For Each oOcc As ComponentOccurrence In oADoc.ComponentDefinition.Occurrences
	If oOcc.Suppressed Then Continue For
	If TypeOf oOcc.Definition Is VirtualComponentDefinition Then Continue For
	If TypeOf oOcc.Definition Is WeldsComponentDefinition Then Continue For
	Dim sDVR As String = oOcc.Definition.RepresentationsManager.ActiveDesignViewRepresentation.Name
	oOcc.SetDesignViewRepresentation(sDVR,,True)
Next
oADoc.Update2(True

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 5 of 5

gprimonBVPBY
Explorer
Explorer

That's exactly what I was looking for. Many thanks

0 Likes