iLogic - Apply shell feature to all parts in assembly

iLogic - Apply shell feature to all parts in assembly

nbarbars
Enthusiast Enthusiast
891 Views
5 Replies
Message 1 of 6

iLogic - Apply shell feature to all parts in assembly

nbarbars
Enthusiast
Enthusiast

I have over 100 solid parts in an assembly (simple rectangular extrusions) and i need to apply a shell with a wall thickness to all of them. I am a novice at ilogic, and i couldn't find anything that can help me create the rule. I know how to edit a parameter of all the parts via ilogic but not how to create a shell feature. I use a template code that goes through each part in an assembly to edit a parameter, i just need to know how to apply a shell feature to that code. Any ideas? 

0 Likes
Accepted solutions (1)
892 Views
5 Replies
Replies (5)
Message 2 of 6

WCrihfield
Mentor
Mentor

Try this.  Just edit the value of the variable oThickness to whatever value you want, just keep in mind that this value will be understood as centimeters by the system, so you may have to either do some math or use a conversion tool.

This process assumes the first surface body within each part document is the main (and only) body, and that the first face in the faces collection is the one you would want to choose as the one to remove in the shell process.  To be more specific about which face to remove, you would most likely have to name the right face within each part file, then find that named face within each part file within the code to use the right one.  If you need to do it that way I can help, just let me know.

Here's the code.

 

Dim oADoc As AssemblyDocument = ThisAssembly.Document
Dim oPDoc As PartDocument
Dim oPDef As PartComponentDefinition
Dim oFaces As FaceCollection = ThisApplication.TransientObjects.CreateFaceCollection
Dim oBody As SurfaceBody
Dim oFace As Inventor.Face
Dim oShellFeats As ShellFeatures
Dim oShellDef As ShellDefinition
Dim oShelllFeat As ShellFeature
Dim oThickness As Double = .125
For Each oRefDoc As Document In oADoc.AllReferencedDocuments
	If oRefDoc.DocumentType = DocumentTypeEnum.kPartDocumentObject Then
		oPDoc = oRefDoc
		oPDef = oPDoc.ComponentDefinition
		oBody = oPDef.SurfaceBodies.Item(1)
		oFace = oBody.Faces.Item(1)
		oFaces.Add(oFace)
		oShellFeats = oPDef.Features.ShellFeatures
		oShellDef = oShellFeats.CreateShellDefinition(oFaces,oThickness,ShellDirectionEnum.kInsideShellDirection)
		oShelllFeat = oShellFeats.Add(oShellDef)
	End If
Next

 

 

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

Vote For My IDEAS 💡and Explore My CONTRIBUTIONS

Inventor 2020 Help | Inventor Forum | Inventor Customization Forum | Inventor Ideas Forum

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 3 of 6

nbarbars
Enthusiast
Enthusiast

edit: it actually applied the shell to the first part, then threw the error

 

Hey, thank you for the reply. I'm getting this error when i tried to test this: 

Error in rule: Rule0, in document: Assembly3

Unspecified error (Exception from HRESULT: 0x80004005 (E_FAIL)

 

I don't need any faces removed either, i just need to make the parts hollow with a .25" wall thickness all around.

 

thank you in advance,

 

0 Likes
Message 4 of 6

WCrihfield
Mentor
Mentor
Accepted solution

OK. Give this a try then.

I removed the variables oBody and oFace and am no longer adding a face into the oFaces collection.   The first variable within the definition of a ShellDefinition is the FaceCollection object, so hopefully it will accept an empty collection.

I also threw in some code to ensure the part document is open before attempting to edit it, then closing it again after I'm done with it.  Hopefully one (or all) of these edits will eliminate the error message for you.  By the way when posting the results of an error message, it's always best to show what was on both tabs of the error message, because while one tab may be rather generic and practically meaningless, the information on the other tab may contain key information that helps us understand where the error occurred.

Here's the updated code:

Dim oADoc As AssemblyDocument = ThisAssembly.Document
Dim oPDoc As PartDocument
Dim oPDef As PartComponentDefinition
Dim oFaces As FaceCollection = ThisApplication.TransientObjects.CreateFaceCollection
Dim oShellFeats As ShellFeatures
Dim oShellDef As ShellDefinition
Dim oShelllFeat As ShellFeature
Dim oThickness As Double = .25
For Each oRefDoc As Document In oADoc.AllReferencedDocuments
	If oRefDoc.DocumentType = DocumentTypeEnum.kPartDocumentObject Then
		oPDoc = oRefDoc
		If Not oPDoc.Open Then ThisApplication.Documents.Open(oPDoc.FullDocumentName,False)
		oPDef = oPDoc.ComponentDefinition
		oShellFeats = oPDef.Features.ShellFeatures
		oShellDef = oShellFeats.CreateShellDefinition(oFaces,oThickness,ShellDirectionEnum.kInsideShellDirection)
		oShelllFeat = oShellFeats.Add(oShellDef)
		oPDoc.Save
		oPDoc.Close
		oPDoc.ReleaseReference
	End If
Next
ThisApplication.Documents.CloseAll(True)

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 5 of 6

nbarbars
Enthusiast
Enthusiast

Thank you, worked perfect! And i learned a bit from your code so thank you for that too!

0 Likes
Message 6 of 6

WCrihfield
Mentor
Mentor

Always glad to help when I can. 🙂

Good luck in all your future customization endeavors.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes