Toggle "Position Offset" for selected components in positional view.

Toggle "Position Offset" for selected components in positional view.

davis.j
Advocate Advocate
563 Views
2 Replies
Message 1 of 3

Toggle "Position Offset" for selected components in positional view.

davis.j
Advocate
Advocate

Might there be any function for the check box "Position Offset"?

I can't seem to find anything in the API help docs.

image.png

 

I am trying to build a code similarly to what was done here:

https://forums.autodesk.com/t5/inventor-ideas/lock-rotation-right-click-menu-on-insert-constraint/id...

 

Using this code as a starting template:

qLock = InputRadioBox("Select one:", "Lock Rotation", "Un-Lock Rotation", True, "ilogic")
oLock = ThisApplication.ActiveDocument

Dim oInsert As InsertConstraint

For Each oInsert In oLock.SelectSet
		Call oInsert.ConvertToInsertConstraint2( _
		oInsert.EntityOne, _
		oInsert.EntityTwo, _
		oInsert.AxesOpposed, _
		oInsert.Distance.Value, _
		qLock)
Next

 

Idea Thread:

https://forums.autodesk.com/t5/inventor-ideas/assembly-position-offset-issue/idc-p/10374152#M42377

 

 

0 Likes
Accepted solutions (2)
564 Views
2 Replies
Replies (2)
Message 2 of 3

Ralf_Krieg
Advisor
Advisor
Accepted solution

Hello

 

Can you try this one?

Dim oAssDoc As AssemblyDocument = ThisDoc.Document
Dim oAssCompDef As AssemblyComponentDefinition=oAssDoc.ComponentDefinition
Dim oOcc As ComponentOccurrence
Dim oObj As Object 
Dim oPosRep As PositionalRepresentation = oAssCompDef.RepresentationsManager.ActivePositionalRepresentation 
Dim oTrans As Transaction = ThisApplication.TransactionManager.StartTransaction(oAssDoc, "Activate Position Offset")

Dim qPosOffset As Boolean = InputRadioBox("Select one:", "Position Offset activate", "Postion Offset deactivate", True, "iLogic")

For Each oObj In oAssDoc.SelectSet 
	oOcc = TryCast(oObj, ComponentOccurrence)
	If oOcc IsNot Nothing Then
		If qPosOffset Then
			oPosRep.SetTransformOverride(oOcc, oOcc.Transformation)
		Else
			oPosRep.RemoveTransformOverride(oOcc)
		End If
	End If
	oOcc=Nothing
Next

oTrans.End

R. Krieg
RKW Solutions
www.rkw-solutions.com
Message 3 of 3

davis.j
Advocate
Advocate
Accepted solution

Thank you @Ralf_Krieg , this is much appreciated.

 

There was some small edits I made to make the code more stable. I set it to continue the rule only if the active positional view does not =  "Master". It isn't written the cleanest but it works for me. 😀

 

Dim oAsmCompDef As AssemblyComponentDefinition
oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition

If oAsmCompDef.RepresentationsManager.ActivePositionalRepresentation.Name <> "Master" Then

	Dim oAssDoc As AssemblyDocument = ThisDoc.Document
	Dim oAssCompDef As AssemblyComponentDefinition=oAssDoc.ComponentDefinition
	Dim oOcc As ComponentOccurrence
	Dim oObj As Object 
	Dim oPosRep As PositionalRepresentation = oAssCompDef.RepresentationsManager.ActivePositionalRepresentation 
	Dim oTrans As Transaction = ThisApplication.TransactionManager.StartTransaction(oAssDoc, "Activate Position Offset")

	Dim qPosOffset As Boolean = InputRadioBox("Select one:", "Position Offset activate", "Postion Offset deactivate", True, "iLogic")

	For Each oObj In oAssDoc.SelectSet 
		oOcc = TryCast(oObj, ComponentOccurrence)
		If oOcc IsNot Nothing Then
			If qPosOffset Then
				oPosRep.SetTransformOverride(oOcc, oOcc.Transformation)
			Else
				oPosRep.RemoveTransformOverride(oOcc)
			End If
		End If
		oOcc=Nothing
	Next

	oTrans.End
Else
	MessageBox.Show("Please activate a Positional view first.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Stop)
End If

 

0 Likes