CAFE

ARX강좌

XDATA관련

작성자구대근|작성시간01.03.30|조회수855 목록 댓글 0
답변자 : 안창근 답변자 메일 : zewoang@cospec.co.kr 답변자 IP : 211.33.124.253 게시물 내용입니다 C++이라기엔 뭐하군요.. 그런 코드가 별로 없어서.. ObjectARX 라이브러리가 필요합니다. 대부분이 resbuf를 사용하기 때문에 포팅하는건 무리가 없을듯하네요. void printList(struct resbuf *rb); void addXdata() { ads_name ename; int success; ads_point pt; AcDbObjectId objId; AcDbEntity *pObj; char STR1[256], STR2[256]; ads_printf("\n>> Add X Data..."); /////////Get Entity//////////////////// success = ads_entsel(NULL, ename, pt); if (success != RTNORM) return; STR2[0] = STR1[0] = ''\0''; /////////Get String//////////////////// success = ads_getstring(1, "\nInput registered application name: ", STR1); if (success != RTNORM || !STR1[0]) return; success = ads_getstring(1, "\nInput application''s extended data: ", STR2); if (success != RTNORM) return; /////////Open Entity////////////////////// if (acdbGetObjectId(objId, ename) != Acad::eOk) { ads_printf("<*ERROR*> retrieving object id.\n"); return; } if (acdbOpenObject(pObj, objId, AcDb::kForWrite) != Acad::eOk) { ads_printf("<*ERROR*> opening object for write.\n"); return; } /////////Add X Data//////////////////////// struct resbuf *pRb, *pTemp; pRb = pObj->xData(STR1); if (pRb != NULL) { // If xdata is present, then walk to the // end of the list. // for (pTemp = pRb; pTemp->rbnext != NULL; pTemp = pTemp->rbnext) { ; } } else { // If xdata is not present, register the application // and add appName to the first resbuf in the list. // Notice that there is no -3 group as there is in // AutoLISP. This is ONLY the xdata so // the -3 xdata-start marker isn''t needed. // acdbRegApp(STR1); pRb = acutNewRb(AcDb::kDxfRegAppName); pTemp = pRb; pTemp->resval.rstring = (char*) malloc(strlen(STR1) + 1); strcpy(pTemp->resval.rstring, STR1); } // Add user-specified string to the xdata. // pTemp->rbnext = acutNewRb(AcDb::kDxfXdAsciiString); pTemp = pTemp->rbnext; pTemp->resval.rstring = (char*) malloc(strlen(STR2) + 1); strcpy(pTemp->resval.rstring, STR2); // The following code shows the use of upgradeOpen() // to change the entity from read to write. // pObj->upgradeOpen(); pObj->setXData(pRb); pObj->close(); acutRelRb(pRb); } void listXdata() { ads_name ename; int success; ads_point pt; AcDbObjectId objId; AcDbEntity *pObj; ads_printf("\n>> List X Data..."); /////////Get Entity//////////////////// success = ads_entsel(NULL, ename, pt); if (success != RTNORM) return; /////////Open Entity////////////////////// if (acdbGetObjectId(objId, ename) != Acad::eOk) { ads_printf("<*ERROR*> retrieving object id.\n"); return; } if (acdbOpenObject(pObj, objId, AcDb::kForRead) != Acad::eOk) { ads_printf("<*ERROR*> opening object for read.\n"); return; } // Get the application name for the xdata. // /*char appname[133]; if (acedGetString(NULL, "\nEnter the desired Xdata application name: ", appname) != RTNORM) return;*/ // Get the xdata for the application name. // struct resbuf *pRb, *pTrace; pRb = pObj->xData();//Get All X Data Header //pRb = pObj->xData(appname); if (pRb != NULL) { // Print the existing xdata if any is present. // Notice that there is no -3 group, as there is in // LISP. This is ONLY the xdata, so // the -3 xdata-start marker isn''t needed. // pTrace = pRb; do { printList(pTrace); pTrace = pTrace->rbnext; } while (pTrace); acutRelRb(pRb); } else { acutPrintf("\nNo xdata for this appname"); } pObj->close(); } void printList(struct resbuf *rb) { switch (rb->restype) { case 1001 : acutPrintf("\nApp Name : %s", rb->resval.rstring); break; case 1000 : acutPrintf("\nString : %s", rb->resval.rstring); break; } } void removeXdata() { ads_name ename; int success; ads_point pt; AcDbObjectId objId; AcDbEntity *pObj; char STR1[256], STR2[256]; ads_printf("\n>> Remove X Data..."); /////////Get Entity//////////////////// success = ads_entsel(NULL, ename, pt); if (success != RTNORM) return; STR2[0] = STR1[0] = ''\0''; /////////Get String//////////////////// success = ads_getstring(1, "\nInput registered application name: ", STR1); if (success != RTNORM || !STR1[0]) return; /////////Open Entity////////////////////// if (acdbGetObjectId(objId, ename) != Acad::eOk) { ads_printf("<*ERROR*> retrieving object id.\n"); return; } if (acdbOpenObject(pObj, objId, AcDb::kForRead) != Acad::eOk) { ads_printf("<*ERROR*> opening object for read.\n"); return; } /////////Add X Data//////////////////////// struct resbuf *pRb; pRb = pObj->xData(); if (pRb == NULL) { pObj->close(); acutPrintf("\n<*INFORMATION*> not exist X data.."); return; } pObj->upgradeOpen(); if (STR1[0] == ''*'') { do { STR2[0] = ''\0''; while (pRb) { if (pRb->restype == 1001) { strcpy(STR2, pRb->resval.rstring); break; } pRb = pRb->rbnext; } acutRelRb(pRb); pRb = NULL; if (STR2[0]) { pRb = acutNewRb(1001); acutNewString(STR2, pRb->resval.rstring); pObj->setXData(pRb); pRb->rbnext = NULL; acutRelRb(pRb); } else break; pRb = pObj->xData(); } while (pRb); } else { acutRelRb(pRb); pRb = NULL; pRb = acutNewRb(1001); acutNewString(STR1, pRb->resval.rstring); pObj->setXData(pRb); pRb->rbnext = NULL; acutRelRb(pRb); } pObj->close(); } ===============================================>>
다음검색
현재 게시글 추가 기능 열기

댓글

댓글 리스트
맨위로

카페 검색

카페 검색어 입력폼