iLogic to Lock Rotation

iLogic to Lock Rotation

Formsprag
Advocate Advocate
2,563 Views
17 Replies
Message 1 of 18

iLogic to Lock Rotation

Formsprag
Advocate
Advocate

Can iLogic be used to add the "Lock Rotation" check box to all Insert constraints in an existing assembly file? 

0 Likes
Accepted solutions (1)
2,564 Views
17 Replies
Replies (17)
Message 2 of 18

JhoelForshav
Mentor
Mentor

Hi @Formsprag 

 

This should do the trick 🙂

 

Dim oAsm As AssemblyDocument = ThisDoc.Document
Dim oCompDef As AssemblyComponentDefinition = oAsm.ComponentDefinition
For Each oConst As AssemblyConstraint In oCompDef.Constraints
	If oConst.Type = kInsertConstraintObject
		Dim oName As String = oConst.Name
		oConst = oConst.ConvertToInsertConstraint2(oConst.EntityOne, oConst.EntityTwo, oConst.AxesOpposed, oConst.Distance.Value, True)
		On Error Resume Next
		oConst.Name = oName
	End If
Next
Message 3 of 18

Formsprag
Advocate
Advocate

You were right, that did the trick for sure! you gave me exactly what I asked for, however, I don't think the result was what I was looking for. I didn't ask the right question. Let me give you a little more detail, my company places all fasteners in one assembly referred as a fastener kit, when this sub-assembly is brought into the master assembly it is made flexible and then constraints are placed. I need this rule to allow me to pick that fastener kit sub-assembly to lock the rotation on all of those fasteners.

 

 

0 Likes
Message 4 of 18

JhoelForshav
Mentor
Mentor

Hi @Formsprag 

Is this what you're looking for?

 

Sub Main
Dim oAsm As Document = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kAssemblyOccurrenceFilter, "Select sub-assembly").Definition.Document
If oAsm.DocumentType <> kAssemblyDocumentObject Then
	MsgBox("Selected occurrence is not an assembly")
	Exit Sub
End If
Dim oCompDef As AssemblyComponentDefinition = oAsm.ComponentDefinition
For Each oConst As AssemblyConstraint In oCompDef.Constraints
	If oConst.Type = kInsertConstraintObject
		Dim oName As String = oConst.Name
		oConst = oConst.ConvertToInsertConstraint2(oConst.EntityOne, oConst.EntityTwo, oConst.AxesOpposed, oConst.Distance.Value, True)
		On Error Resume Next
		oConst.Name = oName
	End If
Next
End Sub
0 Likes
Message 5 of 18

Formsprag
Advocate
Advocate

Nothing happens.....

It behaves as expected, run the rule, pick the sub-assembly, cursor flashes a few seconds and nothing happens.

No errors or warnings and the constraints remain the same.

 

 

0 Likes
Message 6 of 18

JhoelForshav
Mentor
Mentor

Well thats embarrassing for me... I only have access to Inventor 2018 right now so I cannot try this all the way. (Lock Rotation doesn't exist in 2018). I did however have to write OObjectTypeEnum.kInsertConstraintObject instead of just kInsertConstraintObject in order to get it to work. like this:

 

Sub Main
Dim oAsm As Document = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kAssemblyOccurrenceFilter, "Select sub-assembly").Definition.Document
If oAsm.DocumentType <> kAssemblyDocumentObject Then
	MsgBox("Selected occurrence is not an assembly")
	Exit Sub
End If
Dim oCompDef As AssemblyComponentDefinition = oAsm.ComponentDefinition
For Each oConst As AssemblyConstraint In oCompDef.Constraints
	If oConst.Type = ObjectTypeEnum.kInsertConstraintObject 'Had to add the ObjectTypeEnum here in inventor 2018
		Dim oName As String = oConst.Name
		oConst = oConst.ConvertToInsertConstraint2(oConst.EntityOne, oConst.EntityTwo, oConst.AxesOpposed, oConst.Distance.Value, True)
		On Error Resume Next
		oConst.Name = oName
	End If
Next
End Sub

I don't think that is the problem in your case though...

I will continue to investigate as soon as I get my hands on Inventor 2020 again 🙂

0 Likes
Message 7 of 18

Formsprag
Advocate
Advocate

No different.....your first rule worked brilliantly it just locked down a couple shafts in the master assembly that I didn't intend to lock down. I can just go in and remove the lock for those components and all will be well. Thanks... 

0 Likes
Message 8 of 18

JhoelForshav
Mentor
Mentor
Now I think I understand!
The constraints are still on top level and not within the sub assembly?

I will fix this as soon 👍
0 Likes
Message 9 of 18

Formsprag
Advocate
Advocate

Exactly, I'm sorry for not being clear.....

