Need to Suppress Constrains/Mates of Suppressed Parts or Sub assembly in Top Assembly

Need to Suppress Constrains/Mates of Suppressed Parts or Sub assembly in Top Assembly

vdcrocks7
Contributor Contributor
1,917 Views
11 Replies
Message 1 of 12

Need to Suppress Constrains/Mates of Suppressed Parts or Sub assembly in Top Assembly

vdcrocks7
Contributor
Contributor

Hi, need help, I want to suppress constrains of that part or sub assembly, which are suppressed in Top assembly.

0 Likes
Accepted solutions (2)
1,918 Views
11 Replies
Replies (11)
Message 2 of 12

vdcrocks7
Contributor
Contributor

@WCrihfield , please help me on this topic

0 Likes
Message 3 of 12

WCrihfield
Mentor
Mentor
Accepted solution

Hi @vdcrocks7.  What you are asking for definitely sounds possible to do with an iLogic rule.  Try the code example below for that task.  I tested it on one of my own assemblies, and it seemed to work the way you seem to want it to.  It essentially iterates through all of the top level assembly components, finds just the ones that are suppressed, then gets the collection of assembly constraints associated with that component, then iterates through those.  If they are not already suppressed, it will suppress them.

Sub Main
	Dim oADoc As AssemblyDocument = TryCast(ThisDoc.Document, Inventor.AssemblyDocument)
	If oADoc Is Nothing Then Logger.Debug(iLogicVb.RuleName & " exited (no AssemblyDocument obtained)") : Return
	Dim oADef As AssemblyComponentDefinition = oADoc.ComponentDefinition
	Dim oConsts As AssemblyConstraints = oADef.Constraints
	Dim oOccs As ComponentOccurrences = oADef.Occurrences
	For Each oOcc As ComponentOccurrence In oOccs
		If oOcc.Suppressed Then
			Dim oOccConsts As AssemblyConstraintsEnumerator = oOcc.Constraints
			If oOccConsts.Count > 0 Then
				For Each oOccConst As AssemblyConstraint In oOccConsts
					If Not oOccConst.Suppressed Then
						Try
							oOccConst.Suppressed = True
						Catch
							Logger.Error("Error Suppressing AssemblyConstraint named '" & oOccConst.Name & "' on" & _
							vbCrLf & "component named '" & oOcc.Name)
						End Try
					End If
				Next oOccConst
			End If
		End If
	Next oOcc
	oADoc.Update2(True)
End Sub

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 4 of 12

vdcrocks7
Contributor
Contributor

@WCrihfield , Perfect Thank you for help  😊, I would like to know more about if in my Top assembly having sub assembly and that Sub assembly also having another sub assembly, so can we write code, so it suppresses constrain to all level, like From Top to Bottom? Thank you in advance!

0 Likes
Message 5 of 12

WCrihfield
Mentor
Mentor

Hi @vdcrocks7.  Yes, I believe it may be possible to make a code like this effect all levels of the assembly.  The code would need to get a lot more complex though, because we would have to incorporate a separate, 'recursive' Sub routine into the overall code, which can run itself as a way of stepping down another level deeper every time it finds sub components under a component.  Also, even though I know you want it to be able to effect all components at all levels, one small detail is still not clear.  We can create constraints between top level components and lower level components, and since those constraints were created / defined within the 'context' of the main assembly, they exist within the main assembly, not within lower level sub assemblies.  So, do you want this code to only effect the constraints that are defined within the main (highest level) assembly, even if they may effect lower level components, or do you want this code to also effect the constraints that were defined down within all levels of sub assemblies themselves?  If it will only be working with the constraints that were defined within the main assembly, then the code can simply iterate through that one collection of constraints, and check all components that each one effects, to see if one of the components is suppressed, and if one is suppressed, suppress that constraint.  However, if this code needs to look into all constraints within all levels of sub assemblies, then that will be more complex and will require more code.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 6 of 12

vdcrocks7
Contributor
Contributor

