Hello,
(New Programmer)
Does anyone know how to control Positional Reps of a subassembly with Ilogic, What I'm trying to achieve is to change/set every other occurrence from Master Positional Design Rep to Position1 as you can see from the 2 attached pictures this can be done manually. Also I have been able to iterate through the occurrences and change the colours of every other cylinder please see pictures and the ilogic code I have put together through other peoples code (Many Thanks)
I would Appreciate any help I can get.
Thanks In Advance
Paul Hurley
' File path & File to use oPath = "Q:\Inventor\Development\Silo_Standardisation\Test Folder For Ilogic\iLogic Place Component in Assembly\iLogic Place Component in Assembly\STRAKE_PRIMARY_A.iam" Dim offsetCyl As Double = 1000 Dim cylHeight As Double = 181 Dim i As Integer = 0 Dim j As Integer = 0 Dim oAsmCompDef As AssemblyComponentDefinition oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition Dim oTG As TransientGeometry = ThisApplication.TransientGeometry Dim oMatrix As Matrix = oTG.CreateMatrix Dim oOccurrence As ComponentOccurrence oMatrix.SetTranslation(oTG.CreateVector(0, 0, offsetCyl)) ' Insert Loop Dim Total As Integer Total = InputBox("Type How Many", "Insert", "3") For i = 1 To Total ' Place Assy oOccurrence = oAsmCompDef.Occurrences.Add(oPath, oMatrix) oMatrix.SetTranslation(oTG.CreateVector(0, 0, cylHeight * i + offsetCyl)) oOccurrence.Grounded = False Next i Dim StrakeString As String For j = 1 To Total Select Case j Case 1,3,5,7,9 StrakeString = "STRAKE_PRIMARY_A:" & j Component.Color(StrakeString)= "RED" MessageBox.Show(StrakeString, "Title") Case 2,4,6,8,10 StrakeString = "STRAKE_PRIMARY_A:" & j Component.Color(StrakeString)= "YELLOW" MessageBox.Show(StrakeString, "Title") End Select Next j ThisApplication.ActiveView.Fit
Solved! Go to Solution.
Solved by MechMachineMan. Go to Solution.
Solved by adam.nagy. Go to Solution.
Solved by adam.nagy. Go to Solution.
Hi,
In theory you would just need to change the ActivePositionalRepresentation property of the ComponentOccurrence you want to change:
http://adndevblog.typepad.com/manufacturing/2013/07/switch-to-next-representation.html
Cheers,
Hi Adam,
I did try the code you pointed me towards but it wasnt quite what i wanted, between me and my boss we did get it to work this was the code we came up with. This did push us down the road of learning how to start reading the Inventor API.
Public Sub SetPositionalReps() Dim oAsmDoc As AssemblyDocument Set oAsmDoc = ThisApplication.ActiveDocument Dim oAsmDef As AssemblyComponentDefinition Set oAsmDef = ThisApplication.ActiveDocument.ComponentDefinition Dim oC As ComponentOccurrences Set oC = oAsmDef.Occurrences Dim oOcc As ComponentOccurrence Dim pos As Integer pos = 1 Dim oPosRep As PositionalRepresentation Set oPosRep = oAsmDef.RepresentationsManager.PositionalRepresentations("Position1") For Each oOcc In oC If pos = 1 Then Call oPosRep.SetPositionalRepresentationOverride(oOcc, "Position1") pos = 0 Else Call oPosRep.RemovePositionalRepresentationOverride(oOcc) pos = 1 End If Next End Sub
Also Chris from Symetry sent us some code.
'Itterates Through The Assembly To Switch Every Other Occurrance to Position 1 Dim oDoc as document oDoc = ThisDoc.Document Dim oCompDef As Inventor.ComponentDefinition oCompDef = oDoc.ComponentDefinition 'Top level rep Try oCOmpDef.RepresentationsManager.PositionalRepresentations("Position1").Activate Catch oCOmpDef.RepresentationsManager.PositionalRepresentations.add("Position1") End Try 'Each Sub assy override rep i=1 Dim oCompOcc As ComponentOccurrence For Each oCompOcc In oCompDef.Occurrences If i Mod 2 = 0 Then oCompOcc.ActivePositionalRepresentation = "Position1" Else oCompOcc.ActivePositionalRepresentation = "Master" End If i = i+1 Next
This works for us.
Once again thanks for your help its much appreciated.
Regards
Paul Hurley
I have been trying to accomplish the same thing, but oddly enough it isn't changing it in the tree....
I have had to work around by using the .Edit method followed by the .ExitEdit method to refresh the document...
Dim oDoc As Document = ThisApplication.ActiveDocument Dim oOcc As ComponentOccurrences = ThisApplication.ActiveDocument.ComponentDefinition.Occurrences Dim oCyl2 As ComponentOccurrence oCyl2 = oOcc.ItemByName("Cylinder:1") oCyl2.ActivePositionalRepresentation = "EXTENDED" oCyl2.Edit oCyl2.ExitEdit(ExitTypeEnum.kExitToParent)
Hi, Thanks for your interest in this topic. I did manage to do it with the code i posted before but will give your code a try when i get time and get back to you and let you know. one thing is that my code 'im using overrides the positional rep only this only affects the assembly with all the same cylinders in it and not the single cylinder assembly.
SetPositionalRepresentationOverride
Regards
Paul
Yeah, I had noticed that. I was trying to accomplish individual cylinder control so I could control them all with top-level parameter changes.
This is the only method I have found that will actually change and update the positional reps of individual occurrences, and have it update in the top level assembly browser nodes.
Seems very inefficient to have to open and edit the Occurrences to get it to show (although the movement still happens without the browser node updating), so I am guessing that this is some sort of bug.
Just a thought have you created a positional rep on the assembly where your sub assemblies are, which you are trying to change the positional reps ?
I usually create a positional rep at top level.
Cheers Paul
No, I haven't.... The intent is to use this part just as a sort of "free change" just to move around the various parts.
It probably would be a good idea to use the top level positional representations for views that will likely be used again, to reduce the amount of tweaking needed to be done by the end user.