Creating elements in MDL applications


MicroStation has many types of elements that we can divide into graphical and non-graphical elements. This chapter will discuss how to create graphical elements in MDL programs. Since the CE SDK encapsulates the original C functions, it provides a new set of methods for creating elements. The following table lists most of the graphic elements supported in MicroStation. It also lists the old and new methods of creating elements.

ELEMENT TYPE

GRAPHICAL REPRESENTATION

FUNCTION

NOTES

Line

mdlLine_create

ICurvePrimitive::CreateLine

LineHandler::CreateLineElement

A line consisting of two points.

PointString

mdlPointString_create

ICurvePrimitive::CreatePointString

PointStringHandler::CreateLineStringElement

Discrete points consisting of up to 2000 points.

LineString

 

mdlLineString_create

ICurvePrimitive::CreateLineString

LineStringHandler::CreateLineStringelement

Multi-segment line consisting of up to 5000 points.

mdlElmdscr_createFormVertices can create complex LineString with more than 5000 points.

Shape

 

mdlShape_create

ICurvePrimitive::CreateRectangle

CurveVector::CreateLinear

ShapeHandler::CreateShapeElement

Closed straight line segment consisting of up to 5000 points.

mdlElmdscr_createFormVertices can create complex LineString with more than 5000 points.

mdlElmdscr_createShapeWithHole can create hollow shape.

Arc

 

mdlArc_create

mdlArc_createByCenter

mdlArc_createByDEllipse3d

mdlArc_createByPoints

ICurvePrimitive::CreateArc

ArcHandler::CreateArcElement

 

Ellipse

 

mdlEllipse_create

mdlCircle_createBy3Pts

CurveVector::CreateDisk

EllipseHandler::CreateEllipseElement

Circle and Ellipses are the same element type.

ComplexChain ComplexShape

 

mdlComplexChain_createHeader

ChainHeaderHandler::CreateChainHeaderElement/

AddComponentElement/ AddComponentComplete

This function creates complex elements, and then appends elements such as lines and/or arcs to form the final ComplexChain or ComplexShape.

Curve

 

mdlCurve_create

CurveHandler::CreateCurveElement

The simple type of curve that passes through the points you specify.

BsplineCurve

 

mdlBspline_createCurve

mdlBspline_createInterpolationCurve

BSplineCurveHandler::CreateBSplineCurveElement

Can build MSBsplineCurve with

mdlBspline_createBsplineFromPointAndOrder

Multiline

 

mdlMline_create

MultiLineHandler::CreateMultiLineEement

Multiple straight lines consisting of up to 16 lines

Text

 

TestHandlerBase::CreateElement/TextBlock

Text element. The old method will be

deprecated in future

TextNode

 

TestHandlerBase::CreateElement/TextBlock

Text with multiple styles in single or multiline text.

Tag

 

mdlTag_create

A text associated with a graphical element.

Tag will be replaced by item.

Dimension

 

mdlDim_create

DimensionHandler::CreateDimensionElement

 

Cell

 

mdlCell_create

mdlCell_placecCell

mdlCell_getElmDscr

mdlCell_getElmDscr

Extended

NormalCellHeaderHandler::CreateCellelement

mdlCell_create does not rely on the cell library to create a cell header. mdlCell_placeCell or mdlCell_getElmDscr can directly read a cell from the cell library.

SharedCell

 

mdlSharedcell_create

SharedCellHandler::CreateSharedCellElement

Multiple SharedCells shared one ShareCell

definition. It could be used to significantly

reduce model size when there are multiple

identical complex cells

Cone

 

mdlCone_create

ConeHandler::CreateConeElement

This function can be used to create both

cylinders and cones

Surface Solid

 

mdlSurface_project

mdlSurface_resolve

SurfaceOrSolidHandler::CreateProjectionElement

SurfaceOrSolidHandler::CreateresolutionElement

For two old functions you can set edp-

>el.ehdr.type = SOLID_ELM to generate solid. In the new two functions, there is a preferSolid flag which can be used to control whether to generate surface or solid.

SmartSolid

 

mdlKISolid_makeCuboid

mdlKISolid_makePrism

mdlKISolid_makeSphere

mdlKISolid_makeCone

mdlKISolid_makeTorus

mdlKISolid_makeWedge

mdlKISolid_sweepodyWire

ISolidPrimitive::CreateDgnTorusPipe

ISolidPrimitive::CreateDgnCone

