我通常不担心速度,因为迭代次数很小,可以肯定的是,有人讨论过使用entmake来提高速度,也许对于你的命令插入来说,让它成为一个defun。我相信,如果我错了,别人很快就会建议我。任何其他重复的代码行都可以考虑取消它,同样不确定,但由于此代码已经加载到lisp过程中,因此速度应该更快。对于ucs更改,您可以创建新的ucs,只需对其进行更改,注意需要一个名为“myworld”的名称,因为“World”不是直接支持的名称。
- ; from autodesk
- (vl-load-com)
- (defun c:Example_ActiveUCS()
- ;; This example returns the current saved UCS (or saves a new one dynamically)
- ;; and then sets a new UCS.
- ;; Finally, it returns the UCS to the previous setting.
- (setq acadObj (vlax-get-acad-object))
- (setq doc (vla-get-ActiveDocument acadObj))
- (setq UCSs (vla-get-UserCoordinateSystems doc))
-
- ;; Get the current saved UCS of the active document. If the current UCS is
- ;; not saved, then add a new UCS to the UserCoordinateSystems collection
- (if (= (vlax-variant-value (vla-GetVariable doc "UCSNAME")) "")
- (progn
- (setq utility (vla-get-Utility doc))
- (setq currUCS (vla-Add UCSs
- (vla-GetVariable doc "UCSORG")
- (vla-TranslateCoordinates utility (vla-GetVariable doc "UCSXDIR") acUCS acWorld :vlax-false)
- (vla-TranslateCoordinates utility (vla-GetVariable doc "UCSYDIR") acUCS acWorld :vlax-false)
- "OriginalUCS"
- )
- )
- )
- (setq currUCS (vla-get-ActiveUCS doc)) ;; current UCS is saved
- )
-
- (alert (strcat "The current UCS is " (vla-get-Name currUCS)))
-
- ;; Create a UCS and make it current
- (setq origin (vlax-3d-point 0 0 0)
- xAxis (vlax-3d-point 1 1 0)
- yAxis (vlax-3d-point -1 1 0))
- (setq newUCS (vla-Add UCSs origin xAxis yAxis "TestUCS"))
- (vla-put-ActiveUCS doc newUCS)
- (alert (strcat "The new UCS is " (vla-get-Name newUCS)))
-
- ;; Restore the previous UCS
- (vla-put-ActiveUCS doc currUCS)
- (alert (strcat "The UCS is restored to " (vla-get-Name currUCS)))
- )
|