New Shell Command

New Shell Command

kresh.bell
Collaborator Collaborator
954 Views
4 Replies
Message 1 of 5

New Shell Command

kresh.bell
Collaborator
Collaborator

Hi,

is it possible to use iLogic to create a shell but in the following way, so that ilogic-shell generates 2 solid bodies, one standard as usual and the other solid to be the difference between the start solid body and the newly created solid body?

start solid body:

01.jpg

 

create shell

02.jpg

 

run new iLogic and then create two solid body:

03.jpg

 

first, as usual with the shell command

04.jpg

 

and the second, as the difference between the start solid body and the first solid body

05.jpg

 

It is not a problem to add a new solid body when it is simple as in the example, but with more complex bodies there is more work

0 Likes
955 Views
4 Replies
Replies (4)
Message 2 of 5

JhoelForshav
Mentor
Mentor

Hi @kresh.bell 

I've only tried this on a part as simple as in your example. But at least it works for that.

See if it works for you 🙂

 

Dim oDoc As PartDocument = ThisDoc.Document
'Get Face and Thickness
Dim oFace As Face = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartFaceFilter, "Pick Face")
Dim oThickness As String = InputBox("Thickness: ", "Shell thickness", "1 mm")
Dim oFaceCol As FaceCollection = ThisApplication.TransientObjects.CreateFaceCollection
oFaceCol.Add(oFace)

'Copy solid
Dim oBody As SurfaceBody = oFace.SurfaceBody
Dim oNewBody As SurfaceBody = ThisApplication.TransientBRep.Copy(oBody)
Dim oNewBodDefinition As NonParametricBaseFeatureDefinition = oDoc.ComponentDefinition.Features.NonParametricBaseFeatures.CreateDefinition
Dim oCol As ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection
oCol.Add(oNewBody)
oNewBodDefinition.BRepEntities = oCol
oNewBodDefinition.OutputType = BaseFeatureOutputTypeEnum.kSolidOutputType
oNewBodDefinition.IsAssociative = False
Dim oNewBodFeature As NonParametricBaseFeature = oDoc.ComponentDefinition.Features.NonParametricBaseFeatures.AddByDefinition(oNewBodDefinition)

'Create shell
Dim oFeatures As PartFeatures = oDoc.ComponentDefinition.Features
Dim oShellDef As ShellDefinition = oFeatures.ShellFeatures.CreateShellDefinition(oFaceCol, oThickness, ShellDirectionEnum.kInsideShellDirection)
Dim oShell As ShellFeature = oFeatures.ShellFeatures.Add(oShellDef)

'Combine solids (cut operation)
oCol.Clear
oCol.Add(oBody)
oDoc.ComponentDefinition.Features.CombineFeatures.Add(oNewBodFeature.SurfaceBodies(1), oCol, PartFeatureOperationEnum.kCutOperation, True)
oBody.Visible = True
Message 3 of 5

kresh.bell
Collaborator
Collaborator

Hi,

ok, it works but only one face can be selected and I can't run the rule on the body it created after the first time, shows an error

01.jpg02.jpg

0 Likes
Message 4 of 5

JhoelForshav
Mentor
Mentor

@kresh.bell 

Ok, so this was really driving me crazy. The thing is that when you create a shell with ilogic/API it'll always try to create it in on the first solid in the part. That's why it doesn't work the second time (The thickness of the first solid is too small). Only after you've created the shell can you change the affected bodies of the feature... One would think that you should be able to set the affected bodies when you create the ShellDefinition but there's no property in that object for affected bodies....

 

So I made a workaround. I first set the thickness to something really small. That way we make sure it's possible to create a shell in the first body. Then I create the shell and set the affected bodies. After that I change the thickness to the input value.

 

Also, I added a loop so you can select multiple faces.

 

Dim oDoc As PartDocument = ThisDoc.Document
Dim oCompDef As PartComponentDefinition = oDoc.ComponentDefinition
'Get Face and Thickness
Dim oFaceCol As FaceCollection = ThisApplication.TransientObjects.CreateFaceCollection
While True
Dim oFace As Face = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartFaceFilter, "Pick Face(s), end selection with esc..")
If oFace Is Nothing Then Exit While
oFaceCol.Add(oFace)
End While

Dim oThickness As String = InputBox("Thickness: ", "Shell thickness", "1 mm")



