Hi,
I need to save and retrieve some variables from a dwg file.(int, float,strings)
I know there are lots of way to store data in autocad and the main way are xdata and dictionaries.
To attach my data to the autocad entities I use dictionaries, but now I need to store data at dwg level for data related to the drawing.
I think I should create a fake autocad entity with a dictionary attacched to it and put that entity in the drawing in a programmatic way, but the user may remove it, I don't know.
I'm looking for an easy way to store persistent data in the dwg.
Thank you for your time.
Have a good day!
Solved! Go to Solution.
Solved by Alexander.Rivilis. Go to Solution.
What about XRecord and Named Object Dictionary? Named Object Dictionary allow to have data dwg level:
Відповідь корисна? Клікніть на "ВПОДОБАЙКУ" цім повідомленням! | Do you find the posts helpful? "LIKE" these posts!
Находите сообщения полезными? Поставьте "НРАВИТСЯ" этим сообщениям!
На ваше запитання відповіли? Натисніть кнопку "ПРИЙНЯТИ РІШЕННЯ" | Have your question been answered successfully? Click "ACCEPT SOLUTION" button.
На ваш вопрос успешно ответили? Нажмите кнопку "УТВЕРДИТЬ РЕШЕНИЕ"
Alexander Rivilis / Александр Ривилис / Олександр Рівіліс
Programmer & Teacher & Helper / Программист - Учитель - Помощник / Програміст - вчитель - помічник
Facebook | Twitter | LinkedIn
Hi,
it could be good!
I have just to persist the scale factor! as your example!
Where can I find a piece of code to save and retrieve those data?
Thanks for your help!
Massimo
ObjectARX SDK: \samples\database\xrecord_dg
createXrecord() and listXrecord() functions
Відповідь корисна? Клікніть на "ВПОДОБАЙКУ" цім повідомленням! | Do you find the posts helpful? "LIKE" these posts!
Находите сообщения полезными? Поставьте "НРАВИТСЯ" этим сообщениям!
На ваше запитання відповіли? Натисніть кнопку "ПРИЙНЯТИ РІШЕННЯ" | Have your question been answered successfully? Click "ACCEPT SOLUTION" button.
На ваш вопрос успешно ответили? Нажмите кнопку "УТВЕРДИТЬ РЕШЕНИЕ"
Alexander Rivilis / Александр Ривилис / Олександр Рівіліс
Programmer & Teacher & Helper / Программист - Учитель - Помощник / Програміст - вчитель - помічник
Facebook | Twitter | LinkedIn
Its exactly the same as working with Dictionaries and XRecords attached to drawing entities, except you are adding them to the Named Object Dictionary. I'd recommend encapulating your content in a dedicated dictionary to make management easier.
You can use this code as a example:
//----------------------------------------------------------------------------- //----- acrxEntryPoint.cpp //----------------------------------------------------------------------------- #include "StdAfx.h" #include "resource.h" //----------------------------------------------------------------------------- #define szRDS _RXST("") //----------------------------------------------------------------------------- //----- ObjectARX EntryPoint class CDWGVariablesApp : public AcRxArxApp { public: CDWGVariablesApp () : AcRxArxApp () {} virtual AcRx::AppRetCode On_kInitAppMsg (void *pkt) { AcRx::AppRetCode retCode = AcRxArxApp::On_kInitAppMsg (pkt) ; return (retCode) ; } virtual AcRx::AppRetCode On_kUnloadAppMsg (void *pkt) { AcRx::AppRetCode retCode = AcRxArxApp::On_kUnloadAppMsg (pkt) ; return (retCode) ; } virtual void RegisterServerComponents () { } static AcDbObjectId GetOrCreateVariableXrecordId(ACHAR *appName, ACHAR *varName, AcDbDatabase *db = NULL) { AcDbObjectId idXrec, id; if (!db) db = acdbCurDwg(); AcDbObjectId idNOD = db->namedObjectsDictionaryId(); AcDbObjectPointer<AcDbDictionary> pNOD(idNOD,AcDb::kForRead); if (pNOD.openStatus() == Acad::eOk) { AcDbObjectPointer<AcDbDictionary> pDict; AcDbObjectPointer<AcDbXrecord> pXrec; if (pNOD->has(appName)) { if (pNOD->getAt(appName, id) == Acad::eOk) { if (pDict.open(id,AcDb::kForWrite) == Acad::eOk) { if (pDict->has(varName)) { pDict->getAt(varName, idXrec); } else { pXrec.create(); pDict->setAt(varName, pXrec, idXrec); } } } } else { pDict.create(); if (pNOD->upgradeOpen() == Acad::eOk && pNOD->setAt(appName, pDict, id) == Acad::eOk) { pXrec.create(); pDict->setAt(varName, pXrec, idXrec); } } } return idXrec; } static Acad::ErrorStatus SetVariable(ACHAR *appName, ACHAR *varName, int n, AcDbDatabase *db = NULL) { AcDbObjectId idXrecord = GetOrCreateVariableXrecordId(appName, varName, db); if (idXrecord.isNull()) return Acad::eInvalidObjectId; AcDbObjectPointer<AcDbXrecord> pXrec(idXrecord,AcDb::kForWrite); if (pXrec.openStatus() == Acad::eOk) { resbuf *rb = acutBuildList(AcDb::kDxfInt16, n, 0); Acad::ErrorStatus es = pXrec->setFromRbChain(*rb); acutRelRb(rb); return es; } return Acad::eNullHandle; } static Acad::ErrorStatus SetVariable(ACHAR *appName, ACHAR *varName, double d, AcDbDatabase *db = NULL) { AcDbObjectId idXrecord = GetOrCreateVariableXrecordId(appName, varName, db); if (idXrecord.isNull()) return Acad::eInvalidObjectId; AcDbObjectPointer<AcDbXrecord> pXrec(idXrecord,AcDb::kForWrite); if (pXrec.openStatus() == Acad::eOk) { resbuf *rb = acutBuildList(AcDb::kDxfReal, d, 0); Acad::ErrorStatus es = pXrec->setFromRbChain(*rb); acutRelRb(rb); return es; } return Acad::eNullHandle; } static Acad::ErrorStatus SetVariable(ACHAR *appName, ACHAR *varName, ACHAR *str, AcDbDatabase *db = NULL) { AcDbObjectId idXrecord = GetOrCreateVariableXrecordId(appName, varName, db); if (idXrecord.isNull()) return Acad::eInvalidObjectId; AcDbObjectPointer<AcDbXrecord> pXrec(idXrecord,AcDb::kForWrite); if (pXrec.openStatus() == Acad::eOk) { resbuf *rb = acutBuildList(AcDb::kDxfText, str, 0); Acad::ErrorStatus es = pXrec->setFromRbChain(*rb); acutRelRb(rb); return es; } return Acad::eNullHandle; } static resbuf *GetVariable(ACHAR *appName, ACHAR *varName, AcDbDatabase *db = NULL) { resbuf *rb = NULL; AcDbObjectId idXrecord = GetOrCreateVariableXrecordId(appName, varName, db); if (idXrecord.isNull()) return rb; AcDbObjectPointer<AcDbXrecord> pXrec(idXrecord,AcDb::kForWrite); if (pXrec.openStatus() == Acad::eOk) { pXrec->rbChain(&rb); } return rb; } ////////////////////////////////////////////////////////////////////////// // Lisp Function: // (setdwgvariable "appname" "varname" varvalue) // For example: // (setdwgvariable "MassimoVars" "ScaleFactor" 1.0) ////////////////////////////////////////////////////////////////////////// static int ads_setdwgvariable () { ACHAR *appName = NULL, *varName = NULL; resbuf *args = acedGetArgs (), *rb = args; if (rb && rb->restype == RTSTR) { appName = rb->resval.rstring; rb = rb->rbnext; } else { acutPrintf(_T("\nsetdwgvariable: invalid first argument 'appName'")); return RSRSLT ; } if (rb && rb->restype == RTSTR) { varName = rb->resval.rstring; rb = rb->rbnext; } else { acutPrintf(_T("\nsetdwgvariable: invalid second argument 'varName'")); return RSRSLT ; } if (rb) { switch (rb->restype) { case RTSHORT: SetVariable(appName,varName,rb->resval.rint); break; case RTREAL: SetVariable(appName,varName,rb->resval.rreal); break; case RTSTR: SetVariable(appName,varName,rb->resval.rstring); break; } } else { acutPrintf(_T("\nsetdwgvariable: invalid third argument 'varValue'")); return RSRSLT ; } return RSRSLT ; } ////////////////////////////////////////////////////////////////////////// // Lisp Function: // (getdwgvariable "appname" "varname") // For example: // (getdwgvariable "MassimoVars" "ScaleFactor") ////////////////////////////////////////////////////////////////////////// static int ads_getdwgvariable () { ACHAR *appName = NULL, *varName = NULL; resbuf *args = acedGetArgs (), *rb = args; if (rb && rb->restype == RTSTR) { appName = rb->resval.rstring; rb = rb->rbnext; } else { acutPrintf(_T("\nsetdwgvariable: invalid first argument 'appName'")); return RSRSLT ; } if (rb && rb->restype == RTSTR) { varName = rb->resval.rstring; rb = rb->rbnext; } else { acutPrintf(_T("\nsetdwgvariable: invalid second argument 'varName'")); return RSRSLT ; } rb = GetVariable(appName,varName); if (rb) { switch (rb->restype) { case AcDb::kDxfInt16: acedRetInt(rb->resval.rint); break; case AcDb::kDxfReal: acedRetReal(rb->resval.rreal); break; case AcDb::kDxfText: acedRetStr(rb->resval.rstring); break; } } else { acutPrintf(_T("\nsetdwgvariable: no saved variable with name '%s'"), varName); return RSRSLT ; } return RSRSLT ; } } ; //----------------------------------------------------------------------------- IMPLEMENT_ARX_ENTRYPOINT(CDWGVariablesApp) ACED_ADSSYMBOL_ENTRY_AUTO(CDWGVariablesApp, setdwgvariable, true) ACED_ADSSYMBOL_ENTRY_AUTO(CDWGVariablesApp, getdwgvariable, true)
Results:
Відповідь корисна? Клікніть на "ВПОДОБАЙКУ" цім повідомленням! | Do you find the posts helpful? "LIKE" these posts!
Находите сообщения полезными? Поставьте "НРАВИТСЯ" этим сообщениям!
На ваше запитання відповіли? Натисніть кнопку "ПРИЙНЯТИ РІШЕННЯ" | Have your question been answered successfully? Click "ACCEPT SOLUTION" button.
На ваш вопрос успешно ответили? Нажмите кнопку "УТВЕРДИТЬ РЕШЕНИЕ"
Alexander Rivilis / Александр Ривилис / Олександр Рівіліс
Programmer & Teacher & Helper / Программист - Учитель - Помощник / Програміст - вчитель - помічник
Facebook | Twitter | LinkedIn
I am curious as to how this dialog with the symbol tables, dictionaries, and database tabs was generated? Is is an AutoCAD command?
Thanks, Mark
That is the ArxDbg ObjectARX SDK sample.
mjwelch wrote:
I am curious as to how this dialog with the symbol tables, dictionaries, and database tabs was generated? Is is an AutoCAD command?
Thanks, Mark
is it Possible to save some XML file as string......
I try creating APP and Variable and try to save a small string...
but I go the below AutoCAD message..
.
Please help me to get this....