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: 

Control Positional Reps With ILogic

8 REPLIES 8
SOLVED
Reply
Message 1 of 9
Paul__H
2352 Views, 8 Replies

Control Positional Reps With ILogic

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

 

 

8 REPLIES 8
Message 2 of 9
adam.nagy
in reply to: Paul__H

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,



Adam Nagy
Autodesk Platform Services
Message 3 of 9
Paul__H
in reply to: adam.nagy

 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

Message 4 of 9
adam.nagy
in reply to: Paul__H

You're welcome! 🙂

 

I'm glad you managed to turn it into what you need.



Adam Nagy
Autodesk Platform Services
Message 5 of 9
MechMachineMan
in reply to: adam.nagy

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)

 


--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
Message 6 of 9
Paul__H
in reply to: MechMachineMan

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

Message 7 of 9
MechMachineMan
in reply to: Paul__H

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.


--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
Message 8 of 9
Paul__H
in reply to: MechMachineMan

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

Message 9 of 9
MechMachineMan
in reply to: Paul__H

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.


--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type

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

Post to forums  

Autodesk Design & Make Report