Transparent command with Lisp

Transparent command with Lisp

Anonymous
Not applicable
2,526 Views
17 Replies
Message 1 of 18

Transparent command with Lisp

Anonymous
Not applicable
Anyone know if I can do a transparent command with lisp? Ie
(command "'_help") doesn't work. (I'm using AcadUnsupp)
0 Likes
2,527 Views
17 Replies
Replies (17)
Message 2 of 18

Anonymous
Not applicable
garnax,

Are you working in VB/VBA, or Visual LISP? In Visual LISP you can use the
(vlax-add-cmd) function to create a function which is transparent in
AutoLISP. Unfortunately, if you are working in VB/VBA, I don't know of a way
to do it through the command line. You might want to try the VBA Discussion
Group. It looks like you might be trying to start a help topic in AutoCAD
from VB - If that's the case - you'd be better off with a VB method of
starting the Help topic. I suggest going to the VBdesign website and sending
an E-mail to Randall Rath: http://vbdesign.hypermart.net

He'll probably be able to help. (Sorry - I'm not very well versed yet in
VB/VBA...)

--
Phillip Kenewell
CAD Systems Technician
Air Gage Company
[email protected]
===================

garnax wrote in message
news:[email protected]...
> Anyone know if I can do a transparent command with lisp? Ie
> (command "'_help") doesn't work. (I'm using AcadUnsupp)
0 Likes
Message 3 of 18

Anonymous
Not applicable
Hi Phil,

Can you go into more detail as to how you can create a transparent lisp
command using Visual Lisp? I tried to do a transparent lisp zoom previous
command and it did not work:

(defun zp()(command"ZOOM""P"))
(vlax-add-cmd "zp" 'zp)

Paul

Phil Kenewell wrote in message
news:[email protected]...
> garnax,
>
> Are you working in VB/VBA, or Visual LISP? In Visual LISP you can use the
> (vlax-add-cmd) function to create a function which is transparent in
> AutoLISP. Unfortunately, if you are working in VB/VBA, I don't know of a
way
> to do it through the command line. You might want to try the VBA
Discussion
> Group. It looks like you might be trying to start a help topic in AutoCAD
> from VB - If that's the case - you'd be better off with a VB method of
> starting the Help topic. I suggest going to the VBdesign website and
sending
> an E-mail to Randall Rath: http://vbdesign.hypermart.net
>
> He'll probably be able to help. (Sorry - I'm not very well versed yet in
> VB/VBA...)
>
> --
> Phillip Kenewell
> CAD Systems Technician
> Air Gage Company
> [email protected]
> ===================
>
> garnax wrote in message
> news:[email protected]...
> > Anyone know if I can do a transparent command with lisp? Ie
> > (command "'_help") doesn't work. (I'm using AcadUnsupp)
>
0 Likes
Message 4 of 18

Anonymous
Not applicable
Paul,

Using the Command function negates creating a Transparent AutoLISP command.
you must use ActiveX for this. Unfortunately, creating a Transparent command
in the Multiple Document Environment of AutoCAD 2000 is a little more
difficult. First, you have to create a function, Then you have to create a
Docmanager reactor to identify when switching between Active documents to
prevent a Document Mismatch Error. Then you must create a callback function
to redefine the commands for the Active Document. Here's an Example: (Watch
out for word-wrap in this E-mail)

