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: 

Changing Positional Representation Using iLogic

13 REPLIES 13
SOLVED
Reply
Message 1 of 14
dodrain
3810 Views, 13 Replies

Changing Positional Representation Using iLogic

Can anybody help me what command i neet to use to change between different Positional Representations?

 

 

13 REPLIES 13
Message 2 of 14
Curtis_Waguespack
in reply to: dodrain

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

 

Message 3 of 14

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

Message 4 of 14

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
Message 5 of 14

Need to add a progress bar to indicate that it is running.

Need to add:

ThisApplication.CommandManager.ControlDefinitions.Item("AppViewCubeHomeCmd").Execute

 

All suggestions appreciate.

Message 6 of 14

@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

--------------------------------------
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 7 of 14

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.

Message 8 of 14


@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

Message 9 of 14

That is really good.

It gives the running indication - Thanks a lot.

Message 10 of 14


@RoyWickrama_RWEI wrote:

 

It gives the running indication - Thanks a lot.


Hi @RoyWickrama_RWEI,

 

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

 

Message 11 of 14

Is there a way to accomplish this with a subassembly? I would like to change the representation position inside of a subassembly using ilogic??

Message 12 of 14

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" .

Message 13 of 14

Hi @Jolanta_Voigt 

 

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

 

Message 14 of 14

I appreciate that, thank you. I needed it to insert into rules I currently have to Simplify and save each iAssebmly member as stp but I needed it saved in the Flipped position.

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

Post to forums