ObjectARX, AutoCAD. Среда программирования библиотеки C++

Пример Использования AcGi


Следующий пример иллюстрирует, как использовать AcGi. Сначала, это сохраняет текущие значения свойства примитива на цвет, linetype, и уровень. Тогда это изменяет номер цвета черты под-примитива к синему и рисует ломаную линию с тремя точками. Затем, это изменяет номер цвета черты подпримитива к текущему цвету уровня, изменяет значение linetype к DASHDOT, и рисует xline.

Типовой код включает две функции, getLinetypeFromString () и getLayerIdFromString (), которые позволяют Вам получать ID для linetype или уровня от строки.

ОБРАТИТЕ ВНИМАНИЕ Практически, эти функции могли бы также не спешить, использование в пределах worldDraw (), и объектных ID должно быть сохранено и использоваться непосредственно.

static Acad::ErrorStatus

getLinetypeIdFromString(const char* str, AcDbObjectId& id);

static Acad::ErrorStatus

getLayerIdFromString(const char* str, AcDbObjectId& id);

Adesk::Boolean

AsdkTraitsSamp::worldDraw(AcGiWorldDraw* pW)

{

// At this point, the current property traits are

// the entity’s property traits. If the current

// property traits are changed and you want to



// reapply the entity’s property traits, this is

// the place to save them.

//

Adesk::UInt16 entity_color

= pW->subEntityTraits().color();

AcDbObjectId entity_linetype

= pW->subEntityTraits().lineTypeId();

AcDbObjectId entity_layer

= pW->subEntityTraits().layerId();

// Override the current color and make it blue.

//

pW->subEntityTraits().setColor(kBlue);

// Draw a blue 3-point polyline.

//

int num_pts = 3;

AcGePoint3d *pVerts = new AcGePoint3d[num_pts];

pVerts[0] = AcGePoint3d(0.0, 0.0, 0);

pVerts[1] = AcGePoint3d(1.0, 0.0, 0);

pVerts[2] = AcGePoint3d(1.0, 1.0, 0);

pW->geometry().polyline(num_pts, pVerts);

// Force the current color to use current layer’s color.

//

pW->subEntityTraits().setColor(kColorByLayer);

// Force current line type to DASHDOT. If

// DASHDOT is not loaded, the current linetype

// will still be in effect.

//

AcDbObjectId dashdotId;


if (getLinetypeIdFromString("DASHDOT", dashdotId) == Acad::eOk)
{
pW->subEntityTraits().setLineType(dashdotId);
}
// Force current layer to "MY_LAYER". If
// "MY_LAYER" is not loaded, the current layer
// will still be in effect.
//
AcDbObjectId layerId;
if (getLayerIdFromString("MY_LAYER", layerId) == Acad::eOk)
{
pW->subEntityTraits().setLayer(layerId);
}
// Draw a DASHDOT xline in "MY_LAYER"’s color.
//
pW->geometry().xline(pVerts[0], pVerts[2]);
delete [] pVerts;
return Adesk::kTrue;
}
// A useful function that gets the linetype ID from the
// linetype’s name; the name must be in upper case.
//
static Acad::ErrorStatus
getLinetypeIdFromString(const char* str, AcDbObjectId& id)
{
Acad::ErrorStatus err;
// Get the table of currently loaded linetypes.
//
AcDbLinetypeTable *pLinetypeTable;
err = acdbHostApplicationServices()->workingDatabase()
->getSymbolTable(pLinetypeTable, AcDb::kForRead);
if (err != Acad::eOk)
return err;
// Get the ID of the linetype with the name that
// str contains.
//
err = pLinetypeTable->getAt(str, id, Adesk::kTrue);
pLinetypeTable->close();
return err;
}
// A useful function that gets the layer ID from the
// layer’s name; the layer name must be in upper case.
//
static Acad::ErrorStatus
getLayerIdFromString(const char* str, AcDbObjectId& id)
{
Acad::ErrorStatus err;
// Get the table of currently loaded layers.
//
AcDbLayerTable *pLayerTable;
err = acdbHostApplicationServices()->workingDatabase()
->getSymbolTable(pLayerTable, AcDb::kForRead);
if (err != Acad::eOk)
return err;
// Get the ID of the layer with the name that str
// contains.
//
err = pLayerTable->getAt(str, id, Adesk::kTrue);
pLayerTable->close();
return err;
}

Содержание раздела