Message 1 of 18
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Can iLogic be used to add the "Lock Rotation" check box to all Insert constraints in an existing assembly file?
Solved! Go to Solution.
Can iLogic be used to add the "Lock Rotation" check box to all Insert constraints in an existing assembly file?
Solved! Go to Solution.
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
Jhoel Forshav Download my free Inventor Addin - Hole Projector
LinkedIn | Ideas | Contributions | Blog posts | Website
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.
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
Jhoel Forshav Download my free Inventor Addin - Hole Projector
LinkedIn | Ideas | Contributions | Blog posts | Website
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.
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 🙂
Jhoel Forshav Download my free Inventor Addin - Hole Projector
LinkedIn | Ideas | Contributions | Blog posts | Website
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...
Jhoel Forshav Download my free Inventor Addin - Hole Projector
LinkedIn | Ideas | Contributions | Blog posts | Website
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
Jhoel Forshav Download my free Inventor Addin - Hole Projector
LinkedIn | Ideas | Contributions | Blog posts | Website
(This message can be deleted, it was written from wrong account.)
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?
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#.
Ah I just saw that is something that changed from version 2022 to 2023. It was readonly in 2022.
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".
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!
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