The DesignModeler API Operations enables you to perform
different operations on a geometric body. Available operations can be divided into
two different categories: Primary and Boolean
Operations and Tools Operations.
The operations variable
ExtAPI.DataModel.GeometryBuilder.Operations is the
gateway for performing operations. The code must be integrated into the callback
<ongenerate>.
The script function ongenerate() can be used to perform
various types of operations on a geometry feature. The API provides primary and
Boolean operations that allow you to specify properties such as body type,
dimensions, shape, point coordinates, and material. It also offers a number of tools
for manipulating your geometry, including actions such as copying or deleting a body
or transform operations for creating a body based on another body or topological
components.
When using the operation Extrude, you must first create
the geometry to which the extrusion is to be applied. You can create any of the
sheet primitive shapes listed in Creating Primitives. Once the geometry has been created, you can define and apply the operation
Extrude to it.
In the following example, the function ongenerate() is
used to create a polygon sheet body and perform the operation
Extrude.
def Ongenerate(feature,function):
length = 0.3
bodies = []
builder = ExtAPI.DataModel.GeometryBuilder
polygon=builder.Primitives.Sheet.CreatePolygon([0.,0.,3*length,0.,0.,2.*length,length,0.,2.*length])
polygon_generated = polygon.Generate()
extrude = builder.Operations.CreateExtrudeOperation([0.,1.,0.],length/2.)
bodies.Add(extrude.ApplyTo(polygon_generated)[0])
feature.Bodies = bodies
feature.MaterialType = MaterialTypeEnum.Add
return TrueIn this example:
The first part of the function creates a polygon sheet body, using a process similar to the one used to create a cylinder in Creating a Sheet Body.
With the operation Extrude, you use the
operations generator
builder.Operations.CreateExtrudeOperation. The method
CreateExtrudeOperation specifies that the
operation is defined by the following arguments:
Vector coordinates (which defines the direction of the extrusion)
Length of the extrusion
Note: In this example, the variable
Length is used for both the sheet
body and the extrusion definition. However, you could have
used a different variable for each.
The method ApplyTo specifies the geometry to
which to apply the operation Extrude. The method
ApplyTo() returns a list of bodies to which
to apply the operation.
With the lines
bodies.Add(extrude.ApplyTo(polygon_generated)[0])
and feature.Bodies = bodies, you add the extruded
sheet body polygon to the list feature.bodies so
it is added to DesignModeler after generation. Bodies not added to this
list are not retained.
When using the Transform Edges to Wire operation tool,
you must first create a geometry that has some edges. You can create any of the
sheet body or solid body shapes listed in Creating Primitives. Once the primitive has been
created, you can obtain a wire body from its edges by defining and applying the
Transform Edges to Wire tool.
In the following example, the function ongenerate()
creates a polygon sheet body and applies the Transform Edges to
Wire tool.
def Ongenerate(feature,function):
length = 0.3
bodies = []
builder = ExtAPI.DataModel.GeometryBuilder
polygon = builder.Primitives.Sheet.CreatePolygon([0.,0.,2.*length,0.,0.,1.*length,length,0.,0.7])
polygon_generated = polygon.Generate()
body = builder.Operations.Tools.EdgesToWireBody(polygon_generated.Edges);
bodies.Add(body)
feature.Bodies = bodies
feature.MaterialType = MaterialTypeEnum.Add
return TrueIn this example:
The first part of the function creates a polygon sheet body, using a process similar to the one used to create a cylinder in Creating a Sheet Body.
With the body function, you use the operations generator
builder.Operations.Tools.EdgesToWireBody. The
method EdgesToWireBody specifies that the
operation tool is to transform the edges of the sheet body polygon into
a wire body.
Note: In this example, the variable Length is
used for both the sheet body and the extrusion definition. However,
you could have used a different variable for each.
The new wire body is added to the list
feature.bodies as described in Applying the Extrude Operation.