Can anybody help me what command i neet to use to change between different Positional Representations?
Solved! Go to Solution.
Solved by Curtis_Waguespack. Go to Solution.
Hi dodrain,
Attached is a sample assembly that has this rule in it.
The rule gets the active Positional rep, then gets all of the Positional rep names and adds them to a list, then presents the list to the user and automatically sets the active Positional rep as the default in the list. Then either sets the selected Positional rep active or creates a new one, based on the user input.
I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com
'set a reference to the assembly component definition.
'This assumes an assembly document is open.
Dim oAsmCompDef As AssemblyComponentDefinition
oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition
'define pos rep
Dim oPosRep As PositionalRepresentation
Dim sPosRep As String
Dim MyArrayList As New ArrayList
'record the active view rep name
Dim sActivePosRep as String
sActivePosRep = oAsmCompDef.RepresentationsManager.ActivePositionalRepresentation.Name
For Each oPosRep In oAsmCompDef.RepresentationsManager.PositionalRepresentations
MyArrayList.add(oPosRep.Name)
Next
iArrayList = MyArrayList.Count
MyArrayList.add("*Add a new Positional Rep*")
sPosRep = InputListBox("Select from the list:", MyArrayList, sActivePosRep, "iLogic", "Positional Reps")
If sPosRep = "*Add a new Positional Rep*" Then
newPosRep = InputBox("Enter a name:", "iLogic", "New Pos Rep_" & iArrayList)
newAngle = InputBox("Enter an Angle:", "iLogic", "5")
'create new pos rep
oAsmCompDef.RepresentationsManager.PositionalRepresentations.Add(newPosRep)
myAngle = newAngle
Else
'activate the selected pos rep
oAsmCompDef.RepresentationsManager.PositionalRepresentations.Item(sPosRep).Activate
End If
'zoom all
ThisApplication.ActiveView.Fit
Hello,
I've got a question about this script, when i enter the same value of the Angle as it is in the master then the value doesn't get a override. Is there a way to force it to give it a override?
So when i change the master value, the Positional Representation stays in the position and doesn't change to.
Best regards,
Bart
Thanks Curtis. Nice example wit the inventor assembly. I used the coding for my purpose. A little more to go in my model - I keep developing using iLogic to maintain data accuracy and ease of modelling.
With your code for the Design View Representations, I developed the coding for Positional Representations and Level of Detail as well and combined in to a one. With Level of Detail part runs first, t run well as required.
Sub Main() Dim oName_PR As String 'set a reference to the assembly component definition. 'This assumes an assembly document is open. Dim oAsmCompDef As AssemblyComponentDefinition oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition oAsmCompDef.RepresentationsManager.LevelOfDetailRepresentations.Item("Master").Activate 'define pos rep Dim oLOD As LevelOfDetailRepresentation Dim oLOD_Rqd As String Dim oArray_LODs As New ArrayList 'record the active view rep name Dim oActiveLOD As String oActiveLOD = oAsmCompDef.RepresentationsManager.ActiveLevelOfDetailRepresentation.Name For Each oLOD In oAsmCompDef.RepresentationsManager.LevelOfDetailRepresentations oArray_LODs.add(oLOD.Name) Next oAsmCompDef.RepresentationsManager.LevelOfDetailRepresentations.Item("Master").Activate iArrayList = oArray_LODs.Count oLOD_New = "To create new, CLICK!" oArray_LODs.add(oLOD_New) oLOD_Rqd = InputListBox("Select PREF from the list:", oArray_LODs, oActiveLOD, "iLogic", "SET Positional Rep. (PREF)") If oLOD_Rqd = oLOD_New Then newPosRep = InputBox("Enter a name:", "iLogic", "New Pos Rep_" & iArrayList) newAngle = InputBox("Enter an Angle:", "iLogic", "5") 'create new pos rep oAsmCompDef.RepresentationsManager.LevelOfDetailRepresentations.Add(newPosRep) myAngle = newAngle Else 'activate the selected pos rep oAsmCompDef.RepresentationsManager.LevelOfDetailRepresentations.Item(oLOD_Rqd).Activate End If 'activate the selected pos rep oAsmCompDef.RepresentationsManager.LevelOfDetailRepresentations.Item(oLOD_Rqd).Activate oPR() oDefault() oDVR() ThisApplication.ActiveView.Fit End Sub Sub oPR() Dim oName_PR As String 'set a reference to the assembly component definition. 'This assumes an assembly document is open. Dim oAsmCompDef As AssemblyComponentDefinition oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition oAsmCompDef.RepresentationsManager.PositionalRepresentations.Item("Master").Activate 'define pos rep Dim oPosRep As PositionalRepresentation Dim oPosRep_Rqd As String Dim oArray_PosReps As New ArrayList 'record the active view rep name Dim oActivePosRep As String oActivePosRep = oAsmCompDef.RepresentationsManager.ActivePositionalRepresentation.Name For Each oPosRep In oAsmCompDef.RepresentationsManager.PositionalRepresentations oArray_PosReps.add(oPosRep.Name) Next oAsmCompDef.RepresentationsManager.PositionalRepresentations.Item("Master").Activate iArrayList = oArray_PosReps.Count oPosRep_New = "To create new, CLICK!" oArray_PosReps.add(oPosRep_New) oPosRep_Rqd = InputListBox("Select PREF from the list:", oArray_PosReps, oActivePosRep, "iLogic", "SET Positional Rep. (PREF)") If oPosRep_Rqd = oPosRep_New Then newPosRep = InputBox("Enter a name:", "iLogic", "New Pos Rep_" & iArrayList) newAngle = InputBox("Enter an Angle:", "iLogic", "5") 'create new pos rep oAsmCompDef.RepresentationsManager.PositionalRepresentations.Add(newPosRep) myAngle = newAngle Else 'activate the selected pos rep oAsmCompDef.RepresentationsManager.PositionalRepresentations.Item(oPosRep_Rqd).Activate End If 'activate the selected pos rep oAsmCompDef.RepresentationsManager.PositionalRepresentations.Item(oPosRep_Rqd).Activate End Sub Sub oDefault() Dim doc As AssemblyDocument = ThisDoc.Document Dim oAsmCompDef As ComponentDefinition oAsmCompDef = doc.ComponentDefinition Dim oCompOcc As Inventor.ComponentOccurrence For Each oCompOcc in oAsmCompDef.Occurrences If oCompOcc.Visible = True Then If oCompOcc.DefinitionDocumentType = kAssemblyDocumentObject Then oCompOcc.SetDesignViewRepresentation("Default", True) Else End If Else End If 'oCompOcc.SetDesignViewRepresentation("Default",, True) On Error Resume Next Next End Sub Sub oDVR() 'get the current assembly Dim oDoc As AssemblyDocument oDoc = ThisApplication.ActiveDocument 'get AssemblyComponentDefinition Dim oAsmCompDef As AssemblyComponentDefinition oAsmCompDef = oDoc.ComponentDefinition 'get Manager of Representations Dim oViewRepMgr As RepresentationsManager oViewRepMgr = oAsmCompDef.RepresentationsManager 'define new ViewRep - oViewRep_Rqd 'Dim oViewRep As DesignViewRepresentation Dim oViewRep_Rqd As String Dim oArray_ViewReps As New ArrayList 'record the active view rep name Dim oActiveViewRep As String oActiveViewRep = oAsmCompDef.RepresentationsManager.ActiveDesignViewRepresentation.Name For Each oViewRep In oAsmCompDef.RepresentationsManager.DesignViewRepresentations oArray_ViewReps.add(oViewRep.Name) Next iArrayList = oArray_ViewReps.Count oViewRep_New = "To create new, CLICK!" oArray_ViewReps.add(oViewRep_New) oViewRep_Rqd = InputListBox("Select PREF from the list:", oArray_ViewReps, oActiveViewRep(2), "iLogic", "SET Design View Rep. (DVR)") If oViewRep_Rqd = oViewRep_New Then newViewRep = InputBox("Enter a name:", "iLogic", "New View Rep_" & iArrayList) 'create new pos rep oAsmCompDef.RepresentationsManager.DesignViewRepresentations.Add(newViewRep) Else 'activate the selected pos rep oAsmCompDef.RepresentationsManager.DesignViewRepresentations.Item(oViewRep_Rqd).Activate End If 'activate the selected pos rep oAsmCompDef.RepresentationsManager.DesignViewRepresentations.Item(oViewRep_Rqd).Activate End Sub
Need to add a progress bar to indicate that it is running.
Need to add:
ThisApplication.CommandManager.ControlDefinitions.Item("AppViewCubeHomeCmd").Execute
All suggestions appreciate.
@RoyWickrama_RWEI, here is a cleaned up version of your file that uses a couple shared variables to reduce the amount of lines.
Also, is bunched into a class to be able to use shared variables, and for easier portability.
And finally, from what I have read, you shouldn't need to comment for each line as the line should be easy enough to read if the variables you are using make sense. Comments should only be there to explain "Why" you are doing things a certain way, as the how is discovered by reading the code in it's written language.
Sub Main() Dim oPR As PosRepOptions oPR = New PosRepOptions(ThisApplication) End Sub Class PosRepOptions Shared oAsmCompDef As AssemblyComponentDefinition Shared oRepMgr As RepresentationsManager Sub New(oInvApp As Object) oAsmCompDef = oInvApp.ActiveDocument.ComponentDefinition oRepMgr = oAsmCompDef.RepresentationsManager Call oLODR() Call oPR() Call oDefaultDV() Call oDVR() oInvApp.ActiveView.Fit End Sub Sub oLODR() oRepMgr.LevelOfDetailRepresentations.Item("Master").Activate Dim oLOD As LevelOfDetailRepresentation Dim oLOD_Rqd As String Dim oArray_LODs As New ArrayList Dim oActiveLOD As String oActiveLOD = oRepMgr.ActiveLevelOfDetailRepresentation.Name For Each oLOD In oRepMgr.LevelOfDetailRepresentations oArray_LODs.add(oLOD.Name) Next oRepMgr.LevelOfDetailRepresentations.Item("Master").Activate iArrayList = oArray_LODs.Count oLOD_New = "To create new, CLICK!" oArray_LODs.add(oLOD_New) oLOD_Rqd = InputListBox("Select LODRep from the list:", oArray_LODs, oActiveLOD, "iLogic", "SET Level of Detail Rep. (LODRep)") If oLOD_Rqd = oLOD_New Then newPosRep = InputBox("Enter a name:", "iLogic", "New LOD Rep_" & iArrayList) oRepMgr.LevelOfDetailRepresentations.Add(newPosRep) Else oRepMgr.LevelOfDetailRepresentations.Item(oLOD_Rqd).Activate End If oRepMgr.LevelOfDetailRepresentations.Item(oLOD_Rqd).Activate End Sub Sub oPR() oRepMgr.PositionalRepresentations.Item("Master").Activate Dim oPosRep As PositionalRepresentation Dim oPosRep_Rqd As String Dim oArray_PosReps As New ArrayList Dim oActivePosRep As String oActivePosRep = oRepMgr.ActivePositionalRepresentation.Name For Each oPosRep In oRepMgr.PositionalRepresentations oArray_PosReps.add(oPosRep.Name) Next oRepMgr.PositionalRepresentations.Item("Master").Activate iArrayList = oArray_PosReps.Count oPosRep_New = "To create new, CLICK!" oArray_PosReps.add(oPosRep_New) oPosRep_Rqd = InputListBox("Select PRep from the list:", oArray_PosReps, oActivePosRep, "iLogic", "SET Positional Rep. (PRep)") If oPosRep_Rqd = oPosRep_New Then newPosRep = InputBox("Enter a name:", "iLogic", "New Pos Rep_" & iArrayList) newAngle = InputBox("Enter an Angle:", "iLogic", "5") oRepMgr.PositionalRepresentations.Add(newPosRep) myAngle = newAngle Else oRepMgr.PositionalRepresentations.Item(oPosRep_Rqd).Activate End If oRepMgr.PositionalRepresentations.Item(oPosRep_Rqd).Activate End Sub Sub oDefaultDV() On Error Resume Next Dim oCompOcc As Inventor.ComponentOccurrence For Each oCompOcc in oAsmCompDef.Occurrences If oCompOcc.Visible = True Then If oCompOcc.DefinitionDocumentType = kAssemblyDocumentObject Then oCompOcc.SetDesignViewRepresentation("Default", True) End If End If Next End Sub Sub oDVR() Dim oViewRep_Rqd As String Dim oArray_ViewReps As New ArrayList Dim oActiveViewRep As String oActiveViewRep = oRepMgr.ActiveDesignViewRepresentation.Name For Each oViewRep In oRepMgr.DesignViewRepresentations oArray_ViewReps.add(oViewRep.Name) Next iArrayList = oArray_ViewReps.Count oViewRep_New = "To create new, CLICK!" oArray_ViewReps.add(oViewRep_New) oViewRep_Rqd = InputListBox("Select DVRep from the list:", oArray_ViewReps, oActiveViewRep, "iLogic", "SET Design View Rep. (DVRep)") If oViewRep_Rqd = oViewRep_New Then newViewRep = InputBox("Enter a name:", "iLogic", "New View Rep_" & iArrayList) oRepMgr.DesignViewRepresentations.Add(newViewRep) Else oRepMgr.DesignViewRepresentations.Item(oViewRep_Rqd).Activate End If oRepMgr.DesignViewRepresentations.Item(oViewRep_Rqd).Activate End Sub End Class
Thanks a lot. I need to improve. I just know a little VB programming - but trying to use iLogic to a fullest extent. Will adapt your coding style.
@RoyWickrama_RWEI wrote:
Need to add a progress bar to indicate that it is running.
All suggestions appreciate.
Hi rwickrama,
I can provide a progress bar example if you really want it, but I've started just using the status bar for this, as it's generally just as effective and much simpler.
Just add something like this to your For Each loops or somewhere that will update frequently as the code runs, and it will give you an indicator that the code is running.
ThisApplication.StatusBarText = "Processing... "
Here's an example:
For i = 0 To 30 ThisApplication.StatusBarText = "Processing... " & i Threading.Thread.Sleep(100)' delay in millisecond Next ThisApplication.StatusBarText = "Complete!" Threading.Thread.Sleep(2000)' delay in millisecond
I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com
@RoyWickrama_RWEI wrote:
It gives the running indication - Thanks a lot.
I might have given the wrong impression with my example. I couldn't tell for sure from your reply, but I don't use that counting code as a progress bar, that was just meant to be a working example. I thought maybe that's the impression I gave.
What I generally do is more like this example where, as I'm looping through a collection (refDocs in this example) I call the name of each item into the status bar. It could be LOD name, or whatever, here it's the FullFileName of the refDoc.
This way we "flicker" the status bar with some related info that let's the user know something is happening, but generally it flickers too fast to be of any real use other than a "progress" indicator.
I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com
For Each refDoc in refDocs ThisApplication.StatusBarText = "Processing: " & refDoc.FullFileName & " ..." 'code to do lots 'of fancy 'stuff that 'takes a long time 'here... Next
Is there a way to accomplish this with a subassembly? I would like to change the representation position inside of a subassembly using ilogic??
I really like your rules that you publish.
How do I change this rule to skip the list and all the extras, a simple rule to set model to a named Position representation "Flipped" .
Try this example.
I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com
Try ThisDoc.Document.ComponentDefinition. _ RepresentationsManager.PositionalRepresentations.Item _ ("Flipped").Activate Catch End Try 'zoom all ThisApplication.ActiveView.Fit