- UID
- 267748
- 积分
- 1257
- 精华
- 贡献
-
- 威望
-
- 活跃度
-
- D豆
-
- 在线时间
- 小时
- 注册时间
- 2005-5-27
- 最后登录
- 1970-1-1
|
发表于 2005-11-15 17:35:13
|
显示全部楼层
Jon Fleming
May 28 2002, 8:38 pm show options
Newsgroups: autodesk.autocad.customization
From: Jon Fleming <j...@fleming-group.com> - Find messages by this author
Date: Tue, 28 May 2002 05:25:22 -0700
Local: Tues, May 28 2002 8:25 pm
Subject: Re: Using Transparent command within a command in AutoLISP
Reply to Author | Forward | Print | Individual Message | Show original | Report Abuse
You have to use ActiveX methods:
(vl-load-com)
;;; Workaround for (vlax-add-cmd) bug.
;;; by Stephan Koster
;; Comments by JRF: This code should be
;;; run before adding any other commands with vlr-add-cmd.
;;; Otherwise, when using added commands in multiple documents
;;; (MDI mode), sometimes the commands fail with a "Visual LISP
;;; command document mismatch" error. Apparently vlax-add-cmd
;;; must be called in a document in order to activate commands
;;; in that document.
(defun DummyCommand () NIL)
(vlax-add-cmd "DummyCommand" 'DummyCommand)
(defun AddCommandsHelper (a b)
(vlax-add-cmd "DummyCommand" 'DummyCommand)
)
;; Install dummy command reactor only if it's not
;; defined already
(or DummyCommandReactor
(setq DummyCommandReactor
(vlr-docmanager-reactor
NIL
'((:vlr-documentBecameCurrent . AddCommandsHelper))
)
)
)
;;; Two-letter aliases for zooms:
;;; First a wrapper function for zooming using ActiveX methods.
;;; If necessary, first switches to paper space. Does the zoom.
;;; If necessary, switches back to model space.
;;; Argument:
;;; A quoted function to actually do the zoom. It may use the
;;; variables AcadObject and ActiveDocumentObject, which will be
;;; set appropriately by the ZoomWrapper function.
(defun ZoomWrapper (ZoomFunction / SwitchBack OldViewport AcadObject
ActiveDocumentObject
)
(setq AcadObject (vlax-get-acad-object)
ActiveDocumentObject (vlax-get-property
AcadObject "ActiveDocument")
)
;; If we're in a model space viewport in paper space and that
;; viewport's display is locked (saving the currently active viewport
;; in case it's needed later) ...
(if (and (= (getvar "TILEMODE") 0)
(/= (getvar "CVPORT") 1)
(equal :vlax-true
(vlax-get-property
(setq OldViewport
(vlax-get-property
ActiveDocumentObject
"ActivepViewport"
)
)
"DisplayLocked"
)
)
)
;; Set a flag to switch back later, and switch to paper space
(progn
(setq SwitchBack T)
(vlax-put-property
ActiveDocumentObject
"MSpace"
:vlax-false
)
)
)
;; Do the zoom
(eval ZoomFunction)
;; If we need to switch back to model space ...
(if SwitchBack
;; Do it
(progn
(vla-Display OldViewport :vlax-true)
(vlax-put-property ActiveDocumentObject "MSpace" :vlax-true)
)
)
)
(defun ZoomAll ()
(ZoomWrapper '(vla-ZoomAll AcadObject))
(princ)
)
(vlax-add-cmd "ZA" 'ZoomAll "ZA" ACRX_CMD_TRANSPARENT)
(defun ZoomCenter (/ Magnification)
(ZoomWrapper
'(vla-ZoomCenter
AcadObject
(vlax-3d-point
(trans (getpoint "\nSpecify center point: ") 1 0)
)
(if
(setq
Magnification
(getreal
(strcat
"\nEnter magnification or height <"
(rtos (getvar "VIEWSIZE"))
">: "
)
)
)
(vlax-make-variant Magnification vlax-vbDouble)
(vlax-make-variant (getvar "VIEWSIZE") vlax-vbDouble)
)
)
)
(princ)
)
(vlax-add-cmd "ZC" 'ZoomCenter "ZC" ACRX_CMD_TRANSPARENT)
;;; Because there's no vla-ZoomDynamic,we have to use a kludge
;;; that works except you can't repeat it by hitting <Enter>;
;;; hitting <Enter> repeats the ZOOM command.
(defun ZoomDynamic ()
(vla-SendCommand
(vla-Get-ActiveDocument
(vlax-get-acad-object)
)
"'._Zoom _D "
)
(princ)
)
(vlax-add-cmd "ZD" 'ZoomDynamic "ZD" ACRX_CMD_TRANSPARENT)
(defun ZoomExtents ()
(ZoomWrapper '(vla-ZoomExtents AcadObject))
(princ)
)
(vlax-add-cmd "ZE" 'ZoomExtents "ZE" ACRX_CMD_TRANSPARENT)
;;; Because there's no vla-ZoomVMAX,we have to use a kludge
;;; that works except you can't repeat it by hitting <Enter>;
;;; hitting <Enter> repeats the ZOOM command.
(defun ZoomVMAX ()
(vla-SendCommand
(vla-Get-ActiveDocument
(vlax-get-acad-object)
)
"'._Zoom _VMAX "
)
(princ)
)
(vlax-add-cmd "ZM" 'ZoomVMAX "ZM" ACRX_CMD_TRANSPARENT)
(defun ZoomPrevious ()
(ZoomWrapper '(vla-ZoomPrevious AcadObject))
(princ)
)
(vlax-add-cmd "ZP" 'ZoomPrevious "ZP" ACRX_CMD_TRANSPARENT)
(defun ZoomWindow (/ FirstCorner)
(ZoomWrapper
'(vla-ZoomWindow
AcadObject
(vlax-3d-point
(trans
;; When the first point is picked, the crosshairs will
;; align with the current UCS ... I don't see a simple
;; way around that.
(setq FirstCorner (getpoint "\nSpecify first corner: "))
1
0
)
)
(vlax-3d-point
(trans
(getcorner FirstCorner "Specify opposite corner: ")
1
0
)
)
)
)
(princ)
)
(vlax-add-cmd "ZW" 'ZoomWindow "ZW" ACRX_CMD_TRANSPARENT)
(defun ZoomHalf ()
(ZoomWrapper
'(vla-ZoomScaled
AcadObject
(vlax-make-variant 0.5 vlax-vbDouble)
acZoomScaledRelative
)
)
(princ)
)
(vlax-add-cmd "Z5" 'ZoomHalf "Z5" 1)
(vlax-add-cmd "ZH" 'ZoomHalf "ZH" 1)
(defun ZoomTwice ()
(ZoomWrapper
'(vla-ZoomScaled
AcadObject
(vlax-make-variant 2.0 vlax-vbDouble)
acZoomScaledRelative
)
)
(princ)
)
(vlax-add-cmd "Z2" 'ZoomTwice "Z2" ACRX_CMD_TRANSPARENT)
jrf
Member of the Autodesk Discussion Forum Moderator Program
Please do not email questions unless you wish to hire my services |
|