- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Suppress all contraints on suppressing the component
Hi Community,
I apologize if this question has been asked before. I am trying to suppress all the constraints when the component is suppressed, and do the same for unsuppress. I created a code but it is not working.
Thank you.
Dim aDoc As AssemblyDocument = ThisApplication.ActiveDocument
Dim oCon As AssemblyConstraint
Dim oJon As AssemblyJoint
Dim oOcc As ComponentOccurrence
Dim i As Integer
For i = 1 To aDoc.SelectSet.Count
oOcc = aDoc.SelectSet.Item(i)
If oOcc.Suppressed = True Then
For Each oCon In oOcc.Constraints
oCon.Suppressed = True
Next
For Each oJon In oOcc.Joints
oJon.Suppressed = True
Next
ElseIf oOcc.Suppressed = False Then
For Each oCon In oOcc.Constraints
oCon.Suppressed = False
Next
For Each oJon In oOcc.Joints
oJon.Suppressed = False
Next
End If
Next
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Where exactly does it fail, did you find that out? I expect it will not process the exact constraints that you are trying to suppress in the loops. I have experienced that when an occurrence is suppressed, not all his properties and methods are accessible by API anymore.
If that is the case, you might first want to unsuppress the occurrence, suppress his constraints and then suppress the occurrence again.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi @_dscholtes_ ,
I tried with unsuppress + suppress + unsuppress. But it did not work. I cannot figure out why does it not looping through a component and suppress all the constraints.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
There is a question from my end, let's assume you have two components that are connected with one constraint, and you want one of that component to be suppressed, now as you know, in Inventor Mate:1 is shared between two components, if you run an iLogic rule that actually checks if the component is suppressed or not and if it is it will suppress its a constraint, but as Mate:1, in this case, is shared and the second component is not suppressed, so the rule will not suppress the constraint.
Think about it and share your thoughts,
For the time being, I have created a code for you that actually checks if the component is suppressed or not and if it is it will suppress its constraints, but if any of the components are not suppressed it will not suppress the constraint.
To check this code, please suppress both the components (which are sharing the same constraint) and then run the rule below. Also, note that you must have to create a custom level of detail to make this work, it will not work in the Master level of detail, if you are not using Inventor 2022.
Dim oDoc As AssemblyDocument = ThisApplication.ActiveDocument Dim oDef As AssemblyComponentDefinition = oDoc.ComponentDefinition Dim oCon As AssemblyConstraint Dim oJon As AssemblyJoint Dim oOcc As ComponentOccurrence Dim i As Integer For Each oOcc In oDef.Occurrences If oOcc.Suppressed = True For Each oCon In oOcc.Constraints oCon.Suppressed = True Next Else If oOcc.Suppressed = False For Each oCon In oOcc.Constraints oCon.Suppressed = False Next End If Next
Hope this helps.
Regards,
Dutt Thakar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi @dutt.thakar ,
Thanks for the reply.
When we exclude any component, it also excludes its constraints. I want to achieve the same thing with suppression. Inventor does not do that out of the box, therefore I am using Inventor API.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
@dutt.thakar wrote:
There is a question from my end, let's assume you have two components that are connected with one constraint, and you want one of that component to be suppressed, now as you know, in Inventor Mate:1 is shared between two components, if you run an iLogic rule that actually checks if the component is suppressed or not and if it is it will suppress its a constraint, but as Mate:1, in this case, is shared and the second component is not suppressed, so the rule will not suppress the constraint.
Think about it and share your thoughts,
No need to assume when we can simply test. I created an assembly containing three cubes in a row. The first one is placed and grounded at origin, the others are constrained to the previous one. When I suppress the middle one (which is constrained to both others) , its constraints are not suppressed. However, I can suppress the constraints manually, which means it should also be possible by iLogic. I tested this with the posted code and the constraints can be suppressed (whatever status of the occurrence on the other end of the constraint).
It also showed me that some constraints that should be suppressed were not suppressed when the code was finished. What if I told you the fix is to remove the loop that un-suppresses the constraints when the occurrence is not suppressed?
Spoiler: the suppressed occurrence is processed before the un-suppressed ones that it is constrained to.
So first the constraints are suppressed, but later-on they are un-suppressed again.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Thanks for the reply.
I tried eliminating the loop for unsuppress, but it is still not working for me. I will investigate more today.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Yes, I totally understand that, and that is why I am asking @shrey9GP3F if a constraint is shared between two components and we are suppressing one component and not the other, so he really wants to suppress a constraint that is also depending on a component that is not suppressed.?
If you remove the unsuppressed loop it will suppress the constraint but, if the constraint is shared it will suppress the constraint for the unsuppressed component also.
P.S : I know about spoiler also and that is why I am asking, what is the exact intention of achieving this, as there will be suppressed constraints for a component which is unsuppressed and vice versa, as this will be a cyclic dependency between constraints and suppressed/unsuppressed components.
Hope this helps.
Regards,
Dutt Thakar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
If shared constraints should not be suppressed, then no constraints will be suppressed. This is a result @shrey9GP3F may not have thought of (and makes running the code pointless).
If shared constraints should be suppressed, then it is possible that an unsuppressed occurrence is no longer fully constrained and can be moved, thereby modifying the model (unless it was grounded).
I have not used 'exclude', so I do not know what it does exactly. Trying to imitate some of its behavior is not without trouble and needs careful consideration.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
@_dscholtes_ @dutt.thakar All I want to do is when I suppress Part2, the associative mates should be suppressed too.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hey Guys How About the Joint. ?
Theare Only Works For Constrain...
The First Code Above With Joint to.
I try For the Joint Code. But Not Work.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi @drafter_sby2. All you can do is try. If it does not work, then there is your answer. The process is still pretty much the same. Only since the 2022 version, we are working with ModelStates, instead of LevelOfDetailRepresentations, which are what records suppression status. ModelStates sort of made it slightly simpler, since the default ModelState is not 'locked' (which some folks want to make happen), but the introduction of ModelStates also greatly complicated a lot of things that we do by code.
Sub Main
Dim oADoc As AssemblyDocument = TryCast(ThisDoc.Document, Inventor.AssemblyDocument)
If oADoc Is Nothing Then Return
For Each oOcc As ComponentOccurrence In oADoc.ComponentDefinition.Occurrences
If oOcc.Suppressed Then
ConstraintAndJointSuppression(oOcc, True)
Else
ConstraintAndJointSuppression(oOcc, False)
End If
Next
oADoc.Update2(True)
End Sub
Sub ConstraintAndJointSuppression(oOcc As ComponentOccurrence, bSuppress As Boolean)
For Each oConst As AssemblyConstraint In oOcc.Constraints
Try : oConst.Suppressed = bSuppress : Catch : End Try
Next
For Each oJoint As AssemblyJoint In oOcc.Joints
Try : oJoint.Suppressed = bSuppress : Catch : End Try
Next
End Sub
Wesley Crihfield
(Not an Autodesk Employee)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi @drafter_sby2 , welcome to the forum.
If you're using iLogic you can use Capture Current State on the Joint to get /set it's status.
You can do the same for the component(s) it is constrained to.
Here is an example where the 3rd lego is toggled on or off, and the Joint is active only when both of the components it uses is active... if one is not then the Joint's active status is false.
Hope that helps, Curtis
Component.IsActive("Lego:3") = Not Component.IsActive("Lego:3") Joint.IsActive("Rotational:1") = (Component.IsActive("Lego:2") And Component.IsActive("Lego:3"))
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Yes, This Awesome.. Solve For me.
Thank u Sir. @WCrihfield
This Code Is Very Easy To Add For Assembly Template And Combine with iTriger.
Where Inventor Didn't Automatic Suppress Constrain and Joint. Not Like Solidworks Or Else.
Yes u Are Right too.. but is Hard To Code 1 By 1. For Each Part...
And We Should do manual Selection Which Part is Active.
Or Some Case you Need To Create The Other Rule For Selction