Author Topic: Adding XData  (Read 5484 times)

0 Members and 1 Guest are viewing this topic.

Helios

  • Guest
Adding XData
« on: September 14, 2011, 08:20:42 AM »
Hello all,

I'm trying to attach XData records to entities through BRX and I'm not doing too well.
Apart from all the different string flavours (CString, ACHAR*, char buff[]  :-o) it's a bit of a struggle to get info on how to create a result buffer to pass to the setXData() method.

I'm passing a count and two CStringArrays (keys & values) to create a (private member) m_prbX (of type struct resbuf*).

Code: [Select]
Acad::ErrorStatus CadDrawing::setXRecords(int count, const CStringArray& keys, const CStringArray& values)
 {
   
   acdbRegApp(_T("myApp");  //<< this returns RTNORM so seems ok, I know I should to this only once.
     
   struct resbuf *newRB;
   
   newRB = acutNewRb(1001);
   acutNewString(_T("myApp"), newRB->resval.rstring); //<<application name record
   
   m_prbX = newRb;

   for (int i = 0; i <cnt; i++)
   {
     m_prbX = m_prbX->rbnext = acutNewRb(_ttoi(LPCTSTR(keys.GetAt(i))));
     m_prbX ->resval.rstring = CStringW(values.GetAt(i)).GetBuffer(0);
   }
 
   m_prbX = m_prbX->rbnext;
   m_prbX->rbnext = NULL;

   acutRelRb(newRB);
   
    m_XDataPending = true;

    return Acad::eOk;
 }

The keys I pass are stored in a CStringArray >> is my conversion to INT correct? _ttoi(LPCTSTR(keys.GetAt(i)));
Or is there an other way?
Passing the value-string also seems a bridge too far to me.  >> CStringW(values.GetAt(i)).GetBuffer(0)

Next I try to set the XData:

Code: [Select]
Acad::ErrorStatus CadDrawing::setEntityXRecords()
  {
    Acad::ErrorStatus es = Acad::eOk;

    if (m_XDataPending)   //is some Xdata set in m_prxB?
    {
      AcDbObject* pObj;
      AcDbObjectId entID; 

      ads_name ename;
      acdbEntLast(ename);
      acdbGetObjectId(entID, ename);
     
      if ((es = acdbOpenObject(pObj, entID, AcDb::kForWrite)) == Acad::eOk)  //open object for write succeeds
      {
         if ((es = pObj->setXData(m_prbX)) == Acad::eOk)   //..but set Xdata fails with error code 126
        {
           //success..
         }
         es = pObj->close();                             //close onbject
       }
   
      acutRelRb(m_prbX);                                  //release the object's memory
   
       m_XDataPending = false;
    }
   
    return es;
  }


The SetXData returns 126 (eRegappIdNotFound) << any clues?


Anybody who can shed some light on this?

TIA,
Arno van Eeuwen


Draftek

  • Water Moccasin
  • Posts: 1501
Re: Adding XData
« Reply #1 on: September 14, 2011, 09:19:16 AM »
It doesn't look like your checking to see if the xdata app name has been registered in the app dictionary

see 'acdbRegApp()' in the help document.
Soli Deo Gloria

It's Alive!

  • BricsCAD
  • Needs a day job
  • Posts: 6963
  • AKA Daniel
Re: Adding XData
« Reply #2 on: September 14, 2011, 09:47:30 AM »
this works
Code: [Select]
static bool GetEnt(AcDbObjectId &id, AcGePoint3d &pnt)
    {
        ads_name name = {0L, 0L};
        bool flag = (acedEntSel(L"\nGet Entity",name,asDblArray(pnt)) == RTNORM);
        id = (AcDbStub*)name[0];
        return flag;
    }

    static void CStringArrayToResbulList(ResbufList &rList,
                                         const INT_PTR count,
                                         const CStringArray& keys,
                                         const CStringArray& values)
    {
        if(count <= keys.GetCount()  && count <= values.GetCount())
        {
            for(INT_PTR idx = 0; idx < count; idx++)
                rList.push_back(acutBuildList(_ttoi(keys[idx]),values[idx],NULL));
        }
    }

    static void fillArrays(CStringArray& keys, CStringArray& values)
    {
        for(INT_PTR idx = 0; idx < 10; idx++)
        {
            keys.Add(L"1000");
            values.Add(L"AcDb::kDxfXdAsciiString");
        }
    }

    static void BrxXdata_doit(void)
    {
        if(acdbRegApp(L"MyCoolApp") != RTNORM)
            acdbFail(L"BOMBED");
        AcGePoint3d pnt;
        AcDbObjectId id;
        ResbufList rList;
        CStringArray keys,values;
        fillArrays(keys, values);
        if(!GetEnt(id, pnt))
            return;
        AcDbEntityPointer pEnt(id,AcDb::kForWrite);
        if(pEnt.openStatus() != Acad::eOk)
            return;
        rList.push_back(acutBuildList(AcDb::kDxfRegAppName,L"MyCoolApp",NULL));
        CStringArrayToResbulList(rList, keys.GetCount(), keys,values);
        acutPrintf(_T("\n%s"),acadErrorStatusText(pEnt->setXData(rList)));
    }
} ;

