cgv 发表于 2022-7-6 02:10:11

将UCS设置为世界坐标

你好
 
只是想知道是否有人知道是否有某种例程可以在图形关闭时将图形的UCS设置回世界?这可能吗?
 
谢谢

BIGAL 发表于 2022-7-6 02:14:26

可以重新定义命令,使其运行一系列命令。
 
已经有一段时间了,像这样的内容需要保存为自动加载lisps区域的一部分
 

(command "Undefine" "CLOSE")
(defun c:CLOSE ()
(command "ucs" "w")
(command "Zoom" "E")
(command "._CLOSE")
)
 
而且http://www.afralisp.net/autolisp/tutorials/redefining-commands.php

cgv 发表于 2022-7-6 02:22:11

Al,
 
我已经将LISP加载到启动中,但它似乎并没有将我的UCS设置为接近世界坐标。

jdiala 发表于 2022-7-6 02:25:38

(command "Undefine" "CLOSE")
(defun c:CLOSE ()
(command "ucs" "w")
(command "Zoom" "E")
(command "._qsave")
(command "._CLOSE")
)

cgv 发表于 2022-7-6 02:27:38

贾迪亚拉,
 
有没有办法让绘图询问是否保存?否则,它只会自动保存图形。
 
谢谢

jdiala 发表于 2022-7-6 02:34:10

(command "undefine" "close")
(defun C:close ()
(if (= 1 (getvar 'dwgtitled))
   (command "_.ucs" "w" "_.zoom" "e" "_.qsave" "_.close")
   (command "_.close")
)
)

cgv 发表于 2022-7-6 02:34:30

贾迪亚拉,
 
例行程序似乎仍然没有询问是否保存图形。它仍在关闭时自动保存。
 
再次感谢。

jdiala 发表于 2022-7-6 02:39:25

(command "undefine" "close")
(defun C:close ()
(initget 7 "Yes No")
(setq a (getkword "\nDo you want to save the drawing? (Yes / No) "))

(if (= a "Yes")
   (if (= 1 (getvar 'dwgtitled))
   (command "_.ucs" "w" "_.zoom" "e" "_.qsave" "_.close")
   (progn
       (command "_.ucs" "w" "_.zoom" "e")
       (initdia)
       (command "_.save" "_.close")
   )
   )
   (command "_.close" "n")
)
)

cgv 发表于 2022-7-6 02:44:28

谢谢jdiala,但有时它似乎不同意关闭我的绘图。我想这是没有办法的。
 
我读过一些关于在“反应器”中使用命令的内容,但我不知道这些是如何工作的。
http://www.cadtutor.net/forum/showthread.php?46761-没有UCS命令调用的UCS世界

Lee Mac 发表于 2022-7-6 02:46:31

以下是使用绘图反应器的示例:
 

;; UCS Reactor-Lee Mac
;; Sets the active UCS to a UCS equivalent to WCS when the drawing is saved.

(defun c:ucsr-on ( )
   (if (= 'vlr-dwg-reactor (type ucsr:reactor))
       (if (vlr-added-p ucsr:reactor)
         (princ "\nUCS reactor already running.")
         (progn
               (vlr-add ucsr:reactor)
               (princ "\nUCS reactor enabled.")
         )
       )
       (progn
         (setq ucsr:reactor
               (vlr-dwg-reactor "ucs-reactor"
                  '(
                     (:vlr-beginsave    . ucsr:beginsave)
                     (:vlr-savecomplete . ucsr:savecomplete)
                   )
               )
         )
         (princ "\nUCS reactor enabled.")
       )
   )
   (princ)
)

(defun c:ucsr-off ( / cmd )
   (if (= 'vlr-dwg-reactor (type ucsr:reactor))
       (progn
         (vlr-remove ucsr:reactor)
         (setq ucsr:reactor nil)
         (setq cmd (getvar 'cmdecho))
         (setvar 'cmdecho 0)
         (command "_.ucs" "_w")
         (setvar 'cmdecho cmd)
         (if (tblsearch "ucs" "ucsr-ucs")
               (vla-delete (vla-item (vla-get-usercoordinatesystems (ucsr:acdoc)) "ucsr-ucs"))
         )
         (princ "\nUCS reactor disabled.")
       )
       (princ "\nUCS reactor not running.")
   )
   (princ)
)

(defun ucsr:beginsave ( obj arg )
   (if (= "" (setq ucsr:prevucs (getvar 'ucsname)))
       (setq ucsr:prevucs (mapcar 'getvar '(ucsorg ucsxdir ucsydir)))
   )
   (vla-put-activeucs (ucsr:acdoc)
       (vlax-invoke (vla-get-usercoordinatesystems (ucsr:acdoc)) 'add
         '(0.0 0.0 0.0)
         '(1.0 0.0 0.0)
         '(0.0 1.0 0.0)
         "ucsr-ucs"
       )
   )
   (princ)
)

(defun ucsr:savecomplete ( obj arg )
   (cond
       (   (= 'str (type ucsr:prevucs))
         (if (tblsearch "ucs" ucsr:prevucs)
               (vla-put-activeucs (ucsr:acdoc)
                   (vla-item (vla-get-usercoordinatesystems (ucsr:acdoc)) ucsr:prevucs)
               )
         )
       )
       (   (= 'list (type ucsr:prevucs))
         (vla-put-activeucs (ucsr:acdoc)
               (apply 'vlax-invoke
                  (append
                        (list (vla-get-usercoordinatesystems (ucsr:acdoc)) 'add)
                        ucsr:prevucs
                     '("ucsr-ucs")
                  )
               )
         )
       )
   )
   (setq ucsr:prevucs nil)
   (princ)
)

(defun ucsr:acdoc nil
   (eval (list 'defun 'ucsr:acdoc 'nil (vla-get-activedocument (vlax-get-acad-object))))
   (ucsr:acdoc)
)

(vl-load-com) (princ)

 
键入ucsr on以激活反应器,该反应器将在后台无声运行,以在保存图形时触发。
 
保存后,reactor回调函数将UCS设置为WCS等效项,然后在保存操作完成后恢复以前的UCS。
 
您可以随时使用ucsr off命令禁用反应堆。
 
但是,请注意,由于无法从reactor回调函数中评估命令调用,而且(据我所知)不可能使用Visual LISP将UCS设置为WCS,因此上述程序将UCS设置为与WCS等效的命名UCS。
 
页: [1] 2
查看完整版本: 将UCS设置为世界坐标