Author Topic: Transaction Manager in C++ for Bricscad Brx  (Read 4986 times)

0 Members and 1 Guest are viewing this topic.

Helios

  • Guest
Transaction Manager in C++ for Bricscad Brx
« on: November 22, 2008, 05:31:21 AM »
Hello all,

I've taken my first slippery steps in C++ BRX for Bricscad this week and found myself struggling with the transaction manager.
After a kickstart with http://arxdummies.blogspot.com/ and the excelent Bricscad porting instructions I've created an ARX file which reads polylines from a file and puts them in to a drawing.
So far so good.
Instead of opening/closing all objects myself (with obvious desastrous pitfalls) I'm trying to use the Transaction manager but cannot find any clear example on how to set it up.

Which header files do I need to include?
I can declare an acbdTransactionmanager object but the intellisense does not show any methods after the '->'  like in cdbTransactionManager->startTransaction();

Can anyone give me a small example on #includes, declarations  and some sample code?
Or if any usefull site (apart from TheSwamp ofcourse  :kewl: ) is available I'm happy to go after it myself.

Btw, comming from VB6-COM, the ARX speed is quite refreshing!!

T.I.A.


Spike Wilbury

  • Guest
Re: Transaction Manager in C++ for Bricscad Brx
« Reply #1 on: November 22, 2008, 11:52:22 AM »
Hello all,

I've taken my first slippery steps in C++ BRX for Bricscad this week and found myself struggling with the transaction manager.
After a kickstart with http://arxdummies.blogspot.com/ and the excelent Bricscad porting instructions I've created an ARX file which reads polylines from a file and puts them in to a drawing.
So far so good.
Instead of opening/closing all objects myself (with obvious desastrous pitfalls) I'm trying to use the Transaction manager but cannot find any clear example on how to set it up.

Which header files do I need to include?
I can declare an acbdTransactionmanager object but the intellisense does not show any methods after the '->'  like in cdbTransactionManager->startTransaction();

Can anyone give me a small example on #includes, declarations  and some sample code?
Or if any usefull site (apart from TheSwamp ofcourse  :kewl: ) is available I'm happy to go after it myself.

Btw, comming from VB6-COM, the ARX speed is quite refreshing!!

T.I.A.



Are you trying to write an ObjectARX command? - and that can run under the intellicad core? - I'm neophyte in the intellicad stuff.

If you want to write an ObjectARX application, it will much easier to install the ARX Wizard, and use it to create for you an skeleton in Visual Studio, that way all the necessary baggage will be included.

Now, to know the headers locations, you can highlight the name of the function, right-click and click on 'Go To Definition', this will take you the header file. The other way is to open the help and type (in this case the macro name) under Search....

Code: [Select]
acdbTransactionManager->startTransaction();
for (UINT i = 0; i < length; i++)
{
acedSSName(sset, i, ename);
acdbGetObjectId(oid, ename);
AcDbEntity* pEnt = NULL;
if (acdbTransactionManager->getObject((AcDbObject*&)pEnt, oid, AcDb::kForWrite) == Acad::eOk)
pEnt->erase();
}
acdbTransactionManager->endTransaction();

dbtrans.h
« Last Edit: November 22, 2008, 12:10:25 PM by Wilbury »

It's Alive!

  • BricsCAD
  • Needs a day job
  • Posts: 7026
  • AKA Daniel
Re: Transaction Manager in C++ for Bricscad Brx
« Reply #2 on: November 22, 2008, 12:14:22 PM »
Wow cool, Another BRXer

I don’t use the transaction manager much, I like to use smart pointers, so I provided an example of each.


