Mechanical SDK: Introducing Mechanical Structure

Andrii Pobeda

October 06, 2023

Mechanical Structure Overview

In ODA Mechanical SDK you can mark and gather geometry into structured entities to make work with complex drawings easier.

Mechanical structure is a mechanism that allows you to mark geometry as components and create component views for marked geometry. Regardless of geometry mark type, marked geometry will be present in BOM (Bill Of Materials).

For another option to gather and mark geometry see part references documentation.

Mechanical structure includes concept of component and component views. Component is invisible entity that is created to provide structure functionality. Component view is an entity that holds geometry. Components as well as component views have hierarchy.

Also, mechanical structure has conception of definition and instances. At first, component definition and component view definition is created, then instances for definitions are created. This concept provides ability to reuse components and component views.

Basic Operations with Mechanical Structure

All operations with mechanical structure are made through the McadApi library of Mechanical.

Mechanical structure provide operations:

  • amiCreate2dCompDef – Creates new component definition.
  • amiInstance2dComp – Creates component instances based on component definition.
  • ami2DSCreateCompViewDef – Creates component view definition based on previously created component.
  • ami2DSInstanceCompView – Creates component view instance based on component view definition.
  • ami2DSInstanceAnnotationView – Creates annotation view.
  • ami2DSCreateAnnotationViewLabels – Creates annotation view labels for annotation views.
  • ami2DSGetViewsInComp – Gets views contained in a component.
  • ami2DSGetViewName – Gets the view name.
  • ami2DSGetCompViewOwnerDef – Gets the owner's definition of a component view.
  • ami2DSGetViewOwnerDef – Gets the owner's definition of a view.
  • ami2DSGetNextComponentDefinitionName – Gets the name of a component definition, that follows the specified name.
  • ami2DSGetViewGeomExtents – Gets the geometrical extents of a view.
  • ami2DSGetViewDefChildren – Gets view definition's children.
  • ami2DSCompDefHasComponentViewDefinition – Indicates whether the specified component definition contains a certain component view definition.
  • amiGetCompInstanceByGeom – Gets a component instance by geometry.
  • amiGetMasterCompDef – Gets a master component definition.
  • amiGetMasterViewDef – Gets a master view definition.
  • amiGetCompDef – Gets the definition of a specified component.
  • amiGetCompDefChildren – Gets component definition children.
  • amiGetCompName – Gets the name of a component.
  • amiGetCompOwner – Gets the owner of a component.
  • amiIsCompDefMaster – Indicates whether the specified component definition is the master component definition.
  • amiIsCompDefFeature – Indicates whether the component definition is a feature.
  • amiIsCompDef2DAssembly – Indicates whether the component definition is a 2D assembly.
  • amiIsCompDefExternal – Indicates whether the component definition is external.
  • amiSetCompDefName – Sets a new name for a component definition.

 

Simple Mechanical Structure Example

This section provides an example of creating, marking, gethering geometry and putting it in a BOM table.

At first, some basic geometry should be created, Circle and Line for Top and Front view of the same detail:


OdGeVector3d topPos(200.0, 100.0, 0.0);
OdGeVector3d frontPos(400.0, 100.0, 0.0);
        
OdDbCirclePtr pCircle1 = OdDbCircle::createObject();
pCircle1->setDatabaseDefaults(pDb);
pCircle1->setCenter(topPos.asPoint());
pCircle1->setRadius(50.0);
pTMModelSpace->appendOdDbEntity(pCircle1);
       
OdDbLinePtr pLine1 = OdDbLine::createObject();
pLine1->setDatabaseDefaults(pDb);
pLine1->setStartPoint(frontPos.asPoint() + OdGeVector3d(-50.0, .0, .0));
pLine1->setEndPoint(frontPos.asPoint() + OdGeVector3d(50.0, .0, .0));
pTMModelSpace->appendOdDbEntity(pLine1);

As soon as geometry is created, a component can be created and instantiated too. This example demonstrates creation process of one component and two attached component views:

AmiCompDefKeyPtr pCompDefKey1;
AmiCompKeyPtr    pCompKey1;
amiCreate2dCompDef(pDb, pCompDefKey1, L"CIRCLE_COMPONENT");
amiInstance2dComp(pDb, pCompKey1, pCompDefKey1, AmiCompDefKeyPtr());

When the component is created, first component view (Top view) can be created too:

OdGeMatrix3d compMatrix1;
compMatrix1.setTranslation(topPos);
AmiCompViewDefKeyPtr pComp1TopDef;
AmiCompViewKeyPtr    pComp1Top;
OdArray<AmiFolderKey> arrayFolders;
OdDbObjectIdArray entities;
entities.append(pCircle1->objectId());
       
ami2DSCreateCompViewDef(pDb,
  pComp1TopDef,
  pComp1Top,
  pCompKey1,
  entities,
  arrayFolders,
  compMatrix1,
  AmiFolderKeyPtr(),
  L"Top");

Additional component view (Front view):

OdGeMatrix3d compMatrixFront;
compMatrixFront.setTranslation(frontPos);
AmiCompViewDefKeyPtr pComp1FrontDef;
AmiCompViewKeyPtr    pComp1Front;
OdArray<AmiFolderKey> arrayFoldersFront;
OdDbObjectIdArray entitiesFront;
entitiesFront.append(pLine1->objectId());
   
ami2DSCreateCompViewDef(
  pDb,
  pComp1FrontDef,
  pComp1Front,
  pCompKey1,
  entitiesFront,
  arrayFoldersFront,
  compMatrixFront,
  AmiFolderKeyPtr(),
  L"Front");

When components are done, a BOM table which includes the component can be created:

AcmBOMManagerPtr pBomMgr = getAcmBomMgr();
OdDbObjectId bomId;
pBomMgr->createBomTable(bomId, OdDbObjectId::kNull, OD_T("MAIN"), true, pDb);

Physical representation of a new BOM table (with component row) in Database dictionary:

You can find more information in our documentation