Need ilogic rule to ignore suppressed parts in assembly and return results only for the unsuppressed parts.

Need ilogic rule to ignore suppressed parts in assembly and return results only for the unsuppressed parts.

Donna_Fleming
Participant Participant
2,515 Views
11 Replies
Message 1 of 12

Need ilogic rule to ignore suppressed parts in assembly and return results only for the unsuppressed parts.

Donna_Fleming
Participant
Participant

Combining code written by Curtis W and JhoelForshav I have a rule that will go through each part in an assembly, create a flat pattern if it's missing, measure the loop length, and create a custom iproperty for the loop length in each part file. Then the code totals those loop lengths in the part files and creates a custom iproperty for the total loop length in the assembly.

I have now learned that sometimes they want the total loop length for only a subset of parts.  Sometimes they need it for more than one subset, so the number of subsets may vary.

Is there a way to accomplish this?

 

I don't want to eliminate other ideas you may have, but if they create a different LOD for each subset, could a rule be written that would look at each LOD and return a total loop length for only the parts in that LOD?

 

I have attached the code I am using.

Any help you can provide is much appreciated.

 

 

0 Likes
Accepted solutions (4)
2,516 Views
11 Replies
Replies (11)
Message 2 of 12

A.Acheson
Mentor
Mentor

I haven’t had a chance to look at the files so just a few thoughts and questions you might consider to solve your situation.


How you filter could depend on if this is a one time selection or these will be constant through out an assembly and you need to saved the collection of files for repeated processing.


One time selection:

Would an occurrence selection using the pick tool add to collection then run rule based on the manual selection work for you?

Multiple processing:

Add manual selection to multi value parameter to access the collection for future processing. 


View rep:
Create filter based on view reps this way you can hide parts not needed for the loop length and you don’t need to enter the world of LOD. 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
Message 3 of 12

Donna_Fleming
Participant
Participant
Thank you for your suggestions.
If we could get a value for each view rep, that would be awesome.
0 Likes
Message 4 of 12

J-Camper
Advisor
Advisor
Accepted solution

In order to limit the count add this line right after entering the Occurrence loop:

 

'Iterate through all of the occurrences
For Each oOccurrence In oAsmCompDef.Occurrences
	If oOccurrence.Suppressed Then Continue For 'new line to add

 

It will skip over any occurrence that is suppressed.

 

If you automate cycling through your levels of detail, your custom iProperty for total will only show the last level of detail run through.  you would need to create a list or separate iProperties for each level of detail before automating that part would be worth while

 

Let me know if you have any questions, or if this is not working as intended

 

Message 5 of 12

J-Camper
Advisor
Advisor
Accepted solution

If you want to use view reps with visibility, instead of LOD with suppression, you can check the "Visible" Property on the ComponentOccurrenceObject instead of the "Suppressed" Property:

'Iterate through all of the occurrences
For Each oOccurrence In oAsmCompDef.Occurrences
	If Not oOccurrence.Visible Then Continue For 'Alternate new line for visibility check

 

Message 6 of 12

Curtis_Waguespack
Consultant
Consultant

Hi @Donna_Fleming 

 

I dropped some of your iproperty stuff, just to get this example working, but you can add that back in as needed.

 

anyway, here is an example of how to filter and select for only sheet metal parts and get the total loop value.

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

 

 

 

 


Sub Main
Dim oADoc As AssemblyDocument = ThisApplication.ActiveDocument
Dim oSMDoc As PartDocument
Dim oTotalLoopLen As Double
'

Dim oCollection As ObjectCollection
oCollection = ThisApplication.TransientObjects.CreateObjectCollection

oSet = oADoc.CreateHighlightSet

While True
	oMsg = "Select SM parts (press ESC to continue) Total Loop Length " & _
	Round(oTotalLoopLen,3)
	Dim oOcc As ComponentOccurrence 
	oOcc = ThisApplication.CommandManager.Pick(
	  SelectionFilterEnum.kAssemblyLeafOccurrenceFilter, oMsg) 
	
	' If nothing gets selected then we're done	
	If IsNothing(oOcc) Then Exit While
	
	'filter for only sheet metal parts
	If oOcc.Definition.Document.SubType = _
		"{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then
		oSet.AddItem(oOcc)		
		oTotalLoopLen = MeasureLoop(oOcc,oTotalLoopLen)			

	End If
End While

