概要
Mechanical SDK は、特定のレイヤー上にオブジェクトを作成するように事前設定されています。現在のレイヤーが何に設定されていても、Mechanical SDK は定義済みのレイヤー上にのみオブジェクトを作成します。レイヤーが存在しない場合は、自動的に作成されます。これらのメカニカルレイヤーには、レイヤーの色、線種など、事前定義された設定があり、これらはレイヤー定義と呼ばれる事前設定された設定セットから取得されます。
複数のメカニカルレイヤーセットを作成できます。各セットはレイヤーグループと呼ばれます。メカニカルレイヤーグループを使用すると、次のことができます。
- オブジェクトをあるレイヤーグループから別のレイヤーグループに移動またはコピーする。
- レイヤーグループの一部である個々のレイヤーをグローバルに操作する。たとえば、作成したレイヤーグループに関係なく、線種を変更できます。
- レイヤーグループの色を設定し、個々のレイヤーの色をレイヤーグループの色で上書きする。
- 設計作業を簡素化するためにレイヤーグループをロックおよびフリーズする。
必要なクラスと関数が宣言されているファイルは3つあります。
- AmiLayer.h
- AmiLayerCfg.h
- AmiLayObjCfg.h
これらのファイルは McadApi モジュールに属しており、パブリックの Include ディレクトリで利用できます。
レイヤー操作の例
以下のいずれかのメカニカルレイヤーを作成できます: AM_0, AM_1, AM_2, AM_3, AM_4, AM_5, AM_6, AM_7, AM_8, AM_9, AM_10, AM_11, AM_12, AM_0N, AM_1N, AM_2N, AM_3N, AM_4N, AM_5N, AM_6N, AM_7N, AM_8N, AM_9N, AM_10N, AM_11N, AM_12N, AM_CL, AM_PAREF, AM_BOR, AM_VIEWS, AM_INV, AM_TR, AM_HID, AM_VIS, AM_PARDIM, AM_REFDIM。
これらのレイヤーには、事前設定された一連のパラメーターが含まれており、それらのパラメーターに基づいて作成されます。メカニカルレイヤーを作成するには、リストから名前を使用してください。そうしないと、通常のレイヤーが作成されます。
新しいメカニカルレイヤーを作成するには、次のコード例を使用します。
// Note: The next block of code requires additional inclusion of "AmiLayer.h"
OdDbDatabase* pDb = ... // get a pointer to the current database
OdString layerName = L"AM_11"; // layer name from the list above to create
OdString layerGroup; // group name can be empty, in this case no group is
// created. If you want to create a layer in a specific
// group, then specify the name of the group
AmiStatus status = amiCreateLayer(layerName, layerGroup, pDb);
if (status.success())
{
... // The layer is successfully created
}
else
{
... // The layer can not be created. Perhaps it already exists or input
// parameters are not set correctly
}
ファイルからレイヤー設定をインポートするには、次のコード例を使用します。
// Note: The next block of code requires additional inclusion of "AmiLayer.h"
OdDbDatabase* pDb = ... // get a pointer to the current database
bool bReplace = true; // for a complete copy of mechanical layer settings
// if set as false, only part of settings will be copied
OdString dwgName = ... // set file path with file name for settings import
AmiStatus status = amiImportLayCfg(pDb, dwgName, bReplace);
if (status.success())
{
... // Settings successfully imported
}
else
{
... // Failure during import
}
メカニカルレイヤーに関連するすべての設定を工場出荷時のデフォルトにリセットするには、次のコード例を使用します。
//Note: The next block of code requires additional inclusion of "AmiLayer.h"
OdDbDatabase* pDb = ... // get a pointer to the current database
AmiStatus status = amiSetLayCfgDefault(pDb);
if (status.success())
{
... // Settings successfully restored to defaults
}
else
{
... // Failure during settings reset
}
指定された標準のすべてのメカニカルレイヤーの配列を取得するには、次のコード例を使用します。
// Note: The next block of code requires additional inclusion of "AmiLayer.h" and
// "AcmStandardManager.h"
OdDbDatabase* pDb = ... // get a pointer to the current database
// get the current std ID
OdDbObjectId stdId;
if (getAcmStdMgr()->getCurrent(stdId, pDb) != Acm::eOk)
return;
OdArray<AmiLayerCfg*> arLayCfg;
AmiStatus status = amiGetAllLayers(arLayCfg, stdId);
if (status.success())
{
// Perform some actions with the array. For example you can loop through all
// elements of the array and set the same lineweight value. In this case don't
// forget to add the "AmiLayerCfg.h" inclusion
for (OdUInt16 i = 0; i < arLayCfg.length(); ++i)
{
AmiLayerCfg* pLayerCfg = arLayCfg[i];
if (pLayerCfg)
pLayerCfg->setLineweight(OdDb::kLnWt005);
}
}
else
{
... // Failure during execution
}
// Don't forget to clear the memory because the ‘new’ operator is used to create
// each element in the array
for (OdUInt16 i = 0; i < arLayCfg.length(); ++i)
delete arLayCfg[i];
1つのメカニカルレイヤーの値のみを変更する場合、配列全体を取得してその中の特定のオブジェクトを探す必要はありません。以下のコード例を使用して変更できます。
// Note: The next block of code requires additional inclusion of "AmiLayer.h",
// "AcmStandardManager.h" and "AmiLayerCfg.h"
OdDbDatabase* pDb = ... // get a pointer to the current database
// get the current std ID
OdDbObjectId stdId;
if (getAcmStdMgr()->getCurrent(stdId, pDb) != Acm::eOk)
return;
OdString layerName = ... // set the layer name from the previously mentioned
// list of names for the amiCreateLayer() function
AmiLayerCfg* layerProp = NULL;
AmiStatus status = amiGetLayerProperty(layerName, layerProp, stdId);
if (status.success())
{
layerProp->setInvisible(true);
}
else
{
... // Failure during execution. Perhaps the input parameters are incorrect
}
// Don't forget to clear the memory because the ‘new’ operator was used for
// object creation
if (layerProp)
delete layerProp;
指定された標準のすべてのメカニカルレイヤーオブジェクトの配列を取得するには、次のコード例を使用します。
// Note: The next block of code requires additional inclusion of "AmiLayer.h" and
// "AcmStandardManager.h"
OdDbDatabase* pDb = ... // get a pointer to the current database
// get the current std ID for amiGetAllLayerObjs
OdDbObjectId stdId;
if (getAcmStdMgr()->getCurrent(stdId, pDb) != Acm::eOk)
return;
OdArray<AmiLayObjCfg*> arLayObjCfg;
AmiStatus status = amiGetAllLayerObjs(arLayObjCfg, stdId);
if (status.success())
{
// Perform an action with the array. For example you can loop through all
// elements of the array and set the same line weight value. In this case
// don't forget to add the "AmiLayObjCfg.h" inclusion
for (OdUInt16 i = 0; i < arLayObjCfg.length(); ++i)
{
AmiLayObjCfg* pLayObjCfg = arLayObjCfg[i];
if (pLayObjCfg)
pLayObjCfg->setLineweight(OdDb::kLnWt005);
}
}
else
{
... // Failure during execution
}
// Don't forget to clear the memory because the ‘new’ operator is used to create
// each element in the array
for (OdUInt16 i = 0; i < arLayObjCfg.length(); ++i)
delete arLayObjCfg[i];
1つのメカニカルレイヤーオブジェクトの値のみを変更する場合(メカニカルレイヤーの例と同様に)、配列全体を取得してその中の特定のオブジェクトを探す必要はありません。特別なキーを使用して目的のオブジェクトを取得できます。利用可能なすべてのキーは以下のとおりです。
BHNV, BHNVS, BOR2, BOR3, BOR5, CAL2, CAL3, CAL5, CAL7, CENN, CENW, CLIN, CON1, CON2, CON3, CON4, DETA, DIAG, DILI, DIMP, DIMR, FEMN, FEMPN, FEMSP, FEMST, FEMVN, FEMVT, HATC, HIDN, HIDW, HLIN, HOCN, HOCW, INFO, LEAD, N_BHNV, N_CON1, N_CON2, N_CON3, N_CON4, N_CENN, N_CENW, N_DILI, N_HATC, N_HIDN, N_HIDW, N_LEAD, N_NGIP, N_PHAN, N_TCON, N_THLI, N_TLEN, N_VPLI, NGIP, PAL2, PAL3, PAL5, PHAN, POSN, RCGN, RCGW, BRK, SECT, SYB3, MSYM, TCON, THLI, TIT2, TIT3, TIT5, TLEN, TRAIL, TRLI, TXT1, TXT2, TXT3, TXT5, TXT7, VIEW, VEDH, VEDV, VPLI, ZIZA, SPLI。
// Note: The next block of code requires additional inclusion of "AmiLayer.h",
// "AcmStandardManager.h" and "AmiLayObjCfg.h"
OdDbDatabase* pDb = ... // get a pointer to the current database
// get the current std ID
OdDbObjectId stdId;
if (getAcmStdMgr()->getCurrent(stdId, pDb) != Acm::eOk)
return;
OdString objKey = ... // set a key of the mechanical layer object from the list above
AmiLayObjCfg* objProp = NULL;
AmiStatus status = amiGetLayerObjProperty(objKey, objProp, stdId);
if (status.success())
{
OdCmColor color;
color.setColorIndex(3);
objProp->setTrueColor(color);
}
else
{
... // Failure during execution. Perhaps the input parameters are incorrect
}
// Don't forget to clear the memory because the ‘new’ operator was used for
// object creation
if (objProp)
delete objProp;