- UID
- 76534
- 积分
- 0
- 精华
- 贡献
-
- 威望
-
- 活跃度
-
- D豆
-
- 在线时间
- 小时
- 注册时间
- 2003-9-2
- 最后登录
- 1970-1-1
|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
//this function is to attach the object data to the selection which is fit to
// the input layer name
//功能:先取得使用者輸入的圖層名稱,再取得使用者輸入的選集
//當選集中物件是在使用者輸入的圖層時attach the object data
//執行時都能正常運作 但object data不能貼附到物件上
// ----- asdkmap._addODbyLayer command (do not rename)
static void asdkmap_addODbyLayer(void)
{
// Add your code for command asdkmap._addODbyLayer here
ads_name ss, ename;
long sslen, sscur;
AcDbObjectId eId;
AcDbEntity *pEnt;
AcMapSession *mapApi = NULL;
AcMapProject *pProj = NULL;
AcMapODContainer *pODCont = NULL;
AcMapODTable *pODTable = NULL;
mapApi = AcMapGetSession();
mapApi->GetProject(pProj);
pProj->GetODContainer(pODCont);
pODCont->GetODTable(pODTable, "owner");
// acutPrintf("flag 7\n");
//get input layer 取得 與用者輸入的圖層名稱
AcDbObjectId inputLayerID;
char inputLayerName[3];
if (acedGetString(0,"input filter layer name:",inputLayerName) == Adesk::kFalse){
acutPrintf("\nlayer Name is not suitable");
return;
}
if(checkLayer(inputLayerName) !=Acad::eOk){
return;
}
getLayerIdFromString(inputLayerName,inputLayerID);
//選取物件
acutPrintf("\nselect the objects you want to add object data ?");
if (acedSSGet(NULL, NULL, NULL, NULL, ss) != RTNORM) {
acutPrintf("\nNo objects selected.\n");
acedSSFree(ss);
return;
}
acedSSLength(ss, &sslen);
acutPrintf("flag 6");
//check every entity in the selection and attach the object data, if fit the condition
//檢查每個物件是否在指定圖層上 如果是在指定圖層上 attach object data
for (sscur = 0; sscur < sslen; sscur++)
{
acedSSName(ss, sscur, ename);
acdbGetObjectId(eId, ename);
acdbOpenAcDbEntity(pEnt, eId, AcDb::kForRead);
char *temp;
temp = pEnt->layer();
if(*temp == inputLayerName[0]){
// attachODById(eId);
AcMapODTableRecord *pTabRec = NULL;
pTabRec = new AcMapODTableRecord();
pODTable->AddRecord(*pTabRec , eId);
acutPrintf("\n object id : %lx", eId);
//acutPrintf(\n object id : %lx", targetId);
//acutPrintf("\nObject Id %lx",targetId);
acutPrintf ("\nOD Record added to object.");
if (pTabRec) delete pTabRec;
highlightAll(eId);
}
pEnt->close();
}
delete pODTable;
acedSSFree(ss);
}
//檢查圖層是否存在
static Acad::ErrorStatus
checkLayer(char* layerName)
{
AcDbLayerTable *pLayerTbl;
acdbHostApplicationServices()->workingDatabase()
->getSymbolTable(pLayerTbl, AcDb::kForWrite);
if (!pLayerTbl->has(layerName)) {
return Acad::eNotApplicable;
} else {
pLayerTbl->close();
acutPrintf("\nlayer already exists");
return Acad::eOk;
}
}
//從輸入的字串取得layerId
static Acad::ErrorStatus
getLayerIdFromString(const char* pStr, AcDbObjectId& ID)
{
// Get a pointer to the drawing's layer table
//
AcDbLayerTable* pLayerTable;
Acad::ErrorStatus err = acdbCurDwg()->getLayerTable(pLayerTable,
AcDb::kForRead);
if (err != Acad::eOk)
return err;
// Get the ID of the layer with the name in 'pStr' (even if it's
// erased) and place it in 'id'.
//
err = pLayerTable->getAt(pStr, ID, Adesk::kTrue);
pLayerTable->close();
return err;
} |
|