MessageBox.Show("Total: " & Round(oTotalLoopLen,3), "ilogic")
oSet.Clear


End Sub


Function MeasureLoop(oOcc As ComponentOccurrence, oTotalLoopLen As Double)

	Dim oSMDef As SheetMetalComponentDefinition
	Dim oTopFace As Face
	Dim oMeasureTools As MeasureTools = ThisApplication.MeasureTools
	Dim oLoopLength As Double
	Dim oEdgeLoop As EdgeLoop
			
	oSMDoc = oOcc.Definition.Document
	oSMDef = oSMDoc.ComponentDefinition
	If oSMDef.HasFlatPattern = False Then
		Try
			ThisApplication.ScreenUpdating = False
			oSMDef.Unfold
			cDef = ThisApplication.CommandManager. _
			ControlDefinitions.Item_("PartSwitchRepresentationCmd")
			cDef.Execute
			ThisApplication.ScreenUpdating = True
		Catch
			ThisApplication.ScreenUpdating = True
		End Try
		ThisDoc.Document.Activate
		oSMDoc.Close
	End If
	oTopFace = oSMDef.FlatPattern.TopFace
	oLoopLength = 0
	For Each oEdgeLoop In oTopFace.EdgeLoops
		oLoopLength = oLoopLength + oMeasureTools.GetLoopLength(oEdgeLoop)
	Next
	
	oTotalLoopLen = oTotalLoopLen + oLoopLength/2.54
	Return oTotalLoopLen 
End Function

 

 

 

 

 

EESignature

Message 7 of 12

Donna_Fleming
Participant
Participant

Thank you @J-Camper .   Your code snippet got me there though I had some trouble with it because I am pretty green.  We actually want to run the rule for what is visible on the screen.  This is what I ended up with:

For Each oOccurrence In oAsmCompDef.Occurrences
'Iterate through all of the occurrences
If oOccurrence.Visible Then
'Alternate new line for visibility check 
'custom property in the assembly 
xNumber = iProperties.Value("Custom", "TOTAL_LOOP_LENGTH") 
'custom property in the parts
yNumber = iProperties.Value(oOccurrence.Name, "Custom", "LOOP_LENGTH")
sumNumber = xNumber + yNumber
'set custom property values
iProperties.Value("Custom", "TOTAL_LOOP_LENGTH") = sumNumber 
End If
Next

 

0 Likes
Message 8 of 12

Donna_Fleming
Participant
Participant

Thanks for this @Curtis_Waguespack .  I didn't do anything with this, but my existing code was a mash-up of some of yours and some from @JhoelForshav 

I ended up just adding the code from @J-Camper and I seem to finally have my result.

 

These forums are awesome. and the help is much appreciated.  Thank you everybody.

0 Likes
Message 9 of 12

Donna_Fleming
Participant
Participant

We have used the code @Curtis_Waguespack provided in message 6 of 8 after all, because it does not blow up when sheet metal parts are created from multibody parts.

We are finding that clicking on parts to create a set is causing some issues.  If we accidentally click twice on a part, it is added twice.  We have no way of telling we've done that.

Instead of clicking parts to create a set, could you alter the code so the selection set is made up of the parts whose visibility is on?  

I have tried utilizing the code @J-Camper provided, but I don't know how to get it working with your code.

0 Likes
Message 10 of 12

Curtis_Waguespack
Consultant
Consultant
Accepted solution

Hi @Donna_Fleming 

 

This version adds the selected components to a list and checks that against new selections to prevent doubling up.

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

 

Sub Main
Dim oADoc As AssemblyDocument = ThisApplication.ActiveDocument
Dim oSMDoc As PartDocument
Dim oTotalLoopLen As Double

Dim oList As New ArrayList


oSet = oADoc.CreateHighlightSet

While True
	oMsg = "Select SM parts (press ESC to continue) Total Loop Length " & _
	Round(oTotalLoopLen,3)
	Dim oOcc As ComponentOccurrence 
	oOcc = ThisApplication.CommandManager.Pick(
	  SelectionFilterEnum.kAssemblyLeafOccurrenceFilter, oMsg) 
	
	' If nothing gets selected then we're done	
	If IsNothing(oOcc) Then Exit While
	
	'filter for only sheet metal parts
	If oOcc.Definition.Document.SubType = _
		"{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then
		If oList.Contains(oOcc.Name) = False Then
		oList.Add(oOcc.Name)
		oSet.AddItem(oOcc)		
		oTotalLoopLen = MeasureLoop(oOcc, oTotalLoopLen)		
	End if

	End If