ISolidPrimitive::CreateDgnBox

ISolidPrimitive::CreateDgnSphere

ISolidPrimitive::CreateDgnExtrusion

ISolidPrimitive::CreateDgnRotationSweep

ISolidPrimitive::CreateDgnRuledSweep

SolidUtil::Create

SmartSolid handles geometry with the help of the ParaSolid, but the ordinary solids do not. Therefore, for some basic 3D model, both ordinary solid and SmartSolid can be used to create them. The ordinary solid is more efficient than the SmartSolid, but it cannot express complex solids.

BsplineSurface

 

mdlBspline_createSurface

mdlBspline_crossSectionSurface

mdlBspline_gordonSurface

mdlBspline_coonsPatch

mdlBspline_nSidePatch

mdlBspline_skinPatch

mdlBspline_ruledSurface

mdlBspline_surfaceOfProjection

mdlBspline_surfaceOfRevolution

mdlBspline_catmullRomSurface

MSBsplineSurface::CreateXXX

Accurate surface expression.

Mesh

 

mdlMesh_newCoordinateBlock

mdlMesh_newGrid

mdlMesh_newPolyface

mdlMesh_newRegularPolyhedron

PolyfaceHeader::CreateXXX

Mesh is suitable for expressing large-scale ground model mesh data, but the accuracy will be worse than BsplineSurface.

In the CE SDK, most of the old C functions are still retained, but their function prototypes have changed. The main reason is that the CE version completely uses Unicode character encoding. This chapter will only introduce the new C ++ programming method. 

One of the most important classes in CE SDK is ElementHandle, whose object represents an element in memory. MDL defines multiple variants for the same class, the purpose of which is to simplify the writing of C ++ itself. As shown in the following table: 

Class Name 

Actual definition 

ElementHandleP 

ElementHandle * 

ElementHandleCP 

ElementHandle const * 

ElementHandleR 

ElementHandle & 

ElementHandleCR 

ElementHandle const & 

After understanding some of the basics above, we started to write code to generate elements.

1. Edit the HelloWorld.cpp file. The final result is as follows:

/*-------------------------------------------------------------+ 

|   HelloWorld.cpp                                                | 

+-------------------------------------------------------------*/ 

#include <Mstn\MdlApi\MdlApi.h> 

#include <DgnPlatform\DgnPlatformApi.h> 

 

USING_NAMESPACE_BENTLEY_DGNPLATFORM 

USING_NAMESPACE_BENTLEY_MSTNPLATFORM 

USING_NAMESPACE_BENTLEY_MSTNPLATFORM_ELEMENT 

 

double g_1mu; 

 

void createALine(DPoint3dCR basePt) 

{ 

EditElementHandle eeh; 

DSegment3d seg; 

seg.Init(basePt, DPoint3d::From(basePt.x + g_1mu * 2, basePt.y + g_1mu)); 

ICurvePrimitivePtr pCurve = ICurvePrimitive::CreateLine(seg); 

DraftingElementSchema::ToElement(eeh, *pCurve, nullptr, ACTIVEMODEL->Is3d(), *ACTIVEMODEL); 

eeh.AddToModel(); 

} 

 

void createAComplexShape(DPoint3dCR basePt) 

{ 

EditElementHandle eeh; 

DPoint3d         pts[3]; 

 

pts[0] = pts[1] = pts[2] = basePt; 

pts[1].x += g_1mu*0.3;    pts[1].y += g_1mu*0.7; 

pts[0].x += g_1mu;        pts[0].y += g_1mu; 

DEllipse3d arcPts = DEllipse3d::FromPointsOnArc(pts[2], pts[1], pts[0]); 

CurveVectorPtr pCurveVec = CurveVector::Create(CurveVector::BOUNDARY_TYPE_Outer); 

pCurveVec->Add(ICurvePrimitive::CreateArc(arcPts)); 

 

pts[1].x = pts[0].x;    pts[1].y = pts[2].y; 

pCurveVec->Add(ICurvePrimitive::CreateLineString(pts, 3)); 

DraftingElementSchema::ToElement(eeh, *pCurveVec, nullptr, ACTIVEMODEL->Is3d(), *ACTIVEMODEL); 

eeh.AddToModel(); 

} 

 

void createAProjectedSolid(DPoint3dCR basePt) 

