Mechanical Modeler

Part Design

Creating and Modifying a Mechanical Design Feature

Using the Mechanical Design factory and the Part Design interfaces
Use Case

Abstract

This article discusses the CAAPriCreateModify use case. This use case explains how to create and modify a Mechanical Design feature.


What You Will Learn With This Use Case

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]

The CAAPriCreateModify Use Case

CAAPriCreateModify is a use case of the CAAPartInterfaces.edu framework that illustrates PartInterfaces framework capabilities.

[Top]

What Does CAAPriCreateModify Do

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]

How to Launch CAAPriCreateModify

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:

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]

Where to Find the CAAPriCreateModify Code

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]

Step-by-Step

There are seven main steps in CAACreateModify:

  1. Prolog
  2. Retrieving the Sketch Factory and the List of Reference Planes
  3. Creating the Sketch
  4. Creating the Pad
  5. Checking and Saving the Created Pad
  6. Modifying the Created Pad
  7. Saving the Modified Pad and Exiting

We will now comment each of those sections by looking the code.

[Top]

Prolog

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]

Retrieving the Sketch Factory and the List of Reference Planes

...
  // 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]

Creating the Sketch

...
 // 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]

Creating the Pad

...
  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:

The Update method takes these specifications into account to build the pad.

[Top]

Checking and Saving the Created Pad

...
  // 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]

Modifying the Created Pad

...
  // 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]

Saving the Modified Pad and Exiting

...
  // 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]


In Short

This use case has demonstrated the way to create and modify a Mechanical feature.

[Top]


References

[1] Form Feature and Contextual Feature Concepts
[2] Building and Launching a CAA V5 Use Case
[3] Creating a New Document
[Top]

History

Version: 1 [Apr 2000] Document created
[Top]

Copyright © 2000, Dassault Systèmes. All rights reserved.