iLogic Extrude in Assembly

iLogic Extrude in Assembly

Anonymous
Not applicable
610 Views
3 Replies
Message 1 of 4

iLogic Extrude in Assembly

Anonymous
Not applicable

Hi All, 

 

I'm having some issues with an iLogic model regarding an Extrude function used within an Assembly; 

The extrude runs fine on execution - however when expanding the amount of components in the assembly the newly added components are not participating in the extrude command. 

To overcome this I copy-pasted some code together (using he forum as a source) to add the instances to my Extrude Command using 2 FOR loops. 

However - this code executes slow on 'larger' assemblies (+50 parts). 

Is there is faster way to add all components in the assembly to the extrude function? 

 

See code below; 

 

Dim oAsmCompDef As AssemblyComponentDefinition
oAsmDoc= ThisApplication.ActiveDocument

Dim oDef As AssemblyComponentDefinition
oDef = oAsmDoc.ComponentDefinition

Dim oAssemblyFeatures As Features
oAssemblyFeatures = oDef.Features

'Iterate through all of the occurrences
Dim oOccurrence As ComponentOccurrence

For Each oOccurrence In oDef.Occurrences
    'If oOccurrence.Name = "FeatureName" Then
    oOcc = oOccurrence 
    'Else
    'End If
	
		Dim oAssemblyFeature As PartFeature
		'Iterate through all of the assembly features
		For Each oAssemblyFeature In oAssemblyFeatures
   		 	If oAssemblyFeature.Name  = "ExtrusionHeight" Then
    		'add the occurrence to the feature
   			 oAssemblyFeature.AddParticipant(oOcc)
   			 Else
   			 End If
		Next
	
	
Next

'Update
	InventorVb.DocumentUpdate()

 

Thanks in advance for the help & insights.

0 Likes
611 Views
3 Replies
Replies (3)
Message 2 of 4

WCrihfield
Mentor
Mentor

Unfortunately, the AddParticipant() method is the only method for adding participants to an assembly extrusion feature, and it only accepts one component at a time.  The 'Participants' property (assemblies only) is Read Only, the 'SetAffectedBodies' method is for parts only, and the 'SurfaceBodies' property is also for parts only (and is also Read Only).

This is a fairly common situation that many of us wish there was a better way to handle.

Here is another condensed version of that same rule, in which I have changed the name of the feature to match yours.

It also includes a document type check at the beginning, and is set up to let you know if it doesn't find a feature with that name.

If ThisApplication.ActiveDocumentType <> DocumentTypeEnum.kAssemblyDocumentObject Then
	MsgBox("An Assembly Document must be active for this rule to work. Exiting.",vbOKOnly+vbCritical, "WRONG DOCUMENT TYPE")
	Exit Sub
End If
Dim oADoc As AssemblyDocument =  ThisApplication.ActiveDocument
Dim oADef As AssemblyComponentDefinition = oADoc.ComponentDefinition
Dim oOcc As ComponentOccurrence
Dim oXFeat As ExtrudeFeature
Dim oExists As Boolean
For Each oXFeat In oADef.Features.ExtrudeFeatures
	If oXFeat.Name = "ExtrusionHeight" Then
		oExists = True
		For Each oOcc In oADef.Occurrences
			oXFeat.AddParticipant(oOcc)
		Next
	End If
Next
If oExists = False Then
	MsgBox("No Feature by that name was found.", , "")
End If
oADoc.Update

One other thing you can try that may or may not increase processing speed is to avoid looping through all features, and just attempt to specify that feature directly by its name.  Here's one example of doing it that way.

If ThisApplication.ActiveDocumentType <> DocumentTypeEnum.kAssemblyDocumentObject Then
	MsgBox("An Assembly Document must be active for this rule to work. Exiting.",vbOKOnly+vbCritical, "WRONG DOCUMENT TYPE")
	Exit Sub
End If
Dim oADoc As AssemblyDocument =  ThisApplication.ActiveDocument
Dim oADef As AssemblyComponentDefinition = oADoc.ComponentDefinition
Dim oOcc As ComponentOccurrence
Dim oXFeat As ExtrudeFeature
Try
	oXFeat = oADef.Features.ExtrudeFeatures.Item("ExtrusionHeight")
Catch
	MsgBox("No Feature by that name was found. Exiting.", , "")
	Exit Sub
End Try
For Each oOcc In oADef.Occurrences
	oXFeat.AddParticipant(oOcc)
Next
oADoc.Update

If this solved your problem, or answered your question, please click ACCEPT SOLUTION.
Or, if this helped you, please click (LIKE or KUDOS) 👍.

If you have time, please... Vote For My IDEAS 💡or you can Explore My CONTRIBUTIONS

Inventor 2021 Help | Inventor Forum | Inventor Customization Forum | Inventor Ideas Forum

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 4

Anonymous
Not applicable

Hi, 
Thanks for taking a look at this issues.
However, in my assembly all 3 options seems to have the same runtime. 

 

Could I make a filter based on an iPoperty to filter between parts to limit the runtime of the script? 
if so, could you provide me with an insight on how to tackle this. 

 

Thanks & best regards,

0 Likes
Message 4 of 4

WCrihfield
Mentor
Mentor

Which iProperty?  If it is a custom iProperty, then what would it be called, what would its value be, and how is it created/maintained?  Including code to check something in each component's iProperties might add to the run time, instead of reduce it, but I'm not 100% sure.  It all depends on how long each 'check' takes.

If it is attempting to update the document each time a participant is added, instead of waiting for our Update line, then, running a check before adding each one, just might help reduce run time.

 

Another check we may be able to do is simply check if each component is already included in the Participants before attempting to add it again (not sure if it currently causes any issues or slowness if it has already been added).

 

We might also be able to get the extrude feature's RangeBox, then somehow check if each component is within that space.  If it isn't within that space then don't add it, because it won't be effected anyways.  I've never tried this theory before though, so I'm not even sure it's possible to set up.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes