天气与日历 切换到窄版

 找回密码
 立即注册
中国膜结构网
十大进口膜材评选 十大国产膜材评选 十大膜结构设计评选 十大膜结构公司评选
查看: 91|回复: 0

在ARX的帮助下,从Visual LISP创建匿名组

[复制链接]

该用户从未签到

主题

0

回帖

2912

积分

管理员

积分
2912
发表于 2024-6-22 09:46:18 | 显示全部楼层 |阅读模式
Create an anonymous group from Visual LISP with help from ARX
By Gopinath Taget

The following ARX code does that. You need to however register the ARX function using acedDefun() to be able to use it as an external Lisp function.  It is implemented such that it returns a list, containing the new group's ObjectID, to the external Lisp function.

[code]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(L"*", 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);

}


The Lisp code:



(defun isAppLoaded (app)

   (if (not (member app (arx)))

      (setq bAppLoaded :vlax-false)

      (setq bAppLoaded :vlax-true)

   )

   bAppLoaded

)



(defun Example_AddLightWeightPolyline()

   (vl-load-com)

   (if (= (isAppLoaded "asdkanonygrplsp.arx") :vlax-false)

      (arxload (findfile "asdkanonygrplsp.arx"))

   )





   (setq oAcad (vlax-get-acad-object)

           oDoc (vla-get-activedocument oAcad)

           *ModelSpace* (vla-get-ModelSpace oDoc)

   )





   ;;Add anonymous group

   (setq myGroup (vl-catch-all-apply

                              'vla-objectidtoobject

                              (list

                                 oDoc

                                 (vlax-make-variant

                               (car (acdbAddAnonGrpRet2Lsp))

                                    vlax-vbLong

                                 )

                              )

                           )

   ) ;setq





   ;;If error encountered making group, then exit

   (if (vl-catch-all-error-p myGroup)

      (princ (vl-catch-all-error-message myGroup))

      ;;otherwise continue...

      (progn

         ;; Define the 2D polyline points

         (setq pt1 (list 1.0 1.0)

                 pt2 (list 1.0 2.0)

                 pt3 (list 2.0 2.0)

                 pt4 (list 3.0 2.0)

                 pt5 (list 4.0 4.0)

         )

     (setq Points (apply 'append (list pt1 pt2 pt3 pt4 pt5)))

         (setq ptlstlen (length Points))





         ;; Make array of 5*2=10 doubles -

     ;; that's an array of dimension 0 to 9

         (setq PointDataA (

        vlax-make-safearray vlax-vbDouble (

                      cons 0 (1- ptlstlen))))

         (vlax-safearray-fill PointDataA Points)

         (setq PointData (vlax-make-variant PointDataA))





      ;; Create a light weight Polyline object in model space

         (setq myLWpoly (

        vla-addLightweightPolyline *ModelSpace* PointData))





         ;; Make array of 1 object (the new LWPolyline)

   (setq myObjA (vlax-make-safearray vlax-vbObject '(0 . 0)))

         (vlax-safearray-put-element myObjA 0 myLWpoly)





         ;; Add the LWPolyline to the group

         (vla-appenditems myGroup myObjA)

      ) ;progn

   ) ;if

   (princ)

)[/code]

 

 

 

 

在ARX的帮助下,从Visual LISP创建匿名组
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|中国膜结构网|中国膜结构协会|进口膜材|国产膜材|ETFE|PVDF|PTFE|设计|施工|安装|车棚|看台|污水池|中国膜结构网_中国空间膜结构协会

GMT+8, 2024-11-1 13:28 , Processed in 0.167386 second(s), 27 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表