Hi, I have posted this elsewhere but have gotten no response, so I'm trying it here. I have an iassembly whose table controls material of the parts and subassemblies: carbon steel / stainless steel. For the carbon steel configuration, the parts are painted various colors. For stainless, the parts receive no paint. I have design view representations set up in the top level assembly to control colors of the various components. These view reps work just fine by manual selection. However, I want to associate them to the table so that when a factory member is selected, the corresponding view rep is activated.
After considerable experimentation, I can't seem to figure out how to do this. Apparently Inventor (2013) doesn't give you the option to select the active view rep in the table. So I have been trying to do this using iLogic. I am little more than a novice with iLogic / VB, so I did some searching online to find someone else's code to adapt to my situation. Everything I have tried has given me errors; i.e., the code doesn't run properly in the copied format.
Does anyone have any clever tricks in mind for managing design view representations in the iassembly table, or can anyone write the little bit of code that will let me control the active design view representation?
Thanks in advance,
Solved! Go to Solution.
Are you using ETO? You mention iLogic and VB, but this is an ETO forum. Given the context of your post I took a look at this from an VB (Inventor API) perspective.
What you are trying to do is possible, using the Inventor API. You need to listen for the AssemblyEvents.OccurrenceChange event. Your event handler code could then check to see what changed, and set the DVR accordingly, using SetDesignViewRepresentation. You would need to be sure to put a check in the event handler code to make sure you do not set the DVR if it is already what you want, because SetDesignViewRepresentation also triggers the OccurrenceChange event.
Here is a quick and dirty example. Take it for what it is worth. The Event Handler code would need to be in its own class module:
Class module: myEventListener
Option Explicit Private WithEvents oAssemblyEvents As AssemblyEvents Public Sub init() Set oAssemblyEvents = ThisApplication.AssemblyEvents End Sub Public Sub terminate() Set oAssemblyEvents = Nothing End Sub Private Sub oAssemblyEvents_OnOccurrenceChange(ByVal DocumentObject As AssemblyDocument, ByVal Occurrence As ComponentOccurrence, ByVal BeforeOrAfter As EventTimingEnum, ByVal Context As NameValueMap, HandlingCode As HandlingCodeEnum) ' My Assembly only has one occurrence of the iAssembly Dim oAssemblyOcc As ComponentOccurrence Set oAssemblyOcc = DocumentObject.ComponentDefinition.Occurrences(1) If BeforeOrAfter = kAfter Then ' Check to see if we have an iAssemblyFactory If oAssemblyOcc.IsiAssemblyMember Then ' Choose the DVR based on the name of the iAssembly Member Select Case oAssemblyOcc.Definition.iAssemblyMember.Row.Member
Name Case "Assembly1-01" ' Check to make sure we do not set the DVR if it is already what we want, to avoid an infinite loop If StrComp(oAssemblyOcc.ActiveDesignViewRepresentatio n, "purple") <> 0 Then oAssemblyOcc.SetDesignViewRepresentation "purple", , True End If Case "Assembly1-02" If StrComp(oAssemblyOcc.ActiveDesignViewRepresentatio n, "gold") <> 0 Then oAssemblyOcc.SetDesignViewRepresentation "gold", , True End If Case "Assembly1-03" If StrComp(oAssemblyOcc.ActiveDesignViewRepresentatio n, "Default") <> 0 Then oAssemblyOcc.SetDesignViewRepresentation "Default", , True End If End Select End If End If End Sub
This code belongs in the ApplicationProject module, and it starts and stops my event listener:
Option Explicit Dim oEventListener As myEventListener Sub Listen() Set oEventListener = New myEventListener oEventListener.init End Sub Sub StopListening() oEventListener.terminate Set oEventListener = Nothing End Sub
I also added the model files that I was testing with. You should be able to:
1. Open Assembly2.iam
2. Hit Alt-F11 to open the VBA IDE
3. Add a new class module to the ApplicationProject named myEventListener, and paste in the code.
4. Paste in the ApplicationProject module code
5. Put your cursor inside the Listen() routine and hit F5
6. Back in Inventor, expand the sub assembly, right click the Table, and change the PartNumber value.
You should see the color of one of the blocks change. This is controlled by the DVR in the sub assembly.
I forgot to mention: You can find the Inventor API help installed with Inventor. It is in the <Base Install Location>\Local Help\admapi_17_0.chm.
Thanks very much, Casey. I appreciate the help. I'll give it a whirl. It may take a while since I'm new at this, but I have confidence in your appraoch. =)
Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register
Start with some of our most frequented solutions to get help installing your software.