End While

MessageBox.Show("Total: " & Round(oTotalLoopLen,3), "ilogic")
oSet.Clear


End Sub


Function MeasureLoop(oOcc As ComponentOccurrence, oTotalLoopLen As Double)

	Dim oSMDef As SheetMetalComponentDefinition
	Dim oTopFace As Face
	Dim oMeasureTools As MeasureTools = ThisApplication.MeasureTools
	Dim oLoopLength As Double
	Dim oEdgeLoop As EdgeLoop
			
	oSMDoc = oOcc.Definition.Document
	oSMDef = oSMDoc.ComponentDefinition
	If oSMDef.HasFlatPattern = False Then
		Try
			ThisApplication.ScreenUpdating = False
			oSMDef.Unfold
			cDef = ThisApplication.CommandManager. _
			ControlDefinitions.Item_("PartSwitchRepresentationCmd")
			cDef.Execute
			ThisApplication.ScreenUpdating = True
		Catch
			ThisApplication.ScreenUpdating = True
		End Try
		ThisDoc.Document.Activate
		oSMDoc.Close
	End If
	oTopFace = oSMDef.FlatPattern.TopFace
	oLoopLength = 0
	For Each oEdgeLoop In oTopFace.EdgeLoops
		oLoopLength = oLoopLength + oMeasureTools.GetLoopLength(oEdgeLoop)
	Next
	
	oTotalLoopLen = oTotalLoopLen + oLoopLength/2.54
	Return oTotalLoopLen 
End Function

 

 

EESignature

0 Likes
Message 11 of 12

Curtis_Waguespack
Consultant
Consultant
Accepted solution

Hi @Donna_Fleming 

 

Here is a version that only looks at visible sheet metal parts.

 

 

 

Sub main 
	Dim oADoc As AssemblyDocument = ThisApplication.ActiveDocument
	Dim oAsmCompDef As AssemblyComponentDefinition
	oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition

	For Each oOcc In oAsmCompDef.Occurrences
		'Iterate through all of the occurrences
		'filter for Visible and sheet metal subtype only
		If oOcc.Visible = True And oOcc.Definition.Document.SubType = _
			"{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then
			Logger.Info(oOcc.name)

			'step into function
			oTotalLoopLen = MeasureLoop(oOcc, oTotalLoopLen)	
			
			oTotalLoopLen = oTotalLoopLen + oLoopLength/2.54
			
		End If
	Next

	MessageBox.Show("Total: " & Round(oTotalLoopLen,3), "ilogic")

End sub

Function MeasureLoop(oOcc As ComponentOccurrence, oTotalLoopLen As Double)

	Dim oSMDef As SheetMetalComponentDefinition
	Dim oTopFace As Face
	Dim oMeasureTools As MeasureTools = ThisApplication.MeasureTools
	Dim oLoopLength As Double
	Dim oEdgeLoop As EdgeLoop
			
	oSMDoc = oOcc.Definition.Document
	oSMDef = oSMDoc.ComponentDefinition
	If oSMDef.HasFlatPattern = False Then
		Try
			ThisApplication.ScreenUpdating = False
			oSMDef.Unfold
			cDef = ThisApplication.CommandManager. _
			ControlDefinitions.Item_("PartSwitchRepresentationCmd")
			cDef.Execute
			ThisApplication.ScreenUpdating = True
		Catch
			ThisApplication.ScreenUpdating = True
		End Try
		ThisDoc.Document.Activate
		oSMDoc.Close
	End If
	oTopFace = oSMDef.FlatPattern.TopFace
	oLoopLength = 0
	For Each oEdgeLoop In oTopFace.EdgeLoops
		oLoopLength = oLoopLength + oMeasureTools.GetLoopLength(oEdgeLoop)
	Next
	
	oTotalLoopLen = oTotalLoopLen + oLoopLength/2.54
	Return oTotalLoopLen 
End Function

 

 

 

EESignature

0 Likes
Message 12 of 12

Donna_Fleming
Participant
Participant

Thank you so much @Curtis_Waguespack .  The code you provided in messages 10 and 11 works great.  We are very grateful that folks like you take the time to share your knowledge and expertise. It is truly appreciated.