@WCrihfield , Thanks again for update , My main aim is like , I've Main assembly and then in Main assembly having multiple sub assembly which having constrain with Main assembly or other sub assembly but it's same level at Main assembly , so for that level If I wish to suppress constrain based on Suppressed assembly/parts then your code works perfect, But now if I've sub assembly and in that sub assembly also having some parts or Sub assembly at that Level, if I wish to suppressed  constrain based on Suppressed part then , I've to place your same code in that sub assembly level, and then I've to run Separately. So that needs to add each sub assembly, to avoid adding that code in each and every assembly, I'm looking for such kind of rule that will help me to run single code at Top level. Also, I know that too complex as well, because in past I've also use Recursive Loop for adding Custome iproperty for Each part from Main assembly. Hope now you got my main concern 😊

0 Likes
Message 7 of 12

WCrihfield
Mentor
Mentor
Accepted solution

Hi @vdcrocks7.  This may be partially possible, however, when the assembly component representing a sub assembly is suppressed, we will not be able to access any of the sub components within that sub assembly by code.  We may be able to check that one assembly component for constraints directly associated with it, within its parent assembly, but we will not be able to dig any deeper into the sub assembly that it references.  When an assembly component is suppressed, we can not do much with it by code without it throwing errors.  But, if accessing the constraints within referenced sub assemblies that are suppressed is not an issue, we should be OK, because the code will be able to access any other sub assemblies that are not suppressed.

See the attached text file, which contains the code for an iLogic rule you can try out for this recursive process.  It is broken up into 3 parts, but all will be within the same iLogic rule.  One part is the 'Main' routine, which gets the main assembly and its components, then calls the recursive routine to run on them.  Then one routine is just to support the recursive functionality of stepping down into all levels of the assembly components.  Then the third routine is focused on the main task that we want to run on each assembly component...namely suppressing all assembly constraints associated with it, if it is suppressed.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 8 of 12

vdcrocks7
Contributor
Contributor

@WCrihfield , Perfect , thank you once again 🙂 it's work for me!

0 Likes
Message 9 of 12

thomas_h_T36UT
Contributor
Contributor

Is there a possibility to unsupress the constrains after the part or assembly is unsupressed?

Thanks in Advance

Message 10 of 12

cmcewanE2U82
Enthusiast
Enthusiast

I would also like a code for this. Would be nice to be able to turn them back on when bring parts back.

0 Likes
Message 11 of 12

WCrihfield
Mentor
Mentor

Hi @cmcewanE2U82.  Attached is a text file containing an updated version of my previous code.  In this version, the suppression status of each occurrence is first captured to a Boolean type variable, then that variable is used to dictate the suppression status of each of its constraints.  I have not tested this new version yet myself, because I simply have too many other things going on right now, so let me know if it works OK for you.

 

I'm not saying that I would recommend this but...

When your 'active' document is an assembly, you can go to the Manage tab, iLogic panel, and click on the Event Triggers button to open that dialog.  Then, on the 'This Document' tab, you will see a list of event names on the right, one of which is "Component Suppression Change".  You could drag this iLogic rule from the list on the left over and put it under that event name, to cause that rule to run automatically whenever that event happens.  However, if you do a lot of component suppression changes, then setting things up this way may significantly slow Inventor down, due to all the processing going on.  It would likely be better (more efficient) to just run the rule manually after you have completed all necessary component suppression changes.  And if you need to regularly switch component suppression status on and off, I would recommend creating some ModelStates to record those suppression states, so that you can simply switch between the ModelStates to achieve the same effect.  Just some things to think about.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 12 of 12

cmcewanE2U82
Enthusiast
Enthusiast

Makes sense to me. I will try it and see which way works better for the purpose. A lot of the assembling is trial and error due to the type of assemblies being made. There are instances where I want to suppress a bunch of parts and re-constrain the larger main parts to a new location but need to deal with many constraints preventing this from happening. The first code works as intended. I will try the new code and see if event triggers may work for this type of work. Thankyou for your reply.

0 Likes