you can get the resbuflist class here if you want to use it
http://www.theswamp.org/index.php?topic=32574.0

It's Alive!

  • BricsCAD
  • Needs a day job
  • Posts: 6963
  • AKA Daniel
Re: Adding XData
« Reply #3 on: September 14, 2011, 09:53:34 AM »

also have a look at _tcsdup
Code: [Select]
        for (int i = 0; i <cnt; i++)
        {
            m_prbX = m_prbX->rbnext = acutNewRb(_ttoi(LPCTSTR(keys.GetAt(i))));
            m_prbX ->resval.rstring = _tcsdup(values.GetAt(i));
        }

owenwengerd

  • Bull Frog
  • Posts: 439
Re: Adding XData
« Reply #4 on: September 14, 2011, 10:56:49 AM »
When you call acutRelRb(newRB), you are freeing the memory pointed to my m_prbX.

Helios

  • Guest
Re: Adding XData
« Reply #5 on: September 15, 2011, 09:27:30 AM »
Thanks for your swift responses guys.
ResbufList looks very usefull and promising, I've downloaded it and implemented it in the code.

However,
as soon as I try to build the code I get an error 1189

Error   6   fatal error C1189: #error :  You have included some C++/C library header files with _DEBUG defined and some with _DEBUG not defined. This will not work correctly. Please have _DEBUG set or clear consistently.   c:\program files\microsoft visual studio 8\vc\include\use_ansi.h   49   


In Bricscad Knowledge base this error is also mentioned, and a way to alter stdafx.h is suggested. But I had done that already in my existing project.
Adding ResbufList.cpp to my project causes the error to pop up.

So now searching for a way to fix this, as C++ still is not my cup of tea, specially with this kind of errors.

Will keep you posted.






It's Alive!

  • BricsCAD
  • Needs a day job
  • Posts: 6963
  • AKA Daniel
Re: Adding XData
« Reply #6 on: September 15, 2011, 09:47:17 AM »
do you have _DEBUG set in your project?
I don't think you can do this, as BRX links with the release version of MFC...

Helios

  • Guest
Re: Adding XData
« Reply #7 on: September 15, 2011, 09:59:26 AM »
Yes Daniel,

there is _DEBUG in a few places, this used to be no problem earlier.
The Bricscad Knowledge Base suggests to build a Release version to ommit the error  but that does not help.

Would you suggest to take _DEBUG out all the way?

It's Alive!

  • BricsCAD
  • Needs a day job
  • Posts: 6963
  • AKA Daniel
Re: Adding XData
« Reply #8 on: September 15, 2011, 10:07:46 AM »
yep,
maybe you can define your own, I.e MY_DEBUG for your debug code.

It's Alive!

  • BricsCAD
  • Needs a day job
  • Posts: 6963
  • AKA Daniel
Re: Adding XData
« Reply #9 on: September 15, 2011, 10:46:01 AM »
BTY Are you going to Belgium this year?

Helios

  • Guest
Re: Adding XData
« Reply #10 on: September 15, 2011, 10:53:21 AM »
Got my suitcase packed and waiting already... :laugh:

It's Alive!

  • BricsCAD
  • Needs a day job
  • Posts: 6963
  • AKA Daniel
Re: Adding XData
« Reply #11 on: September 15, 2011, 10:59:26 AM »
I've have my plane tickets, but I haven't booked a room yet, maybe I should just stay at the closest pub  :laugh:
I'm bringing empty suitcases, so I can bring back chocolate

Helios

  • Guest
Re: Adding XData
« Reply #12 on: September 19, 2011, 10:32:40 AM »
Daniel, guess what?

It's working!  :lmao:
With some help of our inhouse C++ guru the BRX builds again and I'm able to attach XData to my lines.
It all needed a few #if defined statements; way over my head.
Your ResbufList class has proven to be very usefull.

That's at least one more reason to go to the pub!

(Now can't wait to port the whole thing to the .NET API so I can let go the C++ part, eventhough it's doing a good job)

It's Alive!

  • BricsCAD
  • Needs a day job
  • Posts: 6963
  • AKA Daniel
Re: Adding XData
« Reply #13 on: September 20, 2011, 08:12:46 AM »
Awsome! any excuse for a beer  :laugh:

see you soon!