newer 发表于 2021-1-16 20:44:49

利用ARX从AUTOLISP创建匿名组

Create an anonymous group from Visual LISP with help from ARX



问题:
DevNote TS36234 describes how to create an anonymous group from VBA, with the
help of an ARX application that was supplied.Is it possible to call this ARX
application directly from Lisp?Is it also possible to return the Object ID
of the newly-created group to the Lisp function, as well?

解答:

The attached ARX project is slightly different from the one available in DevNote
(TS36234), in this example acedDefun() is used to define the command
acdbAddAnonGrpRet2Lsp() as an external Lisp function.It is further modified
to return a list, containing the new group's ObjectID, to the external Lisp
function, as well.


// ObjectARX defined commands


#include "StdAfx.h"
#include "StdArx.h"


// This is command 'ACDBADDANONGRPRET2LSP'
int acdbAddAnonGrpRet2Lsp()
{
   // TODO: Implement the command
   resbuf *pArg =acedGetArgs () ;


   struct resbuf *startRb = NULL;
   AcDbGroup *pGroup = new AcDbGroup();
   AcDbObjectId grpId;
   AcDbDictionary *pGroupDict;
   Acad::ErrorStatus es;
   AcApDocument *curDoc;


   //get the group dictionary
   AcDbDatabase *pDb = acdbHostApplicationServices()->workingDatabase();
   if (Acad::eOk == (es = acDocManager->lockDocument(curDoc=acDocManager->curDocument())))
      es = pDb->getGroupDictionary(pGroupDict,AcDb::kForWrite);


   if (es != Acad::eOk)
      return es;


   //make an anonymous entry
   if ((es = pGroupDict->setAt("*", pGroup, grpId)) == Acad::eOk) {
      //retrieve its name char *pNam;
      pGroup->close();
   }


   // create a resbuf with our ObjectID in it
   struct resbuf *newRb = acutBuildList (RTLONG, grpId, RTNONE);
   // if ok
   if (newRb != NULL) {
      // if this is the first time we've done this
      if (startRb == NULL) {
         // then set this as the start
         startRb = newRb;
      }
      // otherwise add it to the end of our list
      else {
         // create a pointer to the beginning of our resbuf list
         struct resbuf *ptr = startRb;
         // find the end of our list
         while (ptr->rbnext != NULL)
            ptr = ptr->rbnext;


         // now attach our newly create resbuf to the end
         ptr->rbnext = newRb;
      }
   }


   pGroupDict->close();
   acDocManager->unlockDocument(curDoc);


   acedRetList(startRb);
   acutRelRb(startRb);
   return (RTNORM);
}


For the most part, the following Lisp code is a direct translation of the VBA
code from the DevNote (TS36234):

下面是LISP代码:
**** Hidden Message *****
页: [1]
查看完整版本: 利用ARX从AUTOLISP创建匿名组