;; Callback Function to redefine Commands in Active Doc.
(defun cmdredef (calbck cmd / return ok)
(foreach x ax:commandslist
(if (and
(member (type (eval (caddr x))) '(SUBR USUBR EXRXSUBR))
(setq ok (apply 'vlax-add-cmd (cdr x)))
)
(setq return (cons ok return))
)
)
return
)

;; This Function is Run at top level at load after Functions
;; are defined to Create the commands.
(defun addmdicmd (lst / old)
(foreach x lst
(vlax-remove-cmd (car x))
(if (setq old (assoc (strcase (car x)) ax:commandslist))
(setq ax:commandslist (subst (cons (strcase (car x)) x) old
ax:commandslist))
(setq ax:commandslist (cons (cons (strcase (car x)) x) ax:commandslist))
)
)
(if (not agc:addcmdreactor)
(setq agc:addcmdreactor
(vlr-docmanager-reactor
"AX-Commands"
'((:vlr-documentBecameCurrent . cmdredef))
)
)
)
(cmdredef nil nil)
)

;; Define Zoom>Extents function.
(defun ax-ze ()
(vla-zoomextents (vlax-get-acad-object))
(princ)
)
;; Add Command "ZE" to Command definitions...
(setq ax:cmdlst (cons (list "ZE" 'ax-ze "ZE" 1) ax:cmdlst))

;; Define Zoom>Previous function.
(defun ax-zp ()
(vla-zoomPrevious (vlax-get-acad-object))
(princ)
)
;; Add Command "ZP" to Command definitions...
(setq ax:cmdlst (cons (list "ZP" 'ax-zp "ZP" 1) ax:cmdlst))

;; Run (addmdicmd) to define commands. (must be done last!)
(addmdicmd ax:cmdlst)

Add the Contents of this in to a LISP file and load the LISP file in your
acaddoc.lsp

Hope this helps,

--
Phillip Kenewell
CAD Systems Technician
Air Gage Company
[email protected]
===================

Paul Li - adesknews.autodesk.com wrote in message
news:[email protected]...
> Hi Phil,
>
> Can you go into more detail as to how you can create a transparent lisp
> command using Visual Lisp? I tried to do a transparent lisp zoom previous
> command and it did not work:
0 Likes
Message 5 of 18

Anonymous
Not applicable
Hi Phil,

This is very helpful. But is there a way I could call the new ZE and ZP
vlisp functions transparently from a LISP function? For example:

(command"_.Line" "0,0" "ZP") ; for a transparent Zoom Previous in the middle
of a line command

Paul

Phil Kenewell wrote in message
news:[email protected]...
> Paul,
>
> Using the Command function negates creating a Transparent AutoLISP
command.
> you must use ActiveX for this. Unfortunately, creating a Transparent
command
> in the Multiple Document Environment of AutoCAD 2000 is a little more
> difficult. First, you have to create a function, Then you have to create a
> Docmanager reactor to identify when switching between Active documents to
> prevent a Document Mismatch Error. Then you must create a callback
function
> to redefine the commands for the Active Document. Here's an Example:
(Watch
> out for word-wrap in this E-mail)
>
> ;; Callback Function to redefine Commands in Active Doc.
> (defun cmdredef (calbck cmd / return ok)
> (foreach x ax:commandslist
> (if (and
> (member (type (eval (caddr x))) '(SUBR USUBR EXRXSUBR))
> (setq ok (apply 'vlax-add-cmd (cdr x)))
> )
> (setq return (cons ok return))
> )
> )
> return
> )
>
> ;; This Function is Run at top level at load after Functions
> ;; are defined to Create the commands.
> (defun addmdicmd (lst / old)
> (foreach x lst
> (vlax-remove-cmd (car x))
> (if (setq old (assoc (strcase (car x)) ax:commandslist))
> (setq ax:commandslist (subst (cons (strcase (car x)) x) old
> ax:commandslist))
> (setq ax:commandslist (cons (cons (strcase (car x)) x)
ax:commandslist))
> )
> )
> (if (not agc:addcmdreactor)
> (setq agc:addcmdreactor
> (vlr-docmanager-reactor
> "AX-Commands"
> '((:vlr-documentBecameCurrent . cmdredef))
> )
> )
> )
> (cmdredef nil nil)
> )
>
> ;; Define Zoom>Extents function.
> (defun ax-ze ()
> (vla-zoomextents (vlax-get-acad-object))
> (princ)
> )
> ;; Add Command "ZE" to Command definitions...
> (setq ax:cmdlst (cons (list "ZE" 'ax-ze "ZE" 1) ax:cmdlst))
>
> ;; Define Zoom>Previous function.
> (defun ax-zp ()
> (vla-zoomPrevious (vlax-get-acad-object))
> (princ)
> )
> ;; Add Command "ZP" to Command definitions...
> (setq ax:cmdlst (cons (list "ZP" 'ax-zp "ZP" 1) ax:cmdlst))
>
> ;; Run (addmdicmd) to define commands. (must be done last!)
> (addmdicmd ax:cmdlst)
>
> Add the Contents of this in to a LISP file and load the LISP file in your
> acaddoc.lsp
>
> Hope this helps,
>
> --
> Phillip Kenewell
> CAD Systems Technician
> Air Gage Company
> [email protected]
> ===================
>
> Paul Li - adesknews.autodesk.com wrote in message
> news:[email protected]...
> > Hi Phil,
> >
> > Can you go into more detail as to how you can create a transparent lisp
> > command using Visual Lisp? I tried to do a transparent lisp zoom
previous
> > command and it did not work:
>
0 Likes
Message 6 of 18

Anonymous
Not applicable
Paul,

In that case, you do need to define it with (vlax-add-cmd) and all that
other stuff, you would just call the original function between calls to
(command) like so:

(command "._line" "_non" "0,0")
(ax-zp)
;; If you need to perform additional calls to the line command,
;; Just continue the command call where you left off.
(command "_non" "2,5"...

The Whole purpose of creating LISP Transparent commands is that they can be
called from the *command line* WHILE another AutoLISP function is running,
without getting a "Can't Reenter AutoLISP" Error.
--
Phillip Kenewell
CAD Systems Technician
Air Gage Company
[email protected]
===================

Paul Li wrote in message
news:[email protected]...
> Hi Phil,
>
> This is very helpful. But is there a way I could call the new ZE and ZP
> vlisp functions transparently from a LISP function? For example:
>
> (command"_.Line" "0,0" "ZP") ; for a transparent Zoom Previous in the
middle
> of a line command
0 Likes
Message 7 of 18

Anonymous
Not applicable
OOPS:

>In that case, you do need to...

should have been:

>In that case, you don't need to

--
Phillip Kenewell
CAD Systems Technician
Air Gage Company
[email protected]
0 Likes
Message 8 of 18

Anonymous
Not applicable
Thanks Phil. Now, how do I get a list of all the available vla-functions
that A2k provides? Because looking at the code you generated, the new
(ax-zp) function calls the vla-zoomPrevious method in vlax-get-acad-object,
right?

Paul

Phil Kenewell wrote in message
news:[email protected]...
> Paul,
>
> In that case, you do need to define it with (vlax-add-cmd) and all that
> other stuff, you would just call the original function between calls to
> (command) like so:
>
> (command "._line" "_non" "0,0")
> (ax-zp)
> ;; If you need to perform additional calls to the line command,
> ;; Just continue the command call where you left off.
> (command "_non" "2,5"...
>
> The Whole purpose of creating LISP Transparent commands is that they can
be
> called from the *command line* WHILE another AutoLISP function is running,
> without getting a "Can't Reenter AutoLISP" Error.
> --
> Phillip Kenewell
> CAD Systems Technician
> Air Gage Company
> [email protected]
> ===================
>
> Paul Li wrote in message
> news:[email protected]...
> > Hi Phil,
> >
> > This is very helpful. But is there a way I could call the new ZE and ZP
> > vlisp functions transparently from a LISP function? For example:
> >
> > (command"_.Line" "0,0" "ZP") ; for a transparent Zoom Previous in the
> middle
> > of a line command
>
0 Likes
Message 9 of 18

Anonymous
Not applicable
Paul,

All the Visual LISP method are wrappers for the ActiveX components described
in the VBA Developer's guide. So AutoDesk did not document them. However,
it's fairly easy to derive the Methods from the VBA guide. Translating from
the VBA guide to Visual LISP is as follows:

object.Method = (vla- )

--
Phillip Kenewell
CAD Systems Technician
Air Gage Company
[email protected]
===================

Paul Li wrote in message
news:[email protected]...
> Thanks Phil. Now, how do I get a list of all the available vla-functions
> that A2k provides? Because looking at the code you generated, the new
> (ax-zp) function calls the vla-zoomPrevious method in
vlax-get-acad-object,
> right?
>
> Paul
0 Likes
Message 10 of 18

Anonymous
Not applicable
Hi Phil,

unfortunately there is another bug in AutoCAD if you
use these ActiveX zoom functions.

A lot of my functions will crash if they were
called after this zoom functions, if they use
one of this functions:
(setvar) -> crashes routine
(regapp) -> returns NIL and therefore crashes routine
(entmake) -> crashes AutoCAD
These crashes will not happen every time, only in some
circumstances.
I have published an example in the thread "ActiveX crashes AutoCAD".
Specially some of my arx functions which uses acdbEntMake will
crash AutoCAD completely without a chance to save the drawings.

This means if you use this ActiveX zoom functions you may crash
third party routines. If you don't want to distribute your app
and you don't use third party apps and you don't have routines
which use the lisp functions above then you can use the ActiveX zooms
but else you shouldn't.

As a workaround you can use:

(defun zp ( / activedoc)
(setq activedoc (vla-get-ActiveDocument (vlax-get-acad-object)))
(vla-SendCommand activedoc "'._zoom _p ")
)

(defun ze ( / activedoc)
(setq activedoc (vla-get-ActiveDocument (vlax-get-acad-object)))
(vla-SendCommand activedoc "'._zoom _e ")
)

Stephan
0 Likes
Message 11 of 18

Anonymous
Not applicable
Okay, great...thanks.

Paul

Phil Kenewell wrote in message
news:[email protected]...
> Paul,
>
> All the Visual LISP method are wrappers for the ActiveX components
described
> in the VBA Developer's guide. So AutoDesk did not document them. However,
> it's fairly easy to derive the Methods from the VBA guide. Translating
from
> the VBA guide to Visual LISP is as follows:
>
> object.Method = (vla- )
>
> --
> Phillip Kenewell
> CAD Systems Technician
> Air Gage Company
> [email protected]
> ===================
>
> Paul Li wrote in message
> news:[email protected]...
> > Thanks Phil. Now, how do I get a list of all the available
vla-functions
> > that A2k provides? Because looking at the code you generated, the new
> > (ax-zp) function calls the vla-zoomPrevious method in
> vlax-get-acad-object,
> > right?
> >
> > Paul
>
0 Likes
Message 12 of 18

Anonymous
Not applicable
And:
If you use ActiveX zooms you should not
use express tools.

Load this:
(defun c:zp()
(vla-zoomPrevious (vlax-get-acad-object))
)
then enter:
zp
and then use btrim or bextend from express tools:
-> AutoCAD will crash.

Stephan

Stephan Koster wrote:
>
> Hi Phil,
>
> unfortunately there is another bug in AutoCAD if you
> use these ActiveX zoom functions.
>
> A lot of my functions will crash if they were
> called after this zoom functions, if they use
> one of this functions:
> (setvar) -> crashes routine
> (regapp) -> returns NIL and therefore crashes routine
> (entmake) -> crashes AutoCAD
> These crashes will not happen every time, only in some
> circumstances.
> I have published an example in the thread "ActiveX crashes AutoCAD".
> Specially some of my arx functions which uses acdbEntMake will
> crash AutoCAD completely without a chance to save the drawings.
>
> This means if you use this ActiveX zoom functions you may crash
> third party routines. If you don't want to distribute your app
> and you don't use third party apps and you don't have routines
> which use the lisp functions above then you can use the ActiveX zooms
> but else you shouldn't.
>
> As a workaround you can use:
>
> (defun zp ( / activedoc)
> (setq activedoc (vla-get-ActiveDocument (vlax-get-acad-object)))
> (vla-SendCommand activedoc "'._zoom _p ")
> )
>
> (defun ze ( / activedoc)
> (setq activedoc (vla-get-ActiveDocument (vlax-get-acad-object)))
> (vla-SendCommand activedoc "'._zoom _e ")
> )
>
> Stephan
0 Likes
Message 13 of 18

Anonymous
Not applicable
Stephan,

Strange, I have not experienced any Fatal errors (yet) with programs that
use (entmake) after These Zooms, nor have I had any problems with the
Express Tools (I have the VIP version loaded). However, I have produced a
consistent Error with programs using (setvar) - It appears the First call to
(setvar) fails after using an ActiveX Zoom method. I have gotten this to
repeat consistently in any case.

Is it only the ActiveX Zooming methods that cause these bugs, or does this
happen with any ActiveX Method? Never mind - I just answered this question
as I feared - ANY ActiveX method appears to cause this problem with
(setvar). Damn! I'm tired of having a lot of work go down the drain because
of Autodesk's poor testing when it comes to new APIs. You listening
AutoDesk?

--
Phillip Kenewell
CAD Systems Technician
Air Gage Company
[email protected]
===================
> Not < a Member of the AutoDESK
Discussion Forum Moderator Program
Stephan Koster wrote in message
news:[email protected]...
> And:
> If you use ActiveX zooms you should not
> use express tools.
>
> Load this:
> (defun c:zp()
> (vla-zoomPrevious (vlax-get-acad-object))
> )
> then enter:
> zp
> and then use btrim or bextend from express tools:
> -> AutoCAD will crash.
>
> Stephan
>
> Stephan Koster wrote:
> >
> > Hi Phil,
> >
> > unfortunately there is another bug in AutoCAD if you
> > use these ActiveX zoom functions.
> >
> > A lot of my functions will crash if they were
> > called after this zoom functions, if they use
> > one of this functions:
> > (setvar) -> crashes routine
> > (regapp) -> returns NIL and therefore crashes routine
> > (entmake) -> crashes AutoCAD
> > These crashes will not happen every time, only in some
> > circumstances.
> > I have published an example in the thread "ActiveX crashes AutoCAD".
> > Specially some of my arx functions which uses acdbEntMake will
> > crash AutoCAD completely without a chance to save the drawings.
> >
> > This means if you use this ActiveX zoom functions you may crash
> > third party routines. If you don't want to distribute your app
> > and you don't use third party apps and you don't have routines
> > which use the lisp functions above then you can use the ActiveX zooms
> > but else you shouldn't.
> >
> > As a workaround you can use:
> >
> > (defun zp ( / activedoc)
> > (setq activedoc (vla-get-ActiveDocument (vlax-get-acad-object)))
> > (vla-SendCommand activedoc "'._zoom _p ")
> > )
> >
> > (defun ze ( / activedoc)
> > (setq activedoc (vla-get-ActiveDocument (vlax-get-acad-object)))
> > (vla-SendCommand activedoc "'._zoom _e ")
> > )
> >
> > Stephan
0 Likes
Message 14 of 18

Anonymous
Not applicable
Phil,

do you think the VIP version of the express tools is
different?

Please tell me what happens, if you perform these
steps:

- (defun c:zp()(vla-zoomPrevious (vlax-get-acad-object)))
- insert a block
- type zp
- type bextend and select the insert

in my configuration AutoCAD will crash with the message:
!scandr.cpp@2328: eLockViolation

What do you get?

By the way, not only vla-zoom causes this, some other
ActiveX methods also, but not every method.

I would be happy if somebody has a workaround for
this problem.

Stephan
0 Likes
Message 15 of 18

Anonymous
Not applicable
Stephan,

It appears so - I performed the steps you just gave me and they worked fine
with no crash. However, I also have the AutoCAD 2000 Service pack
installed - Do you? I don't know if that would make a difference but I guess
it's worth asking...
--
Phillip Kenewell
CAD Systems Technician
Air Gage Company
[email protected]
===================

Stephan Koster wrote in message
news:[email protected]...
> Phil,
>
> do you think the VIP version of the express tools is
> different?
>
> Please tell me what happens, if you perform these
> steps:
>
> - (defun c:zp()(vla-zoomPrevious (vlax-get-acad-object)))
> - insert a block
> - type zp
> - type bextend and select the insert
>
> in my configuration AutoCAD will crash with the message:
> !scandr.cpp@2328: eLockViolation
0 Likes
Message 16 of 18

Anonymous
Not applicable
Phil,

yes, of course I have the service pack installed.
My configuration: A2K SP1 with NT 4 SP6
The described steps crashes AutoCAD always here.

For example I can use this script:
---- begin of script
(defun c:zp()(vla-zoomPrevious (vlax-get-acad-object)))
._line 0,0 100,0

._block test 0,0 _last

._insert test 0,0

_zoom
0,0
100,100
zp
_bextend
0,0

_redraw
---- end of script

I have unload all my apps, only the express tools
stay loaded and the error remains the same.

If you can't recreate the error the only explanation
is your VIP version of the express tools.

Stephan
0 Likes
Message 17 of 18

Anonymous
Not applicable
Oops,

better use this script
(take care, may crash your running AutoCAD session):
---- begin of script
(defun c:zp()(vla-zoomPrevious (vlax-get-acad-object)))
_zoom
-10,-10
120,120
._line 0,0 100,0

._block test 0,0 _last

._insert test 0,0

_zoom
0,0
100,100
zp
_bextend
0,0

_redraw
---- end of script

Stephan

Stephan Koster wrote:
>
> Phil,
>
> yes, of course I have the service pack installed.
> My configuration: A2K SP1 with NT 4 SP6
> The described steps crashes AutoCAD always here.
>
> For example I can use this script:
> ---- begin of script
> (defun c:zp()(vla-zoomPrevious (vlax-get-acad-object)))
> ._line 0,0 100,0
>
> ._block test 0,0 _last
>
> ._insert test 0,0
>
> _zoom
> 0,0
> 100,100
> zp
> _bextend
> 0,0
>
> _redraw
> ---- end of script
>
> I have unload all my apps, only the express tools
> stay loaded and the error remains the same.
>
> If you can't recreate the error the only explanation
> is your VIP version of the express tools.
>
> Stephan
0 Likes
Message 18 of 18

Anonymous
Not applicable
Stephan,

I tried the Script you created and it caused the same error - consistently.
I have no idea why it causes an error under those circumstances, but It
appears that the VIP Express Tools do not matter. I appears that the error
does not occur if any other action is performed after the zoom, but before
starting the bextend command. Very frustrating...

--
Phillip Kenewell
CAD Systems Technician
Air Gage Company
[email protected]
===================

Stephan Koster wrote in message
news:[email protected]...
> Oops,
>
> better use this script
> (take care, may crash your running AutoCAD session):
> ---- begin of script
> (defun c:zp()(vla-zoomPrevious (vlax-get-acad-object)))
> _zoom
> -10,-10
> 120,120
> ._line 0,0 100,0
>
> ._block test 0,0 _last
>
> ._insert test 0,0
>
> _zoom
> 0,0
> 100,100
> zp
> _bextend
> 0,0
>
> _redraw
> ---- end of script
>
> Stephan
0 Likes