反应器,grread引起: Automation 错误等错误
(defun c:test()(if q t (setq q '()))
(setq t1 (vlax-ename->vla-object(car(entsel))))
(if(/= (vl-position t1 q) nil)
(vl-exit-with-value 0)
(setq q (cons t1 q)))
(setq t2 (vlr-object-reactor (list t1 ) nil '((:vlr-modified . t3)(:vlr-erased . t4))))
(princ)
)
(defun t3(notifier-object reactor-object parameter-list)
(cond
((equal
(mapcar '- (vlax-safearray->list(vlax-variant-value(vla-get-StartPoint notifier-object))) (trans (cadr(grread t 1)) 1 0))
'(0.0 0.0 0.0)
(* (/ (getvar "viewsize") (cadr (getvar "screensize"))) (getvar "gripsize")))
(alert "起点"))
((equal
(mapcar '- (vlax-safearray->list(vlax-variant-value(vla-get-EndPoint notifier-object))) (trans (cadr(grread t 1)) 1 0))
'(0.0 0.0 0.0)
(* (/ (getvar "viewsize") (cadr (getvar "screensize"))) (getvar "gripsize")))
(alert "终点"))
(t(alert "中点"))
)
)
(defun t4(notifier-object reactor-object parameter-list)
(if(wcmatch (strcase (car parameter-list)) "ERASE")
(alert "已删除")
(alert "未删除")
)
(princ)
)
使用反应器,t3和t4等函数使用undo、erase时,错误: Automation 错误
本帖最后由 飞雪神光 于 2022-10-6 07:32 编辑
(defun c:test()
(if q t (setq q '()))
(setq t1 (vlax-ename->vla-object(car(entsel))))
(if(/= (vl-position t1 q) nil)
(vl-exit-with-value 0)
(setq q (cons t1 q))
)
(setq t2 (vlr-object-reactor (list t1 ) nil '((:vlr-modified . t3)(:vlr-erased . t4))))
(princ)
)
(defun t3(notifier-object reactor-object parameter-list)
(if (and (null(vlax-erased-p notifier-object)) (entget(vlax-vla-object->ename notifier-object)))
(cond
((equal
(mapcar '- (vlax-safearray->list(vlax-variant-value(vla-get-StartPoint notifier-object))) (trans (cadr(grread t 1)) 1 0))
'(0.0 0.0 0.0)
(* (/ (getvar "viewsize") (cadr (getvar "screensize"))) (getvar "gripsize")))
(alert "起点")
)
((equal
(mapcar '- (vlax-safearray->list(vlax-variant-value(vla-get-EndPoint notifier-object))) (trans (cadr(grread t 1)) 1 0))
'(0.0 0.0 0.0)
(* (/ (getvar "viewsize") (cadr (getvar "screensize"))) (getvar "gripsize")))
(alert "终点")
)
(t(alert "中点"))
)
)
)
(defun t4(notifier-object reactor-object parameter-list)
(if(null parameter-list)
(alert "已删除")
(alert "未删除")
)
(princ)
)
技术有限在07上测试没问题
UNDO时,对象恢复了entname,或者恢复了vla-object 对象,但是这个时候对象还是不可读的状态,所以,在对象反应器中要读取某个对象的属性,一定要判断三个条件,1)是否删除。2)是否可读。3)是否有此属性。如下:
(and
(vlax-read-enabled-p notifier-object);此句非常重要,因为在对象删除后,重新恢复时,对象的上erased-p判断为nil,但是此时的对象为不可读状态,此时读取属性就会报错。
(not (vlax-erased-p notifier-object));如果只有这一句的判断,这个就会读取属性,此时会报错。读取对象属性,一定要判断是否可读,如夹点编辑后,undo一下,此时对象并没有删除,
;但是此时对象却不可读,若判断条件没有加read-enabled,就会“错误: Automation 错误。 对象已打开进行放弃”。
(vlax-property-available-p notifier-object "Radius");加了条件不可执行到此,若一定要取得属性,可以把notifier-object的变量指针付给一个全局变量*modified-obj*,在CMD-ended时取出对象的属性
)。
那一定要取得这个属性怎么办了,就需要等到命令执行完成。即到(:vlr-commandended . cmd-ended)命令完成,触发command反应器的回调函数cmd-ended,到此函数中读取*modified-obj*保存的对象属性,此时就没有问题了。
页:
[1]