0 Likes
Message 10 of 18

JhoelForshav
Mentor
Mentor
Accepted solution

No worries @Formsprag 

I think this should work 🙂

 

 

Dim oAsm As AssemblyDocument = ThisDoc.Document
Dim oCompDef As AssemblyComponentDefinition = oAsm.ComponentDefinition
Dim oSubOcc As ComponentOccurrence = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kAssemblyOccurrenceFilter, "Select sub-assembly")
If oSubOcc.Definition.Document.DocumentType <> kAssemblyDocumentObject
	MsgBox("The selected component is not an assembly")
	Exit Sub
End If
For Each oConst As AssemblyConstraint In oCompDef.Constraints
	If oConst.Type = ObjectTypeEnum.kInsertConstraintObject
	If oConst.OccurrenceOne Is oSubOcc Or oConst.OccurrenceTwo Is oSubOcc
		Dim oName As String = oConst.Name
		oConst = oConst.ConvertToInsertConstraint2(oConst.EntityOne, oConst.EntityTwo, oConst.AxesOpposed, oConst.Distance.Value, True)
		On Error Resume Next
		oConst.Name = oName
	End If
	End If
Next

 

Message 11 of 18

Formsprag
Advocate
Advocate

Perfect! Thanks for all your help this will be a huge time saver!

Message 12 of 18

ReneRepinaLedinek
Contributor
Contributor

(This message can be deleted, it was written from wrong account.)

 

0 Likes
Message 13 of 18

ReneRepina
Collaborator
Collaborator

@JhoelForshav 

Thanks for the iLogic rule! It will save a lot of time on old models (and even new ones).

 

I have one question though.

Is there any possibility to directly change the constraint lock rotation? For example that we do not have to convert whole constrain, but only change the propertly (oConst.LockRotation = True) (if we simulate with mouse clicks, that would be "Edit constraint --> Check Lock Rotation box")? It seems other properties can be accessed and changed like that, but not LockRotation. You can read it, but it cannot be set (I get error "Public Let 'LockRotation' on type 'InsertConstraint' not found. Use 'CallByName' function with 'CallType.Set'.", when setting the property). If we use "MsgBox(oConst.LockRotation)", it displays the value (True / False). Any ideas?

 

Edit 2021-08-05, 09:07 (CEST):

Ahh, it is an "ReadOnly" Property. Why?

0 Likes
Message 14 of 18

tobias_wiesendanger
Advocate
Advocate

I'll add to that question. Why is it only readOnly when using C#. Im able to change LockRotation in VBA and iLogic but not when I use C#.

0 Likes
Message 15 of 18

tobias_wiesendanger
Advocate
Advocate

Ah I just saw that is something that changed from version 2022 to 2023. It was readonly in 2022.

0 Likes
Message 16 of 18

ReneRepina
Collaborator
Collaborator

@tobias_wiesendanger 

 

Correct.

It was read-only in 2020, possibly also in 2021 and 2022, but I can confirm that in 2023, property is now changed to "Get / Set" instead of "Read-Only", so it can be set as "oConst.LockRotation = True" or of course with "False".

0 Likes
Message 17 of 18

sei.bun
Enthusiast
Enthusiast

Hi! @JhoelForshav 

Thanks for the iLogic rule! It helps me a lot!

Now I have a question though.

I use imate(insert) to constrain parts and washer. But it was transferred to regular constraint with lock rotation when I use your ilogic rule. 

Is there any possibility of maintaining the status quo(imate constrain) and just lock rotation? 

Any comments or suggestions will be appreciated!

Message 18 of 18

ReneRepina
Collaborator
Collaborator

Hello @sei.bun .

 

Above code can be simplified, since there is now a "get/set" property "LockRotation" (oConst.LockRotation = True). I can confirm this property exists and works in 2023, but I am not sure, if it is already in prior versions.

 

As for your case, I did some testing and digging. It seems that there is currently no way to lock "Insert iMates" via iLogic. It can be manually edited and locked - this means that property exists, but it is not visible in the iLogic, maybe because it is a "private" property. I have tried to pinpoint where this property is and according to Autodesk's documentation (link below) and my logic, it should be here "oConst.iMateResult.LockRotation", but it is not. I also checked the API documentation and there is no "LockRotation" property for "iMates".

 

Sorry that I could not help you. You can also try to contact Autodesk support and/or post on "Inventor Ideas".

 

Autodesk's documentation:

https://help.autodesk.com/view/INVNTOR/2023/ENU/?guid=GUID-97DD5557-FAEE-46FA-845D-11123D725BA9

 

Quote:

"Lock Rotation is only available when creating an Insert constraint or editing an iMate result. "

 

 

Best regards,

Rene Repina

0 Likes