Code: [Select]
  //++-- Transcation Example
  static void BRXDoit1(void)
  {
    Acad::ErrorStatus es;
    long ssLength = 0;

    ads_name sel;
    AcDbObject *pObj;
    AcDbObjectIdArray ids;

    if(acedSSGet(NULL, NULL, NULL, NULL, sel) != RTNORM)
    {
      return;
    }

    if(acedSSLength(sel, &ssLength) != RTNORM || ssLength == 0)
    {
      acedSSFree(sel);
      return;
    }

    if(acedGetCurrentSelectionSet(ids) != Acad::eOk)
    {
      acedSSFree(sel);
      return;
    }

    AcTransaction *pTransaction = actrTransactionManager->startTransaction();

    for(int i = 0 ; i < ids.length(); i++)
    {
      if(pTransaction->getObject(pObj,ids[i],AcDb::kForRead) == Acad::eOk)
      {
        AcDbEntity *pEnt = (AcDbEntity*) pObj;
        if(pEnt)
        {
          pEnt->upgradeOpen();
          pEnt->setLayer(_T("0"));
        }
      }
    }

    actrTransactionManager->endTransaction();
    acedSSFree(sel);
  }

  //++-- Smart pointer Example
  static void BRXDoit2(void)
  {
    Acad::ErrorStatus es;
    long ssLength = 0;

    ads_name sel;
    AcDbObjectIdArray ids;

    if(acedSSGet(NULL, NULL, NULL, NULL, sel) != RTNORM)
    {
      return;
    }

    if(acedSSLength(sel, &ssLength) != RTNORM || ssLength == 0)
    {
      acedSSFree(sel);
      return;
    }

    if(acedGetCurrentSelectionSet(ids) != Acad::eOk)
    {
      acedSSFree(sel);
      return;
    }

    for(int i = 0 ; i < ids.length(); i++)
    {
      AcDbEntityPointer smartPointer(ids[i],AcDb::kForRead);
      if(smartPointer.openStatus() == Acad::eOk)
      {
        smartPointer->upgradeOpen();
        smartPointer->setLayer(_T("0"));
      }
    }

    acedSSFree(sel);
  }
« Last Edit: November 22, 2008, 12:31:28 PM by Daniel »

It's Alive!

  • BricsCAD
  • Needs a day job
  • Posts: 7026
  • AKA Daniel
Re: Transaction Manager in C++ for Bricscad Brx
« Reply #3 on: November 22, 2008, 12:21:53 PM »
FYI, In Bricscad 9.2.2 beta, there is a sample BRX solution. Have a good read though it’s StdAfx.h and the project settings, to get an idea of how to setup the headers

Spike Wilbury

  • Guest
Re: Transaction Manager in C++ for Bricscad Brx
« Reply #4 on: November 22, 2008, 12:39:32 PM »
Hi Daniel,

Have you implemented the use of create(); on your smart pointers calls? - and if you do, in calls like this too:

Code: [Select]
AcDbDatabase* pDb = acdbHostApplicationServices()->workingDatabase();
AcDbBlockTableRecordPointer pBTR(pDb->currentSpaceId(), AcDb::kForWrite); //<<<<<

pBTR.create(); //<<<<<<<

I'm not, just on this ones:

Code: [Select]
AcDbObjectPointer<AcDbLine> pLine;
pLine.create();
...

as your topic about smart pointers.... BTW

It's Alive!

  • BricsCAD
  • Needs a day job
  • Posts: 7026
  • AKA Daniel
Re: Transaction Manager in C++ for Bricscad Brx
« Reply #5 on: November 22, 2008, 01:15:20 PM »
Right, I would not use ::create() on the first example as the object already exists, but would on creating ‘new’ objects I.e


Code: [Select]
  typedef AcDbObjectPointer<AcDbLine> AcDbLinePointer;
  static void CRPDBRXTransDoit3(void)
  {
    AcDbDatabase* pDb = acdbHostApplicationServices()->workingDatabase();
    AcDbBlockTableRecordPointer pBTR(pDb->currentSpaceId(), AcDb::kForWrite); //<<<<<
    AcDbLinePointer pLine;

    if(pLine.create() == Acad::eOk)
    {
      pLine->setStartPoint(AcGePoint3d(0,0,0));
      pLine->setEndPoint(AcGePoint3d(100,100,0));
      pBTR->appendAcDbEntity(pLine);
    }
  }

