找回密码
 立即注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

楼主: 贱人

[求助] .....................................

[复制链接]
发表于 2005-8-19 00:31:58 | 显示全部楼层
用反应器编程 可以记住上个执行的命令
下面的程序是我为了学习 反应器,  很久以前网上找来的, 文字说明可以忽略(天知道是什么语言)     
通过这段东东, 你应该知道, 怎么编程记住上个执行的命令


(defun c:Rea ()
;;; Definisco i Reattori di inizio e fine comando:
(vl-load-com)
(CreaReattoreFineComando)
(CreaReattoreInizioComando)

;;; Trasformo la poly in un oggetto VLA:
   (setq VLPoly(vlax-ename->vla-object (entlast)))

;;; Definisco il Reattore oggetto:
(setq ModificaPoly(vlr-object-reactor (list VLPoly) "Reattore POLY"
'((:vlr-modified . EstraiPolyModificata))))

;;; e lo rendo persistente:
(vlr-pers ModificaPoly)

)
;;;
;;; Calcolo della lunghezza di una polilinea:
;;;
(defun LunghezzaCurva (Curva)
(setq startSpline (vlax-curve-getStartParam Curva))
(setq endSpline (vlax-curve-getEndParam Curva))
(vlax-curve-getDistAtParam Curva (- endspline startspline))
)
;;;
;;; Definisco il Reattore comando che reagisce alla conclusione del comando AutoCAD:
;;;
(defun CreaReattoreFineComando ()
(if (not *ReattoreFineComando*)
            (setq *ReattoreFineComando* (VLR-Command-Reactor nil
'((:vlr-commandEnded . PolyModificata))))
)
)
;;;
;;; Definisco il Reattore comando che reagisce all'inizio del comando AutoCAD:
;;;
(defun CreaReattoreInizioComando ()
(if (not *ReattoreInizioComando*)
            (setq *ReattoreInizioComando* (VLR-Command-Reactor nil
'((:vlr-commandWillStart . PolyVerraModificata))))
)
)
;;;
;;; routine per la conversione di un Array Variant (coordinate della Polyline) in una lista
;;; di punti.
;;;
(defun Array->ListaPunti (poly*)
(setq CoordNew(vla-get-Coordinates poly*))
(setq VCoordNew(vlax-variant-value CoordNew))
(setq DimensioneArray(vlax-safearray-get-dim VCoordNew))
(setq IndiceDiPartenza(vlax-safearray-get-l-bound VCoordNew
DimensioneArray))
(setq IndiceDiArrivo(vlax-safearray-get-u-bound VCoordNew DimensioneArray))
(setq ListaPunti nil)
(setq i IndiceDiPartenza)
(repeat (/ (+ 1 IndiceDiArrivo) 3)
  (setq XV(vlax-safearray-get-element VCoordNew i))
  (setq YV(vlax-safearray-get-element VCoordNew (+ i 1)))
  (setq ZV(vlax-safearray-get-element VCoordNew (+ i 2)))
  (setq ListaPunti(cons (list XV YV ZV) ListaPunti))
  (setq i(+ i 3))
)
(reverse ListaPunti)
)
;;;
;;; routine attivata dal Reattore di inizio Comando (:vlr-commandWillStart):
;;;
(defun PolyVerraModificata (reattore lista-comando)
(setq XDATAPoly nil)
(setq ComandoCorrente (car lista-comando))
(princ "\n YOUR ACTION IS: ")(princ ComandoCorrente)(princ)
)
;;;
;;; routine attivata dal Reattore di fine Comando (:vlr-commandEnded):
;;;
(defun PolyModificata (reattore lista-comando)
;;;
  (setq XDATAPoly nil)
;;;
  (setq ComandoCorrente (car lista-comando))
   (if passato
; se passato=t vuol dire che si è passati per la modificadella polilinea...
  (progn (princ "\n  La nuova lunghezza è: ")
         (princ (LunghezzaCurva *Poly*)))
)

)
;;;
;;; routine per l'estrazione di vecchi dati della polilinea (prima del cambiamento)
;;; viene attivata dal Reattore oggetto:
;;;
(defun EstraiPolyModificata (oggetto-notifica oggetto-poly NomeEntita)

(setq NomeReattore(vlr-data oggetto-poly))
   (if (member ComandoCorrente '("EXTEND" "GRIP_STRETCH" "STRETCH" "SCALE"
"U" "MOVE" "ROTATE" ))
   (progn
   (setq *Poly* oggetto-notifica)
   (setq passato t)
   (setq XDATAPoly(*LetturaXDATAPoly *Poly* "SEZIONI"))
   (cond
   ((and (vlax-property-available-p *Poly* 'Coordinates) (= ListaPuntiVec nil))
    (setq ListaPuntiVec (Array->ListaPunti *Poly*))
   ))
   (princ "\n  La vecchia lunghezza è: ")(princ (LunghezzaCurva *Poly*))
   )
     (setq passato nil)
)
)
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

发表于 2005-8-19 12:08:12 | 显示全部楼层
这个程序是在你刚敲入一个命令后立刻显示命令名,而不是显示上一个执行完的命令。 也许改一改可以做到。
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|申请友链|Archiver|手机版|小黑屋|辽公网安备|晓东CAD家园 ( 辽ICP备15016793号 )

GMT+8, 2025-9-28 11:33 , Processed in 0.163717 second(s), 27 queries , Gzip On.

Powered by Discuz! X3.5

© 2001-2025 Discuz! Team.

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