{ 

DPoint3d  pts[6]; 

pts[0] = basePt; 

pts[1].x = pts[0].x;               pts[1].y = pts[0].y - g_1mu / 2;   pts[1].z = pts[0].z; 

pts[2].x = pts[1].x + g_1mu / 2;   pts[2].y = pts[1].y;               pts[2].z = pts[0].z; 

pts[3].x = pts[2].x;               pts[3].y = pts[2].y - g_1mu / 2;   pts[3].z = pts[0].z; 

pts[4].x = pts[3].x + g_1mu / 2;   pts[4].y = pts[3].y;               pts[4].z = pts[0].z; 

pts[5].x = pts[4].x;               pts[5].y = pts[0].y;               pts[5].z = pts[0].z; 

 

CurveVectorPtr pCurveVec = CurveVector::CreateLinear(pts, 6, CurveVector::BOUNDARY_TYPE_Outer); 

DVec3d extrusionVec = DVec3d::From(0, 0, g_1mu); 

DgnExtrusionDetail  data(pCurveVec, extrusionVec, true); 

ISolidPrimitivePtr pSolid = ISolidPrimitive::CreateDgnExtrusion(data); 

EditElementHandle eeh; 

DraftingElementSchema::ToElement(eeh, *pSolid, nullptr, *ACTIVEMODEL); 

eeh.AddToModel(); 

} 

 

void createABsplineSurface(DPoint3dCR basePt) 

{ 

MSBsplineSurface bsSurface; 

MSBsplineCurve   bsCurves[4]; 

DPoint3d         center[4]; 

RotMatrix        rMatrix[4]; 

double           radius = g_1mu / 2; 

 

center[0] = center[1] = center[2] = center[3] = basePt; 

center[0].x += radius; 

center[1].x += g_1mu;     center[1].y += radius; 

center[2].x += radius;    center[2].y += g_1mu; 

center[3].y += radius; 

 

DVec3d xVec = DVec3d::From(1, 0, 0), negativeXVec = DVec3d::From(-1, 0, 0); 

DVec3d yVec = DVec3d::From(0, 1, 0), negativeYVec = DVec3d::From(0, -1, 0); 

DVec3d zVec = DVec3d::From(0, 0, 1); 

rMatrix[0].InitFrom2Vectors(xVec, zVec);  //Front View 

rMatrix[1].InitFrom2Vectors(yVec, zVec);  //Right View 

rMatrix[2].InitFrom2Vectors(negativeXVec, zVec);  //Back View 

rMatrix[3].InitFrom2Vectors(negativeYVec, zVec);  //Left View 

 

EditElementHandle eeh; 

for (int i = 0; i<4; i++) 

{ 

bsCurves[i].InitEllipticArc(center[i], radius, radius, 0, PI, &rMatrix[i]); 

} 

if (SUCCESS == mdlBspline_coonsPatch(&bsSurface, bsCurves)) 

{ 

DraftingElementSchema::ToElement(eeh, bsSurface, nullptr, *ACTIVEMODEL); 

eeh.AddToModel(); 

mdlBspline_freeSurface(&bsSurface); 

} 

for (int i = 0; i<4; i++) 

mdlBspline_freeCurve(&bsCurves[i]); 

} 

 

extern "C" DLLEXPORT void MdlMain(int argc, WCharCP argv[]) 

{ 

ModelInfoCP pInfo = ACTIVEMODEL->GetModelInfoCP(); 

g_1mu = pInfo->GetUorPerStorage(); 

 

DPoint3d basePt = DPoint3d::FromZero(); 

createALine(basePt); 

basePt.x += g_1mu*1.7;     basePt.y -= g_1mu*0.3;    basePt.z -= g_1mu*0.6; 

createAComplexShape(basePt); 

basePt.x += g_1mu*1.5;     basePt.y -= g_1mu*0.3;    basePt.z -= g_1mu*0.6; 

createAProjectedSolid(basePt); 

basePt.x += g_1mu*2.2;     basePt.y -= g_1mu*1.7;    basePt.z -= g_1mu*0.6; 

createABsplineSurface(basePt); 

} 

Explanation:

2. Type bmake -a in the MicroStation Developer Shell to generate the final HelloWorld.ma and HelloWorld.dll.

3. Start MicroStation, open or create a new 3D model, type MDL LOAD HelloWorld in the input command field and press Enter to generate the figure shown below. This graphic is the effect seen in the ISO view.

Tips:

Prev:[[Detailed explanation of mke file]]Next:[[Adding commands to MDL applications]]