void Additional_Class::addXdata( AcDbObjectId entID, CString xdataStr, CString xdataNameStr ) { AcDbEntity * pEnt; struct resbuf * pRb; if(Acad::eOk != acdbOpenAcDbEntity(pEnt, entID, AcDb::kForWrite)) { pEnt->close(); return; } TCHAR * tempTchar = CString2TCHAR(xdataNameStr); //TCHAR strAppName[] = tempTchar; acdbRegApp(tempTchar); TCHAR * typeName = CString2TCHAR(xdataStr); struct resbuf * pTemp; pTemp = pEnt->xData(tempTchar); pRb = acutBuildList(AcDb::kDxfRegAppName, tempTchar, AcDb::kDxfXdAsciiString, typeName, RTNONE); pEnt->setXData(pRb); acutRelRb(pRb); pEnt->close(); return; }
void addXData() { // Get an Entity. ads_name mnEnt; ads_point ptSel; int nRet = acedEntSel(_T("\nSelect an Entity: "), mnEnt, ptSel); if (nRet != RTNORM) return; AcDbObjectId oid; Acad::ErrorStatus retStat; retStat = acdbGetObjectId(oid, mnEnt); if (retStat != Acad::eOk) return; AcDbObject* pObj = NULL; if ((retStat = acdbOpenObject(pObj, oid, AcDb::kForRead)) != Acad::eOk) { return; } // Get new XData. TCHAR appName[132] = {0}; TCHAR resString[200] = {0}; acedGetString(NULL, _T("\nEnter application name: "), appName); acedGetString(NULL, _T("\nEnter string to be added: "), resString); // XData resbuf *pRb = NULL; resbuf *pTemp = NULL; pRb = pObj->xData(appName); if (pRb != NULL) { for (pTemp = pRb; pTemp->rbnext != NULL; pTemp = pTemp->rbnext); } else { acdbRegApp(appName); pRb = acutNewRb(AcDb::kDxfRegAppName); pTemp = pRb; pTemp->resval.rstring = (TCHAR*)malloc((_tcslen(appName) + 1) * sizeof(TCHAR)); _tcscpy(pTemp->resval.rstring, appName); } pTemp->rbnext = acutNewRb(AcDb::kDxfXdAsciiString); pTemp = pTemp->rbnext; pTemp->resval.rstring = (TCHAR*)malloc((_tcslen(resString) + 1) * sizeof(TCHAR)); _tcscpy(pTemp->resval.rstring, resString); // Set XData. pObj->upgradeOpen(); pObj->setXData(pRb); pObj->close(); acutRelRb(pRb); }
void AsdkAcUiDialogSample::OnKillfocusComboRegapps() { CString strFromEdit; m_ctrlRegAppComboBox.GetWindowText(strFromEdit); if (m_ctrlRegAppComboBox.FindString(-1, strFromEdit) == CB_ERR) { if (acdbRegApp(strFromEdit) == RTNORM) m_ctrlRegAppComboBox.AddString(strFromEdit); } }
void addXdata() { AcDbObject* pObj = selectObject(AcDb::kForRead); if (!pObj) { acutPrintf(_T("Error selecting object\n")); return; } // Get the application name and string to be added to // xdata. // TCHAR appName[132], resString[200]; appName[0] = resString[0] = _T('\0'); acedGetString(NULL, _T("Enter application name: "), appName); acedGetString(NULL, _T("Enter string to be added: "), resString); struct resbuf *pRb, *pTemp; pRb = pObj->xData(appName); 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(appName); pRb = acutNewRb(AcDb::kDxfRegAppName); pTemp = pRb; const size_t nSize = _tcslen(appName) + 1; pTemp->resval.rstring = (TCHAR*) malloc(nSize * sizeof(TCHAR)); errno_t err = _tcscpy_s(pTemp->resval.rstring, nSize, appName); assert(err == 0); } // Add user-specified string to the xdata. // pTemp->rbnext = acutNewRb(AcDb::kDxfXdAsciiString); pTemp = pTemp->rbnext; const size_t nSize = _tcslen(resString) + 1; pTemp->resval.rstring = (TCHAR*) malloc(nSize * sizeof(TCHAR)); errno_t err = _tcscpy_s(pTemp->resval.rstring, nSize, resString); assert(err == 0); // 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); }
bool addXData() { Acad::ErrorStatus es, esTmp; CLogger::Print(_T("*Call: addXData()")); //------------ // Require to select an entity. AcDbObject* pObj = selectObject(AcDb::kForRead); if (!pObj) { CLogger::Print(_T("*Exit: addXData() - Khong chon duoc object!")); return false; } //------------ // Require to enter the application name, then require to enter its string value. ACHAR appName[133], resString[133]; appName[0] = resString[0] = L'\0'; acedGetString(NULL, ACRX_T("\nEnter application name: "), appName); acedGetString(NULL, ACRX_T("\nEnter string to be added: "), resString); CLogger::Print(_T("Inform: Found out application name '%s'!"), appName); struct resbuf * pRb; struct resbuf * pTemp; pRb = pObj->xData(appName); if (pRb) { // If the appname is existing! Seek to the tail of resbuf link list. CLogger::Print(_T("Inform: Found out application name '%s' - Seek to the end of resbuf link list."), appName); for (pTemp = pRb; pTemp->rbnext; pTemp = pTemp->rbnext) {} } else { // If the appname is not existing! Register a new application name. CLogger::Print(_T("Inform: The application name %s is not existing, register this application name!"), appName); acdbRegApp(appName); // Then create new resbuf to copy the application name into it. pRb = acutNewRb(AcDb::kDxfRegAppName); pTemp = pRb; pTemp->resval.rstring = (ACHAR*) malloc((lstrlen(appName) + 1) * sizeof(ACHAR)); lstrcpy(pTemp->resval.rstring, appName); } //------------ // Create new resbuf at the tail of the link list, then copy the value string into it. pTemp->rbnext = acutNewRb(AcDb::kDxfXdAsciiString); pTemp = pTemp->rbnext; pTemp->resval.rstring = (ACHAR*) malloc((lstrlen(resString) + 1) * sizeof(ACHAR)); lstrcpy(pTemp->resval.rstring, resString); CLogger::Print(_T("Inform: Upgrade object opening!")); if (Acad::eOk != (es = pObj->upgradeOpen())) { CLogger::Print(_T("*Exit: addXData() - Fail to upgrade opening object!")); pObj->close(); acutRelRb(pRb); return false; } //------------ // Set object's xData. pObj->setXData(pRb); pObj->close(); acutRelRb(pRb); // remember to release resbuf after using CLogger::Print(_T("*Exit: addXData()!")); return true; }