Mechanical Modeler |
Part Design |
Creating and Modifying a Mechanical Design FeatureUsing the Mechanical Design factory and the Part Design interfaces |
Use Case |
AbstractThis article discusses the CAAPriCreateModify use case. This use case explains how to create and modify a Mechanical Design feature. |
This use case is intended to help you make your first steps in programming the CATIA Part Design [1]. Its main intent is to create mechanical design feature.
[Top]
CAAPriCreateModify is a use case of the CAAPartInterfaces.edu framework that illustrates PartInterfaces framework capabilities.
[Top]
The goal of CAAPriCreateModify use case is to show how to use Mechanical Design factory to instantiate Mechanical Design feature and how to modify Mechanical design feature by using the interfaces of Part Design. We illustrate this by creating and modifying a pad feature. The created part and the modified part are saved in two different documents. More precisely CAAPriCreateModify:
[Top]
To launch CAAPriCreateModify, you will need to set up the build time environment, then compile CAAPriCreateModify along with its prerequisites, set up the run time environment, and then execute the use case [2].
Launch the use case as follows:
e:>CAAPriCreateModify outputDirectory\PartCM1.CATPart outputDirectory\PartCM2.CATPart |
$ CAAPriCreateModify outputDirectory/PartCM1.CATPart outputDirectory/PartCM2.CATPart |
where:
outputDirectory |
The directory into which PartCM1.CATPart and PartCM2.CATPart
will be stored |
PartCM1.CATPart
| The file that contains the pad created |
PartCM2.CATPart |
The file that contains the pad after it is modified |
[Top]
The CAAPriCreateModify use case is made of a single class named CAAPriCreateModify located in the CAAPriCreateModify.m module of the CAAPartInterfaces.edu framework:
Windows | InstallRootDirectory\CAAPartInterfaces.edu\CAAPriCreateModify.m\ |
Unix | InstallRootDirectory/CAAPartInterfaces.edu/CAAPriCreateModify.m/ |
where InstallRootDirectory
is the directory where the CAA CD-ROM
is installed.
[Top]
There are seven main steps in CAACreateModify:
We will now comment each of those sections by looking the code.
[Top]
CAAPriCreateModify begins by checking that the command lines contains three
arguments. It then creates a session, and creates a new CATPart document,
reffered to using a pointer to the CATDocument class named pDoc
,
and a smart pointer to the CATInit interface named spiInitOnDoc
.
This is the usual sequence for creating a CATIA document [3].
[Top]
... // Retrieves the sketch factory to instantiate objects CATISketchFactory_var spSketchFactOnPrtCont(piPrtCont); // Creates the sketch plane // retrieves the reference planes of the part CATIPrtPart_var spPart = piPrtCont->GetPart(); CATListValCATISpecObject_var spListRefPlanes = spPart->GetReferencePlanes(); ... |
Using the smart pointer to CATInit, the document's root container is
retrieved thanks to the GetRootContainer
method as a CATIPrtContainer
interface pointer. The root container implements the factory interfaces needed
to create sketch objects and allows the reference planes of the document to be
accessed.
CATISketchFactory | The sketch object factory interface |
[Top]
... // defines the xy plane as the first sketch plane CATISpecObject_var spSketchPlane = spListRefPlanes[1]; // Instantiates the sketch with the plane CATISketch_var spSketch = spSketchFactOnPrtCont->CreateSketch(spSketchPlane); // Retrieves the 2D factory to create the lines and points of the sketch CATI2DWFFactory_var spWF2DFactOnSketch(spSketch); // Creates the elements of the sketch double pt1[2] = { 10., 5.}, pt2[2] = {-10., 5.}, pt3[2] = {-10., -5.}, pt4[2] = { 10., -5.}; // Edits the sketch and draws the lines and the endpoints. spSketch->OpenEdition(); CATISpecObject_var spLine1 = spWF2DFactOnSketch->CreateLine(pt1,pt2); CATISpecObject_var spLine2 = spWF2DFactOnSketch->CreateLine(pt2,pt3); CATISpecObject_var spLine3 = spWF2DFactOnSketch->CreateLine(pt3,pt4); CATISpecObject_var spLine4 = spWF2DFactOnSketch->CreateLine(pt4,pt1); CATI2DCurve_var spCurveOnLine1(spLine1); spCurveOnLine1->GetStartPoint(); spCurveOnLine1->GetEndPoint(); CATI2DCurve_var spCurveOnLine2(spLine2); spCurveOnLine2->GetStartPoint(); spCurveOnLine2->GetEndPoint(); CATI2DCurve_var spCurveOnLine3(spLine3); spCurveOnLine3->GetStartPoint(); spCurveOnLine3->GetEndPoint(); CATI2DCurve_var spCurveOnLine4(spLine4); spCurveOnLine4->GetStartPoint(); spCurveOnLine4->GetEndPoint(); // Closes the sketch edition spSketch->CloseEdition(); ... |
As we will see later, one of the specifications of the pad is a sketch. It is
a 2D object made of curves and points positioned in a plane of the 3D space.
Consequently, to instantiate a sketch, we use the spSketchPlane
that represents the plane (0,x,y), created from a CATMathPlane and
retrieved as a CATISpecObject thanks to the CreatePlane
method of CATIGSMFactory. This plane is given the SketchPlane
identifier. Then the sketch is created using the CreateSketch
method of CATISketchFactory. The sketch implements the CATI2DWFFactory
interface that groups all methods to create 2D geometric objects, and the smart
pointer spWF2DFactOnSketch
to this interface is retrieved from the
sketch for this purpose. A rectangle defined with four points whose coordinates
are set using pt1
, pt2
, pt3
, and pt4
makes up the sketch. The CATISketch interface defines a set of methods to
edit the sketch. Any sketch editing sequence begins with OpenEdition
,
and closes with CloseEdition
. The CreateLine
method of
CATI2DWFFactory creates the line and the GetStartPoint
and GetEndPoint
methods on CATICurve2D interface allow to create the endpoints.
[Top]
... CATMathDirection dirZ(0., 0., 1.); // Extrusion direction of the pad double firstLimit = 20.; double secondLimit = 0.; // Retrieves the Mechanical Design factory to create the pad CATIPrtFactory_var spPrtFactOnPrtCont(piPrtCont); piPrtCont->Release(); CATISpecObject_var spSpecObj = spPrtFactOnPrtCont->CreatePad(spSketch); CATIPad_var spPadOnSpecObj(spSpecObj); spPadOnSpecObj->ModifyDirection(dirZ); spPadOnSpecObj->ModifyEndType(catOffsetLimit); spPadOnSpecObj->ModifyEndOffset(firstLimit); spPadOnSpecObj->ModifyStartType(catOffsetLimit); spPadOnSpecObj->ModifyStartOffset(secondLimit); spSpecObj->Update(); // Builds the pad ... |
The sketch on which the pad relies is now created. The remaining
specifications of the pad are the direction along which the sketch is to be
extruded, and its two limits. The CATIPrtFactory interface is also
implemented by the root container, which is now not any longer needed. The pad
is created using the CreatePad
method to which the sketch is passed
as the argument, and its specifications are set using the CATIPad
interface methods that the pad implements itself:
ModifyDirection
, that sets the pad extrusion direction to the
z axis. Note that the default, that is, omitting to call ModifyDirection
,
is to set this direction to the normal of the sketch planeModifyEndType
, that sets the pad end to be set using an
offset from the sketch plane using the catOffsetLimit
value of
the CatLimitMode
enumModifyEndOffset
, that sets this offset, also named the first
limit in the pad edition dialog boxModifyStartType
and ModifyStartOffset
, that do
the same for the pad second limit. Since firstLimit
equals to
0, the pad starts from the sketch plane.The Update
method takes these specifications into account to
build the pad.
[Top]
... // Checks the limits of the created pad if (spPadOnSpecObj->GetEndOffset() != firstLimit || spPadOnSpecObj->GetStartOffset() != secondLimit) return 3; // Saves the created pad in the first input path char * pNomPart1 = iArgv[1]; CATDocumentServices::SaveAs(*pDoc, pNomPart1); ... |
A simple check of the actual offsets of the pad using the methods GetEndOffset
and GetStartOffset
that retrieve the values of the first limit and
the second limit respectively. If one of these values is different from those
defined for the creation, CAAPriCreateModify stops with a code 3, otherwise the
pad is saved in the CATPart document in the directory set as the first argument
when launching CAAPriCreateModify. This is the usual sequence for saving a
document [3].
[Top]
The figure shows the pad in both the graphic viewer and the specification tree where it is displayed using its name Pad.1. It relies on the sketch named Sketch.1.
[Top]
... // Modifies the pad changing the extrusion direction // and applying the symetry CATMathDirection dir2(0., 1., 1.); // Direction of the pad // Modifies the first limit type spPadOnSpecObj->ModifySym(1); // Modifies the first limit spPadOnSpecObj->ModifyDirection(dir2); spSpecObj->Update(); // Builds the pad ... |
Let's now modify one of the pad's specifications: using the ModifySym
method, we set the symmetrical extension property and we modify the direction
using the method ModifyDirection
with dir2
as new
extrusion direction.
[Top]
... // Saves the modified pad in the second input path char * pNomPart2 = iArgv[2]; CATDocumentServices::SaveAs(*pDoc, pNomPart2); // Closes the session ::Delete_Session("SampleSession"); return rc; } |
The modified pad is saved in the CATPart document stored in the file whose path is the second argument passed when launching CAAPriCreateModify. The figure shows modified pad for which the height is now two times the initial height, and the extrusion direction is no more perpendicular to the sketch plane. The session is then deleted. This is the usual sequence for saving a document and closing the session [3].
[Top]
This use case has demonstrated the way to create and modify a Mechanical feature.
[Top]
[1] | Form Feature and Contextual Feature Concepts |
[2] | Building and Launching a CAA V5 Use Case |
[3] | Creating a New Document |
[Top] |
Version: 1 [Apr 2000] | Document created |
[Top] |
Copyright © 2000, Dassault Systèmes. All rights reserved.