'Copy solid
Dim oBody As SurfaceBody = oFaceCol(1).SurfaceBody
Dim oNewBody As SurfaceBody = ThisApplication.TransientBRep.Copy(oBody)
Dim oNewBodDefinition As NonParametricBaseFeatureDefinition = oCompDef.Features.NonParametricBaseFeatures.CreateDefinition
Dim oCol As ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection
oCol.Add(oNewBody)
oNewBodDefinition.BRepEntities = oCol
oNewBodDefinition.OutputType = BaseFeatureOutputTypeEnum.kSolidOutputType
oNewBodDefinition.IsAssociative = False
Dim oNewBodFeature As NonParametricBaseFeature = oCompDef.Features.NonParametricBaseFeatures.AddByDefinition(oNewBodDefinition)

ThisApplication.UserInterfaceManager.DoEvents

'Create shell
Dim oFeatures As PartFeatures = oCompDef.Features
'SET THE THICKNESS TO SOMETHING REALLY SMALL
Dim oShellDef As ShellDefinition = oFeatures.ShellFeatures.CreateShellDefinition(oFaceCol, 1/1000, ShellDirectionEnum.kInsideShellDirection)
oCol.Clear
oCol.Add(oBody)
Dim oShell = oFeatures.ShellFeatures.Add(oShellDef)
'SET AFFECTED BODIES
oShell.SetAffectedBodies(oCol)
'SET THICKNESS TO THE REAL VALUE
oShell.Definition.Thickness.Expression = oThickness


'Combine solids (cut operation)
oCompDef.Features.CombineFeatures.Add(oNewBodFeature.SurfaceBodies(1), oCol, PartFeatureOperationEnum.kCutOperation, True)
oBody.Visible = True

 

Message 5 of 5

J-Camper
Advisor
Advisor

Edit: @JhoelForshav  didn't see your reply before looking at it myself.

 

Original:

I added a loop at the beginning to gather more than 1 face, and also replaced the non-parametric body creation with an array/move combo to keep it parametric.

 

Here is the code:

 

Dim oDoc As PartDocument = ThisDoc.Document
Dim oFaceCount As Integer = InputBox("How many faces need to be removed: ", "Face Count", "1")
Dim oFaceCol As FaceCollection = ThisApplication.TransientObjects.CreateFaceCollection

While oFaceCol.Count < oFaceCount
	'Get Face and Thickness
	Dim oFace As Face = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartFaceFilter, "Pick Face")
	If IsNothing(oFace) Then 
		If oFaceCol.Count > 0
			Exit While
		Else 
			Exit Sub
		End If
	Else
		oFaceCol.Add(oFace)
	End If
End While

Dim oThickness As String = InputBox("Thickness: ", "Shell thickness", "1 mm")

'Copy solid
Dim oBody As SurfaceBody = oFaceCol.Item(1).SurfaceBody

'New Changed:
'Array Solid then move back instead of non-parametric
Dim BodyCol As ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection
BodyCol.Add(oBody)
Dim oAxis As WorkAxis = oDoc.ComponentDefinition.WorkAxes.Item(1)'X axis
Dim DeltaX As Double = 12
Dim oRecPat As RectangularPatternFeatureDefinition = oDoc.ComponentDefinition.Features.RectangularPatternFeatures.CreateDefinition(BodyCol, oAxis, True, "2 ul", DeltaX, PatternSpacingTypeEnum.kDefault)
oRecPat.Operation = PartFeatureOperationEnum.kNewBodyOperation
Dim RecPatFeat As RectangularPatternFeature = oDoc.ComponentDefinition.Features.RectangularPatternFeatures.AddByDefinition(oRecPat)
Dim oNewBody As SurfaceBody 
For Each b As SurfaceBody In oDoc.ComponentDefinition.SurfaceBodies
	If b.CreatedByFeature.Name = RecPatFeat.Name
		oNewBody = b
		Exit For
	End If
Next
BodyCol.Clear()
BodyCol.Add(oNewBody)
Dim oMoveBodyDef As MoveDefinition = oDoc.ComponentDefinition.Features.MoveFeatures.CreateMoveDefinition(BodyCol)
oMoveBodyDef.AddFreeDrag(-DeltaX, 0, 0)
Dim oMoveBody As MoveFeature = oDoc.ComponentDefinition.Features.MoveFeatures.Add(oMoveBodyDef)

'Copied from original:
'Create shell
Dim oFeatures As PartFeatures = oDoc.ComponentDefinition.Features
Dim oShellDef As ShellDefinition = oFeatures.ShellFeatures.CreateShellDefinition(oFaceCol, oThickness, ShellDirectionEnum.kInsideShellDirection)
Dim oShell As ShellFeature = oFeatures.ShellFeatures.Add(oShellDef)
'Combine solids (cut operation)
BodyCol.Clear
BodyCol.Add(oBody)
oDoc.ComponentDefinition.Features.CombineFeatures.Add(oNewBody, BodyCol, PartFeatureOperationEnum.kCutOperation, True)
oBody.Visible = True

 

 

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

0 Likes