ObjectARX
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Transaction Method Vs open/close Method

10 REPLIES 10
SOLVED
Reply
Message 1 of 11
Zanzabar
1417 Views, 10 Replies

Transaction Method Vs open/close Method

I am new to ObjectArx. I have been working through the documentation. I have used some of the code with the open and closed methods of creating/edit entities in Autocad. The problem that I was having is with Transactions. I can't find any good code of creating an object with a transaction and submitting it to the database.

 

I had read about transactions and the inefficiencies of them. For what I am going to be doing which is just creating object and submitting them to the database I figured that Transactions would not be any less efficient and since it is a module it should be able to take care of and handle issues that I don't care to really program for. That being said is my assumptions correct? Should I keep trying to figure otu transactions or should I just deal with the open close methods.

 

Any code posts of transaction handling would be awesome since I think I am missing something.I had a program that compiled and would run but would not submit anythign to the database ( best of my knowledge ).

 

Talk with you soon and thank you for any input.

 

--Zac

10 REPLIES 10
Message 2 of 11
owenwengerd
in reply to: Zanzabar

You're more likely to get help here if you include the code and describe where and how it is failing.

--
Owen Wengerd
ManuSoft
Message 3 of 11

ObjectARX for AutoCAD 2013: Developer Guide > Advanced Topics > Advanced Topics > Transaction Management > Example of Nested Transactions

Відповідь корисна? Клікніть на "ВПОДОБАЙКУ" цім повідомленням! | 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
Expert Elite Member

Message 4 of 11
Zanzabar
in reply to: owenwengerd

I will have to recreate the code but I will try to post something within the next day or so. I deleted it because I was just testing things out. I had not seen any real transaction examples so I was fumbling through what I could.

Message 5 of 11

Alex thanks for the input. In the code I noticed that the newly created object had a postToDb() function which I couldn't find documented anywhere.

Message 6 of 11

//-------------------------------------------------------------
// Adding new created circle to current space (Model or Paper)  
// with help of transaction
//-------------------------------------------------------------
static void MyGroupMyTransaction () {
  AcDbDatabase *pCurDb = acdbCurDwg();
  AcGePoint3d pCenter;
  double radius;
  if (acedGetPoint(NULL,_T("\nCenter point: "),asDblArray(pCenter)) == RTNORM) {
    if (acedGetDist(asDblArray(pCenter),_T("\nRadius: "),&radius) == RTNORM) {
      AcGeMatrix3d matUCS;  acedGetCurrentUCS(matUCS); pCenter.transformBy(matUCS);
      AcGeVector3d norm = AcGeVector3d::kZAxis; norm.transformBy(matUCS);
      AcDbCircle *pCircle = new AcDbCircle(pCenter,norm,radius);
      pCircle->setDatabaseDefaults(pCurDb);
      AcTransaction *tr = acTransactionManagerPtr()->startTransaction();
      AcDbBlockTableRecord *pBTR = NULL;
      if (tr->getObject((AcDbObject *&)pBTR,pCurDb->currentSpaceId(),AcDb::kForWrite) == Acad::eOk && pBTR != NULL) {
        // Adding circle to current space BlockTableRecord  
        pBTR->appendAcDbEntity(pCircle);
        // Adding circle to transaction
        acTransactionManagerPtr()->addNewlyCreatedDBRObject(pCircle,true);
      }
      acTransactionManagerPtr()->endTransaction();
    }
  }
}

Function postToDb can be found in file \samples\entity\polysamp\utilui.cpp within ObjectARX SDK or here.

Відповідь корисна? Клікніть на "ВПОДОБАЙКУ" цім повідомленням! | 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
Expert Elite Member

Message 7 of 11
Zanzabar
in reply to: Zanzabar

Alex thank you that is just what I was looking for. I will work through this code and see what I can figure out.

 

For the most part though would you recommend a new objectarx programmer and novice C++ programmer to stick with transactions or would you say that using the open close method would be better?

Message 8 of 11

I prefer the mechanism open / close. But with a important addition - the use of smart pointers, such as AcDbObjectPointer, AcDbEntityPointer, AcDbBlockTableRecordPointer, etc. defined in dbobjptr.h header file.

Example

Відповідь корисна? Клікніть на "ВПОДОБАЙКУ" цім повідомленням! | 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
Expert Elite Member

Message 9 of 11

Alex thanks for your input. I had seen some information here (in the comments) about smart pointers but I wasn't sure exactly what they are or how they work. I will have to look through the example you had posted and get a better grasp of how they work.

 

I also thought it was interesting how you used this norm.transformBy(matUCS); to take in account the WCS vs UCS.

 

Message 10 of 11
owenwengerd
in reply to: Zanzabar

I recommend to avoid smart pointers until you understand the mechanism of opening and closing objects. Once you understand the mechanism, and once you understand how smart pointers work, then you should use them as Alexander said. Also, I recommend to avoid transactions until you have mastered open/close. In any case, use transactions only where needed or properly justified.

--
Owen Wengerd
ManuSoft
Message 11 of 11
Zanzabar
in reply to: owenwengerd

Owen,

Thank you for your input. I will go back to the mechanisms and figure out everything on the simplest form before doing anything with smart pointers or transactions.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost