Ilogic cut through all solids

Ilogic cut through all solids

gcoombridge
Advisor Advisor
1,042 Views
3 Replies
Message 1 of 4

Ilogic cut through all solids

gcoombridge
Advisor
Advisor

Hi All,

 

I am looking to compile a code which cut through all solids (assuming you don't know how many there will be). I have made something that (kind of) works below. However if does throw this error when first loaded: (The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))).

 

A flaw in this seems to be that all the cut operations have to be after the new solid operations. This makes sense because otherwise you'd be telling the extrude to cut something which doesn't yet exist. My plan to get around this was to remove the first for/each and add an additional if statement before the kCutOperation one. This would return the solid if a new body extrusion was encountered and add it to a collection (this collection would then be list of solids for the subtractions to cut through). I can't seem to get this to work.  This is what I had:

 

Any thoughts/advice?

 

Dim oExtrusionSolid as Object

'Iterate through each extrudefeature in part, establish if its a cut and then set to the list of all bodies
For Each oExtrusion In partDoc.ComponentDefinition.Features.ExtrudeFeatures

If oExtrusion.Definition.Operation = kNewBodyOperation Then

oExtrusionSolid = oExtrusion.surfacebodies

ObjCol.Add(oExtrusionSolid)
Else If oExtrusion.Definition.Operation = kCutOperation Then
oExtrusion.SetAffectedBodies(ObjCol)
'MsgBox(oExtrusion.Name)
End If
i = i + 1
Next oExtrusion

 

 

Below is the semi-working code:

 

Dim partDoc As PartDocument
partDoc = ThisDoc.Document
Dim solid As SurfaceBody

Dim i As Integer
Dim oExtrusion As ExtrudeFeature
Dim TransObj As TransientObjects
TransObj = ThisApplication.TransientObjects
Dim ObjCol As ObjectCollection
ObjCol = TransObj.CreateObjectCollection

i = 1

 

''Create a collection of all solids in part
For Each solid In partDoc.ComponentDefinition.SurfaceBodies
ObjCol.Add(solid)
'MsgBox(solid.Name)
i = i + 1
Next solid

i = 1

 

'Iterate through each extrudefeature in part, establish if its a cut and then set to the list of all bodies
For Each oExtrusion In partDoc.ComponentDefinition.Features.ExtrudeFeatures
If oExtrusion.Definition.Operation = kCutOperation Then
oExtrusion.SetAffectedBodies(ObjCol)
'MsgBox(oExtrusion.Name)
End If
i = i + 1
Next oExtrusion

Thanks,

Glenn

 

 

Use iLogic Copy? Please consider voting for this long overdue idea (not mine):https://forums.autodesk.com/t5/inventor-ideas/string-replace-for-ilogic-design-copy/idi-p/3821399
0 Likes
1,043 Views
3 Replies
Replies (3)
Message 2 of 4

Sergio.D.Suárez
Mentor
Mentor

Hi, I'm not sure that I understood you correctly. However, here I share a possible example, if there are no solids it will not continue with the code and will not throw error the first time it is loaded.

Dim partDoc As PartDocument
partDoc = ThisDoc.Document
Dim solid As SurfaceBody

Dim i As Integer
Dim oExtrusion As ExtrudeFeature
Dim TransObj As TransientObjects
TransObj = ThisApplication.TransientObjects
Dim ObjCol As ObjectCollection
ObjCol = TransObj.CreateObjectCollection

i = 1


If partDoc.ComponentDefinition.SurfaceBodies.Count>0 Then

	''Create a collection of all solids in part
	For Each solid In partDoc.ComponentDefinition.SurfaceBodies
	ObjCol.Add(solid)
	'MsgBox(solid.Name)
	i = i + 1
	Next solid

	i = 1

	'Iterate through each extrudefeature in part, establish if its a cut and then set to the list of all bodies
	For Each oExtrusion In partDoc.ComponentDefinition.Features.ExtrudeFeatures
	If oExtrusion.Definition.Operation = kCutOperation Then
	oExtrusion.SetAffectedBodies(ObjCol)
	'MsgBox(oExtrusion.Name)
	End If
	i = i + 1
	Next oExtrusion

End If

 I hope this helps with your problem. Regards


Please accept as solution and give likes if applicable.

I am attaching my Upwork profile for specific queries.

Sergio Daniel Suarez
Mechanical Designer

| Upwork Profile | LinkedIn

0 Likes
Message 3 of 4

gcoombridge
Advisor
Advisor

Hi Sergio,

 

Thanks for your answer - the if statement doesn't solve it because the cut extrusions can be referencing bodies that do not exist yet in the tree. This I happening because my ObjCol object collection is just a list of ALL the bodies in the part, not the ones that have come before the particular cut extrusion in the tree. What I was looking to do was only use one for next statement that sorts extrusions into two categories:

  • Ones that make new bodies using  if oExtrusion.Definition.Operation = kNewBodyOperation then... put the solid  its creating into a the collection. I think that oExtrusion.SurfaceBodies should return what I want but I'm not sure how to get that into the collection... Perhaps because it can return multiple objects you can't just use ObjCol.Add(...)?
  • The second part of the conditional statement is as in the original code. If the extrusion is a cut feature then  I want to set the affected bodies to all members of the collection (that I've made in the first part). 

Using this approach I think that the list of solids will get built up as the code iterates through the tree, that was no cut extrusion can reference a solid body that hasn't been built yet. This means that the cuts can be anywhere in the browser tree without causing an error.

 

The reason I was to do this is for building tanks as multi-solid bodies. I want to be able to change strakes panel numbers and positions without affecting cuts in the shell. Currently this can only be done by selecting each solid using the shift key so you are guaranteed an error whenever you make a change. I put an idea up a while ago for the extrusion to have a 'through all solids' button but this seems very solvable with ilogic...

 

Sorry about my explanation - this is a tough one to get my head around. 

Use iLogic Copy? Please consider voting for this long overdue idea (not mine):https://forums.autodesk.com/t5/inventor-ideas/string-replace-for-ilogic-design-copy/idi-p/3821399
0 Likes
Message 4 of 4

gcoombridge
Advisor
Advisor

Attached is the part file with the code and some extrusions (new bodies then cuts)

This is the code I'm using - specifically the error is in the 'setaffectedbodies' I think - when this is commented out the rule runs without error...

 

Dim partDoc As PartDocument
partDoc = ThisApplication.ActiveDocument

Dim oExtrusion As ExtrudeFeature 
Dim NewBodyObjCol As ObjectCollection
NewBodyObjCol = ThisApplication.TransientObjects.CreateObjectCollection

'Iterate through each extrudefeature in part, establish if its a cut and then set to the list of all bodies
For Each oExtrusion In partDoc.ComponentDefinition.Features.ExtrudeFeatures
	If oExtrusion.Definition.Operation = kNewBodyOperation Then
		NewBodyObjCol.Add(oExtrusion.Definition.AffectedBodies)
	Else If oExtrusion.Definition.Operation = kCutOperation Then
		oExtrusion.SetAffectedBodies(NewBodyObjCol)
	End If
Next oExtrusion


 

Use iLogic Copy? Please consider voting for this long overdue idea (not mine):https://forums.autodesk.com/t5/inventor-ideas/string-replace-for-ilogic-design-copy/idi-p/3821399
0 Likes