Spike Wilbury

  • Guest
Re: Transaction Manager in C++ for Bricscad Brx
« Reply #6 on: November 22, 2008, 01:28:47 PM »
Yep....

Wonder why it is available.... later today will do some tests.


Thanks!

It's Alive!

  • BricsCAD
  • Needs a day job
  • Posts: 7026
  • AKA Daniel
Re: Transaction Manager in C++ for Bricscad Brx
« Reply #7 on: November 22, 2008, 01:47:32 PM »
I Think, the smart point in AutoCAD 09 is more like a shared pointer instead of just a new/delete || Open/Close mechanism like previous versions

Helios

  • Guest
Re: Transaction Manager in C++ for Bricscad Brx
« Reply #8 on: November 23, 2008, 08:50:31 AM »
Thanks for your posts guys.

I've downloaded the V9.2.2 SDK and have a go with that.

Daniel, what's the advantage of 'smartpointers' over the TransactionManager?

B.t.w, I've had a play with your ARX.NET wrapped libraries in BricsCad. Couldn't get the V9 versions to work but V8 was ok.
Got comparable speed with VBA, your stuff was approx. 20% faster than VBA.

Cheers.

It's Alive!

  • BricsCAD
  • Needs a day job
  • Posts: 7026
  • AKA Daniel
Re: Transaction Manager in C++ for Bricscad Brx
« Reply #9 on: November 23, 2008, 12:54:30 PM »
I guess it’s just a personal preference, In general I try to use smart pointers where I can, whether it’s AcDbObjectPointer, std::auto_ptr or some of boost’s smart pointers.

I wonder why my drxnet didn’t work for you, It works on my machine with V9.2.2. are you getting any error messages? I admit I have not been putting much effort in this due to lack of interest.

Helios

  • Guest
Re: Transaction Manager in C++ for Bricscad Brx
« Reply #10 on: December 18, 2008, 04:11:01 PM »
Hi Daniel,

thanks for (smart)pointing me in the smartpointer direction.
Things are starting to work out.
I've abandoned the TransactionManager approach.

With respect to .NET wrappers on ARX/BRX routines:
If I was to wrap an AddText ARX method with a .NET skin, does that mean I jump from managed  to unmanaged each time I add a textlabel to a drawing?
Is that going to  put a penalty on performance?


Helios

It's Alive!

  • BricsCAD
  • Needs a day job
  • Posts: 7026
  • AKA Daniel
Re: Transaction Manager in C++ for Bricscad Brx
« Reply #11 on: December 18, 2008, 04:52:54 PM »
..
With respect to .NET wrappers on ARX/BRX routines:
If I was to wrap an AddText ARX method with a .NET skin, does that mean I jump from managed  to unmanaged each time I add a textlabel to a drawing?
Is that going to  put a penalty on performance?


Helios



Yes it will, but not by too much, It  only takes a few clock cycles to p/invoke and marshal types over.
 For the projects I am working on now, I am using mixed managed/unmanaged code. Basically everything
 is unmanaged except for the forms and a few type converters. So far this seems to be working well.

MickD

  • Gator
  • Posts: 3411
  • (x-in)->[process]->(y-out)
Re: Transaction Manager in C++ for Bricscad Brx
« Reply #12 on: December 18, 2008, 05:22:45 PM »
I found that passing simple types such as entity ObjectID's or strings, doubles etc was very convenient and straight forward. This way your unmanaged code can open and deal with the 'type' in unmanaged code and you are only dealing with a few types to convert.
Forth is like the Tao: it is a Way, and is realized when followed.
Its fragility is its strength; its simplicity is its direction - Michael Ham

Lao Tzu: “To attain knowledge, add things
every day; to obtain wisdom, remove things every day.”