Google 网上论坛不再支持新的 Usenet 帖子或订阅项。历史内容仍可供查看。

Using Transparent command within a command in AutoLISP

已查看 320 次
跳至第一个未读帖子

Jon Fleming

未读,
2002年5月28日 08:25:222002/5/28
收件人
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

In article <f0e30...@WebX.maYIadrTaRb>, Shyam wrote:
> Can anyone give me hints to use a Transparent command within a
> command in AutoLISP. As an example I want to use transparent Zoom
> command ('ZOOM) within PLINE command that I have used in AutoLISP.
>
> When I am using 'ZOOM in command prompt it is working but same
> command when I am using in AutoLISP it is terminating the LISP.
> Please help.
>


Doug Broad

未读,
2002年5月28日 09:26:062002/5/28
收件人
And it still won't be transparent if an arx command is running.

Jon,
Can you do me a favor and check out my last post on the
thread, "Simple lisp question, I think". How do you
like that method of dealing with locked viewports and zoom
vmax?
I also think John Uhden has got a nice short alternative as
his first post in that thread which deals very nicely with
locked viewports. Thanks for the reminder about
the dummy command.

Doug

"Jon Fleming" <jo...@fleming-group.com> wrote in message news:VA.0000117...@fleming-group.com...

Jon Fleming

未读,
2002年5月29日 08:18:062002/5/29
收件人
Your method seems fine to me; it's mostly a matter of programming style. Your check for a locked
viewport is better than mine, mostly because mine isn't pure ActiveX.

I don't see anything in John's first post that explicitly deals with locked viewports ...

jrf
Member of the Autodesk Discussion Forum Moderator Program
Please do not email questions unless you wish to hire my services

Doug Broad

未读,
2002年5月29日 09:56:122002/5/29
收件人
I think the neat thing about John's program is that he doesn't have
to look for locked viewports, since he is essentially sending the
zoom command itself, letting the zoom command work with
the locked viewport logic.

As Tony T. and others have mentioned, mixing active-x and
non-active x sometimes has problems. I sure would like someone
to keep track of those problems. Until then I'm trying to make
an effort not to mix the two. Thanks Jon for your reply.

0 个新帖子