Ilogic cut through all solids
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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