马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
Calling (entget) in my :vlr-pickfirstmodified callback causes AutoCAD to crash.
To reproduce this, load the Lisp code below, and then select a PViewport in a layout:
 - (vl-load-com)
- (vl-load-reactors)
- (vlr-miscellaneous-reactor nil (list (cons ':vlr-pickfirstmodified 'crash)))
- (defun Crash (p1 p2 / sel ii)
- (setq sel (cadr (ssgetfirst))
- ii 0
- )
- (repeat (if sel (sslength sel) 0)
- (setq ent (ssname sel ii)
- ii (1+ ii)
- )
- (entget ent)
- )
- )
解决方案:
反应器在SDI=1下工作正常,然而,在SDI=0的时候,会出现问题。通常,在编辑器反应器(editor reactor)中,实体不能打开进行写操作 (:vlr-miscellaneous-reactor is an editor reactor),是因为文档没有锁定。在SDI=0时候,文档不会自动的锁定。通过VLISP,没有办法进行锁定文档操作,但是可以通过ARX是可行的,因此,我们可以通过在ARX,写一个文档锁定的函数给LISP调用,来解决这个问题。
下面的ARX代码,我们通过acedDefun定义两个函数(lockDoc)和(unlockDoc)
[C++] 纯文本查看 复制代码 // ----- ads_lockdoc symbol (do not rename)
static int ads_lockdoc(void)
{
// TODO: add your code here
acDocManager->lockDocument(acDocManager->curDocument()) ;
// TODO: Replace the following line by your returned value if any
acedRetVoid () ;
return (RSRSLT) ;
}
// ----- ads_unlockdoc symbol (do not rename)
static int ads_unlockdoc(void)
{
// TODO: add your code here
acDocManager->unlockDocument(acDocManager->curDocument());
// TODO: Replace the following line by your returned value if any
acedRetVoid () ;
return (RSRSLT) ;
}
下面是LISP在回调函数里面使用这两个函数的代码。
[Plain Text] 纯文本查看 复制代码 (vl-load-com)
(vl-load-reactors)
;;; Check to see if the ARX program is loaded
(defun isAppLoaded (app)
(if (not (member app (arx)))
(setq bAppLoaded :vlax-false)
(setq bAppLoaded :vlax-true)
)
bAppLoaded
)
;;; Load the ARX program if necessary
(if (= (isAppLoaded "asdkLockDoc.arx") :vlax-false)
(arxload (findfile "asdkLockDoc.arx"))
)
(vlr-miscellaneous-reactor nil (list (cons ':vlr-pickfirstmodified 'crash)))
(defun Crash (p1 p2 / sel ii)
(lockdoc) ; lock the document
(setq sel (cadr (ssgetfirst))
ii 0
)
(repeat (if sel (sslength sel) 0)
(setq ent (ssname sel ii)
ii (1+ ii)
)
(entget ent)
)
(unlockdoc) ; unlock the document
)
上面是ARX写函数的解决方案。
XDRX API提供了文档锁定和解锁的函数
xdrx_document_lock
xdrx_document_unlock
|