Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Is Document Open

10 views
Skip to first unread message

Jason Piercey

unread,
May 30, 2002, 12:47:21 PM5/30/02
to
Slowly dipping my toes into the ActiveX pool.....

Is there a better way? or should that be What is the better way?

(defun IsDocOpen ( Doc / Tmp)
(vlax-for x (vla-get-documents (vlax-get-acad-object))
(if (equal (strcase Doc) (strcase (vla-get-name x)))
(setq Tmp x)
)
)
Tmp
)

No need to keep going once the (if) evaluates to T. What are my other
alternatives? How do you handle multiple sessions?
(vla-get-documents (vlax-get-acad-object)) is only for the current session,
right?

--
-Jason

Member of the Autodesk Discussion Forum Moderator Program


Ken Alexander

unread,
May 30, 2002, 1:45:31 PM5/30/02
to
That water is cold....

--
Ken Alexander
Acad 2000
Win 2000
"Jason Piercey" <Jason@AtrEngDOTcom> wrote in message
news:A96D6D8FF241D771...@in.WebX.maYIadrTaRb...

Bobby C. Jones

unread,
May 30, 2002, 2:20:02 PM5/30/02
to
Jason! You do realize what comes after ActiveX with lisp don't you :-)

Look at the ITEM method of the layers collection...and you'll also need to
look at the VL-CATCH-ALL-APPLY function...we're here for ya
--
Bobby C. Jones
www.acadx.com

"Jason Piercey" <Jason@AtrEngDOTcom> wrote in message
news:A96D6D8FF241D771...@in.WebX.maYIadrTaRb...

James Buzbee

unread,
May 30, 2002, 2:28:16 PM5/30/02
to
Jason,

This jb:OpenDbxDocument returns the axdbdocument object if the drawing is
NOT opened - nil if it is opened (locked by the OS).

;;; Does NOT close DbxDocument!!!
(defun jb:OpenDbxDocument (DwgName / dbxopen)
(if (not (RegisterObjectDBX))
(exit)
)
(if (= (type dwgname) 'STR)
(progn
(if (setq Dwg-Name (findfile DwgName))
(progn
(setq *dbxDoc*
(vla-GetInterfaceObject
(vlax-get-acad-object)
"ObjectDBX.AxDbDocument"
)
)
(setq dbxopen(vl-catch-all-apply
'vla-open (list *dbxDoc* Dwg-Name)))
(if (vl-catch-all-error-p dbxopen)
(setq *dbxDoc* nil)
)
)
(alert
(strcat
"*WARNING*\n\nDrawing "
dwgname
" \nnot found. Check to make sure it has not been moved or erased"
)
)
)
)
)
*dbxDoc*
)


jb


Doug Broad

unread,
May 30, 2002, 2:42:01 PM5/30/02
to
Jason,
I like it. The vla-catch-all....method requires an
exact match as far as string case. Your method does
not require a case match. You might also trim the
dwg from each to avoid the necessity of including that
in the match.

Doug


"Jason Piercey" <Jason@AtrEngDOTcom> wrote in message news:A96D6D8FF241D771...@in.WebX.maYIadrTaRb...

Jason Piercey

unread,
May 30, 2002, 3:22:13 PM5/30/02
to
OH NO! Bob! not the dark side......

Thanks for jumping in here, you are pretty scarce around here these days....

Time for me to stop playing and get back to work :-(

Hopefully I can concentrate on this a bit more after while.

--
-Jason

Member of the Autodesk Discussion Forum Moderator Program

Jason Piercey

unread,
May 30, 2002, 3:33:12 PM5/30/02
to
Thanks for the input, Doug.

Tony Tanzillo

unread,
May 30, 2002, 3:24:11 PM5/30/02
to
Well, for one thing you can eliminate the constant
expression (strcase doc), since it always evalutes
to the same result, there's no need to call strcase
more than once.

You can use (vl-catch-all-apply ...(exit)..) to break
out of just about any type of looping construct, as
shown here:

(defun isDocOpen(name / temp)
(setq name (strcase name)) ;; only need to do this once
(vl-catch-all-apply
'(lambda ()
(vlax-for doc (vla-get-documents (vlax-get-acad-object))
(if (eq name (strcase (vla-get-name doc)))
(progn
(setq temp doc)
(exit) ;; stop iterating


)
)
)
)
)

temp ;; returns the document object if open, or NIL
)


"Jason Piercey" <Jason@AtrEngDOTcom> wrote in message
news:A96D6D8FF241D771...@in.WebX.maYIadrTaRb...

Jason Piercey

unread,
May 30, 2002, 3:32:08 PM5/30/02
to
Thanks, James.

--
-Jason

Member of the Autodesk Discussion Forum Moderator Program

> This jb:OpenDbxDocument returns the axdbdocument object if the drawing is

James Buzbee

unread,
May 30, 2002, 3:57:32 PM5/30/02
to
"Tony Tanzillo" <tony.tanzillo at caddzone dot com> wrote:
> (vlax-for doc (vla-get-documents (vlax-get-acad-object))

Network, multiple sessions? What's wrong with the ObjectDBX method?

jb

Jason Piercey

unread,
May 30, 2002, 3:42:39 PM5/30/02
to
Thanks for the pointers, Tony.

I generally try and stay away from (exit) since it is such an abrupt ending,
but I see that wrapping it in (vl-catch-all-apply) takes care of that.


> (setq name (strcase name)) ;; only need to do this once

Wouldn't 'name' need to be localized now?

Jason Piercey

unread,
May 30, 2002, 4:32:33 PM5/30/02
to
Guess I don't follow, Frank....

>(defun isDocOpen(name / temp)

No 'name' after the '/'

> (setq name (strcase name))

Wouldn't this make it so it needs to be localized? Or am I all wet?

--
-Jason

Member of the Autodesk Discussion Forum Moderator Program


> It was. Look at the parameter list.

Tony Tanzillo

unread,
May 30, 2002, 4:27:24 PM5/30/02
to
"James Buzbee" <j...@levelvoid.com> wrote in message
news:04CB2966BF0A9CFB...@in.WebX.maYIadrTaRb...

> "Tony Tanzillo" <tony.tanzillo at caddzone dot com> wrote:
> > (vlax-for doc (vla-get-documents (vlax-get-acad-object))
>
> Network, multiple sessions? What's wrong with the ObjectDBX method?
>

Technically, you should always check to see if a given
file is open in the editor before trying to open it in
ObjectDBX. If it's already open in the editor, you can
just access it via AcadDocument instead, or you can ask
the user to close the drawing first if you require it to
be open in ObjectDBX.

Your code doesn't make an attempt to determine what
caused the vla-open method to fail, which could be
because the drawing is already open in the editor, or
in another AutoCAD session, or because it's read only,
or because of network permissions..., file corruption,
etc.


Frank Oquendo

unread,
May 30, 2002, 4:24:04 PM5/30/02
to
Jason Piercey <Jason@AtrEngDOTcom> had this to say:

> I see that name is nil, how does that work? If the same symbol is
> used for an argument and local var it doesn't need to be localized?

It was. Look at the parameter list.

--
http://www.acadx.com
"If you want to be somebody else change your mind"


Jason Piercey

unread,
May 30, 2002, 4:24:29 PM5/30/02
to
I see that name is nil, how does that work? If the same symbol is used for
an argument and local var it doesn't need to be localized?

--

Doug Broad

unread,
May 30, 2002, 4:20:55 PM5/30/02
to
Tony,

Thanks for that great illustration of how to break out of a vlax-for
loop. Almost as good as having a while. Though it may be
overkill here(with the likely number of documents open < 20), it
has excellent application for larger collections.


Tony Tanzillo

unread,
May 30, 2002, 4:43:23 PM5/30/02
to
Both function arguments and local variables are "localized'.

"Jason Piercey" <Jason@AtrEngDOTcom> wrote in message

news:77789807D67247E5...@in.WebX.maYIadrTaRb...

Jason Piercey

unread,
May 30, 2002, 4:47:07 PM5/30/02
to
I see. Guess I never realized that before. Somebody wake me up!

--
-Jason

Member of the Autodesk Discussion Forum Moderator Program

Bobby C. Jones

unread,
May 30, 2002, 5:03:32 PM5/30/02
to
I lurk as much as I can...things have been very busy lately and time is a
precious commodity. It won't be long before I'm back on a regular basis,
spreading the dark side :-)

--
Bobby C. Jones
www.acadx.com


"Jason Piercey" <Jason@AtrEngDOTcom> wrote in message

news:366B20A6325E4CBE...@in.WebX.maYIadrTaRb...

Cliff Middleton

unread,
May 31, 2002, 8:55:31 AM5/31/02
to
This version (which I think Bobby C. was hinting at, even though he said
"layers":) avoids iterating through the documents collection but has the
down side of the name argument being case sensitive.

(defun isDocOpen (name)
(not
(vl-catch-all-error-p
(vl-catch-all-apply
'vla-item
(list
(vla-get-documents (vlax-get-acad-object))
name


)
)
)
)
)

--
Cliff

"Jason Piercey" <Jason@AtrEngDOTcom> wrote in message

news:A96D6D8FF241D771...@in.WebX.maYIadrTaRb...

Jason Piercey

unread,
May 31, 2002, 9:39:58 AM5/31/02
to
Thanks, Cliff. So many ways to get the same thing done.

--
-Jason

Member of the Autodesk Discussion Forum Moderator Program

>avoids iterating through the documents collection but has the

Bobby C. Jones

unread,
May 31, 2002, 9:50:24 AM5/31/02
to
Did I say layers? It's a good thing that you knew what I meant <g> This is
indeed more along the lines of what I was suggesting. However, I like
Tony's version for two reasons. It avoids the case issue and it returns the
document object if it's open.

Funny thing is that the help files state that the selection set collection
is the only case sensitive collection. I've never encountered the documents
case problem as the only time that I've ever tested the open documents
against a file name is when I've collected the name directly from the file.
Another note to add to the list...

Here is my generic Item recipe that you all may, or may not, find useful:

(defun ax:Item (oCollection item / RetVal)
(if
(vl-catch-all-error-p
(setq RetVal
(vl-catch-all-apply
'vla-item
(list oCollection item)
)
)
)
nil
RetVal
)

R. Robert Bell

unread,
May 31, 2002, 10:35:47 AM5/31/02
to
Bobby,

As Tony pointed out weeks ago, this can be reduced to:

(defun ax:Item (oCollection item / RetVal)

(vl-catch-all-apply
(function (lambda () (setq RetVal (vla-Item oCollection item)))))
RetVal)


--
R. Robert Bell, MCSE
www.AcadX.com


"Bobby C. Jones" <bob...@acadx.com> wrote in message
news:BFF61B70E337DA98...@in.WebX.maYIadrTaRb...

Cliff Middleton

unread,
May 31, 2002, 11:50:12 AM5/31/02
to
For some reason my Outlook Express shows RBell's reply to Bobby but not
Bobby's post. I am wondering how many other posts I haven't seen. I
apologize in case it appears I haven't replied to someone. Any suggestions
as to what the problem may be?

Bobby,
I agree that Tony's version is better for the reasons given. The generic
item utility is handy tool. I have to look up vl-catch-all-apply every time
I use it.

R. Robert,
Thanks for posting the reduced version.
--
Cliff

"R. Robert Bell" <NOT.r...@acadx.com> wrote in message
news:4FEAC5AEC1EEB46B...@in.WebX.maYIadrTaRb...

James Buzbee

unread,
May 31, 2002, 11:54:33 AM5/31/02
to
"Cliff Middleton" <cmidd...@generalbroach.com> wrote:
>I have to look up vl-catch-all-apply every time

You and me both! :-)

jb


Cliff Middleton

unread,
May 31, 2002, 11:56:05 AM5/31/02
to
Also, I just noticed in Tony's version that the second argument [list of
parameters] to vl-catch-all-apply is optional. This is undocumented.
--
Cliff

"James Buzbee" <j...@levelvoid.com> wrote in message

news:DE9E88536F08A2B2...@in.WebX.maYIadrTaRb...

Bobby C. Jones

unread,
May 31, 2002, 11:44:41 AM5/31/02
to
Look at that...looks like I'm going to have to start following this group a
little closer <g>

Cliff Middleton

unread,
May 31, 2002, 1:31:06 PM5/31/02
to
Another aspect of the charm of programming with vlisp. The unadventurous
need not apply (or catch-all-apply).
--
Cliff

"R. Robert Bell" <NOT.r...@acadx.com> wrote in message

news:CE4BB6882A9E12BB...@in.WebX.maYIadrTaRb...
> In fact, it's documented *otherwise*:
>
> <clip>
>
> Your program can intercept and attempt to process errors instead of
allowing
> control to pass to *error*. The vl-catch-all-apply function is designed to
> invoke any function, return a value from the function, and trap any error
> that may occur. The function _requires_ (emphasis mine) two arguments: a
> symbol identifying a function or lambda expression, and a list of
arguments
> to be passed to the called function.
>
> </clip>
>
> Visual LISP Developer's Guide, Catching Errors and Continuing Program
> Execution


>
> --
> R. Robert Bell, MCSE
> www.AcadX.com
>
>

> "Cliff Middleton" <cmidd...@generalbroach.com> wrote in message
> news:569A9E72D6996EE9...@in.WebX.maYIadrTaRb...

R. Robert Bell

unread,
May 31, 2002, 1:19:41 PM5/31/02
to
In fact, it's documented *otherwise*:

<clip>

Your program can intercept and attempt to process errors instead of allowing
control to pass to *error*. The vl-catch-all-apply function is designed to
invoke any function, return a value from the function, and trap any error
that may occur. The function _requires_ (emphasis mine) two arguments: a
symbol identifying a function or lambda expression, and a list of arguments
to be passed to the called function.

</clip>

Visual LISP Developer's Guide, Catching Errors and Continuing Program
Execution

--


R. Robert Bell, MCSE
www.AcadX.com

"Cliff Middleton" <cmidd...@generalbroach.com> wrote in message
news:569A9E72D6996EE9...@in.WebX.maYIadrTaRb...

John Uhden

unread,
May 31, 2002, 2:05:50 PM5/31/02
to
Actually, it's catching the error of the lack of the second argument.

Command: (vl-catch-all-apply 'eval)
#<%catch-all-apply-error%>

Command: (vl-catch-all-apply 'rtos)
#<%catch-all-apply-error%>

It's sorta catching itself. :]

Can't go wrong with this one:
Command: (vl-catch-all-apply 'vl-catch-all-apply *anything/nothing*)
#<%catch-all-apply-error%>

--
John Uhden, Cadlantic/formerly CADvantage
http://www.cadlantic.com
Sea Girt, NJ

"Cliff Middleton" <cmidd...@generalbroach.com> wrote in message
news:569A9E72D6996EE9...@in.WebX.maYIadrTaRb...

R. Robert Bell

unread,
May 31, 2002, 2:21:54 PM5/31/02
to
<ouch> My head hurts... ;-)

--
R. Robert Bell, MCSE
www.AcadX.com


"John Uhden" <juh...@cadlantic.com> wrote in message
news:C6BDA6CD12FB831F...@in.WebX.maYIadrTaRb...

Bobby C. Jones

unread,
May 31, 2002, 3:20:51 PM5/31/02
to
I applaud Tony for his ingenuity in coming up with this algorithm, but after
looking over the code and reviewing the documentation, I have to say that I
don't agree with using it. Other than removing a few lines of code, are
there any valid reasons to use the shorter version? In light of the
documentation issue, the shorter version masks the true intent of the code
and makes it almost impossible for even an advanced lisp programmer to
easily see what the original programmers intent was. Don't get me wrong, I
don't have a problem with pushing a language to its limits if there's enough
gain to justify it, but I just don't see any gain here. I think that I'll
stick with my version for now.

Jason Piercey

unread,
May 31, 2002, 3:56:14 PM5/31/02
to

> after looking over the code and reviewing the documentation, I
> have to say that I don't agree with using it.

Guess I don't follow you with the documentation issue.


> Other than removing a few lines of code, are
> there any valid reasons to use the shorter version?

Case sensitivity is an issue for me, and shorter than your version?

> In light of the documentation issue, the shorter version
> masks the true intent of the code and makes it almost
> impossible for even an advanced lisp programmer to
> easily see what the original programmers intent was.

Have to disagree there, I barely know what I am looking at with this stuff
and I think it is pretty clear what the intent was/is.

Cliff Middleton

unread,
May 31, 2002, 4:16:07 PM5/31/02
to
As John Uhden points out below, vl-catch-all-apply is capturing the "too few
arguments" error generated when it tries to apply the non-existent arg list
to the function. Vlisp should return a syntax error when you load the file
but it does not.
--
Cliff

"Bobby C. Jones" <bob...@acadx.com> wrote in message

news:3C36BFFF9A47EE38...@in.WebX.maYIadrTaRb...

Cliff Middleton

unread,
May 31, 2002, 4:29:32 PM5/31/02
to
Retraction. Did some more testing on the error object. It is indeed
"Automation Error. Description was not provided." which means
vl-catch-all-apply is working with only one argument.
--
Cliff

"Cliff Middleton" <cmidd...@generalbroach.com> wrote in message

news:838A99A35AE578A4...@in.WebX.maYIadrTaRb...

Bobby C. Jones

unread,
May 31, 2002, 4:14:15 PM5/31/02
to
For iterating the documents collection, where case is an issue, then Tony's
routine is the way to go. I was speaking of these two functions and
specifically of the usage of vl-catch-all-apply. While the shorter version
is...shorter...it utilizes a technique that is unclear and not readily
apparent to someone looking over the code. IOW, If someone stumbled across
this code in a routine and cross referenced the docs to figure out how it
functioned, there would be some serious head scratching going on. Whereas
with the longer version, the intent is easy to follow...easy being a
relative term when dealing with lisp and ActiveX <g> It has been noted to
me, off group, that my opinion is not necessarily shared by all....nothing
new there <vbg>

(defun ax:Item (oCollection item / RetVal)
(if
(vl-catch-all-error-p
(setq RetVal
(vl-catch-all-apply
'vla-item
(list oCollection item)
)
)
)
nil
RetVal
)
)

(defun ax:Item (oCollection item / RetVal)


(vl-catch-all-apply
(function (lambda () (setq RetVal (vla-Item oCollection item)))))
RetVal)

--
Bobby C. Jones
www.acadx.com

"Jason Piercey" <Jason@AtrEngDOTcom> wrote in message
news:DF9F6D7AEA1BCBD5...@in.WebX.maYIadrTaRb...

Tony Tanzillo

unread,
May 31, 2002, 7:47:12 PM5/31/02
to
Well - That's not the case.

The second argument to (vl-catch-all-apply) is
optional, and if not supplied, defaults to '()
or Nil.

The second argument if supplied, must be a list.
The number of elements in that list must be at
least equal to the number of required arguments
that the function passed as the first argument
takes.

So, in your example, (vl-catch-all-apply) is not
catching "itself", it is catching the error raised
by (eval), which requires one argument.


"John Uhden" <juh...@cadlantic.com> wrote in message
news:C6BDA6CD12FB831F...@in.WebX.maYIadrTaRb...

John Uhden

unread,
May 31, 2002, 11:30:10 PM5/31/02
to
Tony:

I get the feeling we're all learning the behavior, and it ain't over 'til it's
over.
Notice in the following (I deleted the CRs) how the second argument is *not* a
list, and there's no apparent error.
Command: (vl-catch-all-apply 'boole 1)
Command: (setq error (vl-catch-all-apply 'boole 1))
Command: (type error) nil

Go figure.

Meanwhile, though this little (vla-catch-all...) exercise is only academic for
the reasons you stated earlier (file might be open for other reasons), I found
that your IsDocOpen function, though very clever, returned a VLA-Object for
"Drawing1.dwg" that had not yet been saved, as in (getvar "dwgtitled") being
zero. And, of course, without using the FullName how can you tell that *this*
"Drawing1.dwg" is different from or same as *that* "Drawing1.dwg?"

Also, the use of (vla-item) isn't predictable, because it appears to succeed
only if the string is an exact match, character by character.

So I hafta believe that James' ObjectDBX approach (which needs a little path
embellishment as well) or something like it is probably more reliable, and we
oughta drop the "blinders" approach that the current AutoCAD session is the only
application that might have the file open.

What say?

--
John Uhden, Cadlantic/formerly CADvantage
http://www.cadlantic.com
Sea Girt, NJ


"Tony Tanzillo" <tony.tanzillo at caddzone dot com> wrote in message
news:715DDA409F792DCA...@in.WebX.maYIadrTaRb...

John Uhden

unread,
Jun 1, 2002, 1:01:32 AM6/1/02
to
Jason:

It seems that after all this T&E that Dale's (dos_openp) function might be a
better mouse trap. :]

--
John Uhden, Cadlantic/formerly CADvantage
http://www.cadlantic.com
Sea Girt, NJ

"Jason Piercey" <Jason@AtrEngDOTcom> wrote in message

news:A96D6D8FF241D771...@in.WebX.maYIadrTaRb...
> Slowly dipping my toes into the ActiveX pool.....
>
> Is there a better way? or should that be What is the better way?
>
> (defun IsDocOpen ( Doc / Tmp)
> (vlax-for x (vla-get-documents (vlax-get-acad-object))
> (if (equal (strcase Doc) (strcase (vla-get-name x)))
> (setq Tmp x)
> )
> )
> Tmp
> )
>
> No need to keep going once the (if) evaluates to T. What are my other
> alternatives? How do you handle multiple sessions?
> (vla-get-documents (vlax-get-acad-object)) is only for the current session,
> right?
>

Tony Tanzillo

unread,
Jun 1, 2002, 4:28:27 AM6/1/02
to
"John Uhden" <juh...@cadlantic.com> wrote in message
news:4CA35B0B2836A636...@in.WebX.maYIadrTaRb...

> Tony:
>
> I get the feeling we're all learning the behavior, and it ain't over 'til
it's
> over.
> Notice in the following (I deleted the CRs) how the second argument is
*not* a
> list, and there's no apparent error.
> Command: (vl-catch-all-apply 'boole 1)
> Command: (setq error (vl-catch-all-apply 'boole 1))
> Command: (type error) nil

The fact that it doesn't generate an error when the
second argument isn't a list, is a bug. But, aside
from that, the behavior you suggested earlier is
simply not the case. The function accepts nil, or
no second argument, and behaves identically.

> Meanwhile, though this little (vla-catch-all...) exercise is only academic
for
> the reasons you stated earlier (file might be open for other reasons), I
found
> that your IsDocOpen function, though very clever, returned a VLA-Object
for
> "Drawing1.dwg" that had not yet been saved, as in (getvar "dwgtitled")
being
> zero. And, of course, without using the FullName how can you tell that
*this*
> "Drawing1.dwg" is different from or same as *that* "Drawing1.dwg?"

The version of Jason's IsDocOpen() function I posted was
intended to demonstrate how to break out of a loop using
(vl-catch-all-apply) and (exit), and nothing more.

> So I hafta believe that James' ObjectDBX approach (which needs
> a little path embellishment as well) or something like it is
> probably more reliable, and we oughta drop the "blinders"
> approach that the current AutoCAD session is the only application
> that might have the file open.

Sorry, but I don't follow your logic here at all.
Jason's original post, and James' reply are each
attempts at answering two different questions:

1. Can the file be opened for writing? (James' code)

2. Is the file is open in the drawing editor? (Jason's code)

The code they posted are not two different approaches
that attempt to answer the same question, each answers
a different question, both of which are legitmate and
not mutually exclusive.

In any case, it isn't really necessary to use ObjectDBX
to figure out if a drawing file is write-enabled. This is
what I've used for the past ten or so years for any type
of file:

(defun is-write-enabled (file / fh)
(if (setq fh (open file "a"))
(not (close h))
)
)

After AutoCAD switched from using ".DWK" semaphores
to the OS's file locking mechanism, this also happens
to work for dwg's as well, but again, the point here
is that "can this dwg file be opened?" and "is this
dwg file opened in this instance of AutoCAD" are two
different questions which can have different answers.

Which of the two questions (if not both) Jason should
be asking, is something you nor I know enough about
to intelligently debate.


Doug Broad

unread,
Jun 1, 2002, 12:55:50 PM6/1/02
to
Thanks again for your excellent contribution. For those who would like
to use this great little function, a minor correction:.

(defun is-write-enabled (file / fh)
(if (setq fh (open file "a"))

(not (close fh));<----
)
)

It should also be noted that this will flag non-existant files as "write-enabled"
which is appropriate. But it should always return nil if the drawing file is
opened.

Regards,
Doug

"Tony Tanzillo" <tony.tanzillo at caddzone dot com> wrote in message news:33462E80711BD166...@in.WebX.maYIadrTaRb...

Tony Tanzillo

unread,
Jun 1, 2002, 5:09:20 PM6/1/02
to
Thanks for pointing out the typo.

Yes, it will return nil for non-existing files,
but keep in mind that its job is limited to
determining if an existing file can be opened
for write. IOW, it assumes the file passed in
does exist.

"Doug Broad" <dbr...@earthlink.net> wrote in message
news:EA23B43735A0DB36...@in.WebX.maYIadrTaRb...

John Uhden

unread,
Jun 1, 2002, 10:09:37 PM6/1/02
to
Sheesh, Tony, I really didn't mean to keep you up that late (or is that get you
up that early?)<G>

Sorry for the delay; the storm last night blew the entire top of my corner maple
over the wires, knocked out power for 8 hours, and the utility company left me
to clean up all the debris out of my yard. I've been conjugating the Latin verb
"shio" all day. :/

My apologies for erroneously implying that (vl-catch-all-apply) "catches
itself." I agree that's not the case. I don't take it that the 2nd argument is
optional, but rather the function catches the error of the argument's absence
only if the function being "caught" requires argument(s). Similarly, if the
function being "caught" does not take any arguments and you give it one, a
(vl-catch-all-error-message) will be likewise generated.
Example (CRs removed):
Command: (setq error (vl-catch-all-apply 'terpri))
nil
Command: (setq error (vl-catch-all-apply 'terpri '("X")))
#<%catch-all-apply-error%>
Command: (vl-catch-all-error-message error)
"too many arguments"

So, while the documentation is, let's say "abridged", the function works
logically.

Also, upon further inspection, if any 2nd argument is required or provided, then
it must be in the form of a list, otherwise even the (vl-catch-all-apply)
function will fail without either warning or continuing subsequent code.
Example (CRs removed):
Command: (setq error "Whatever")
"Whatever"
Command: (setq error (vl-catch-all-apply 'exit 1))(princ error)
Command: !error
"Whatever"

Note that nil qualifies as an empty list.

I think Dale's (dos_openp) function might be the best all-around method. I used
to use a function similar to your (open file "a") method, but found it
inappropriate because it would change the file's date/time stamp.

Thanks for helping us learn.

--
John Uhden, Cadlantic/formerly CADvantage
http://www.cadlantic.com
Sea Girt, NJ

"Tony Tanzillo" <tony.tanzillo at caddzone dot com> wrote in message

news:33462E80711BD166...@in.WebX.maYIadrTaRb...

Tony Tanzillo

unread,
Jun 1, 2002, 11:14:09 PM6/1/02
to
"John Uhden" <juh...@cadlantic.com> wrote in message >

> I think Dale's (dos_openp) function might be the best all-around


> method. I used to use a function similar to your (open file "a")
> method, but found it inappropriate because it would change the
> file's date/time stamp.

Well, it doesn't appear to change the
file's timestamp here (Win2K).


Doug Broad

unread,
Jun 1, 2002, 11:39:14 PM6/1/02
to
While we're on the subject of vl-catch-all-apply, anyone got any idea
why this chokes
(vl-catch-all-apply 'command (list "line" "0,0" "1,1"))

but this doesn't choke
(vl-catch-all-apply 'vl-cmdf (list "line" "0,0" "1,1"))


"John Uhden" <juh...@cadlantic.com> wrote in message news:2E35B106210B7907...@in.WebX.maYIadrTaRb...

John Uhden

unread,
Jun 2, 2002, 12:57:23 AM6/2/02
to
Doug:

I'm beat and have got to get some sleep, so I'm not going to put my foot in my
mouth by responding without research (if you know what I mean). But I do recall
that "catching" 'command was futile. Could be the order in which the arguments
are evaluated. Not so sure that "catching" 'vl-cmdf was any better. Maybe
tomorrow... (which is already today) <yawn/zzzz>.

--
John Uhden, Cadlantic/formerly CADvantage
http://www.cadlantic.com
Sea Girt, NJ

"Doug Broad" <dbr...@earthlink.net> wrote in message

news:52C9BBFF9B079F7E...@in.WebX.maYIadrTaRb...

John Uhden

unread,
Jun 2, 2002, 12:47:41 AM6/2/02
to
Well, I'll be (running Win2KPro). Guess it's been a long time since I used that
method.

Care to address the vl-catch-... stuff?

--
John Uhden, Cadlantic/formerly CADvantage
http://www.cadlantic.com
Sea Girt, NJ


"Tony Tanzillo" <tony.tanzillo at caddzone dot com> wrote in message

news:6D9DB77F3523AD59...@in.WebX.maYIadrTaRb...

Tony Tanzillo

unread,
Jun 2, 2002, 9:23:03 AM6/2/02
to
(vl-catch-all-apply) doesn't seem to deal well with many
AutoLISP functions, but in fact, using it with a lambda
makes the issue moot:

(vl-catch-all-apply
'(lambda ()
(apply 'command (list "line" "0,0" "2,2" ""))
)
)

I usually avoid using vl-catch-all-apply directly like
your command example since it makes code harder to read.

"Doug Broad" <dbr...@earthlink.net> wrote in message
news:52C9BBFF9B079F7E...@in.WebX.maYIadrTaRb...

John Uhden

unread,
Jun 2, 2002, 12:02:28 PM6/2/02
to
Doug:
You can read the help on (vl-cmdf) yourself, but apparently the (command)
function doesn't evaluate anything... just passes all its arguments to AutoCAD
in order. (vl-cmdf) evaluates the list of arguments ahead of time. Tony's
'(lambda) thing is pretty cool. I found that this even works...

(vl-catch-all-apply
(function
(lambda ()
(command "line" "0,0" "2,2" "Kaboom")
)
)
)
Though the resulting error message is a bit confusing.

--
John Uhden, Cadlantic/formerly CADvantage
http://www.cadlantic.com
Sea Girt, NJ

"Doug Broad" <dbr...@earthlink.net> wrote in message
news:52C9BBFF9B079F7E...@in.WebX.maYIadrTaRb...

John Uhden

unread,
Jun 2, 2002, 11:43:34 AM6/2/02
to
That's neat, Tony.
But why not just this, bypassing (apply)?
(vl-catch-all-apply
'(lambda ()
(command "line" "0,0" "2,2" "")
)
)


--
John Uhden, Cadlantic/formerly CADvantage
http://www.cadlantic.com
Sea Girt, NJ


"Tony Tanzillo" <tony.tanzillo at caddzone dot com> wrote in message

news:8C64F7B1ABDFE993...@in.WebX.maYIadrTaRb...

Doug Broad

unread,
Jun 2, 2002, 2:50:29 PM6/2/02
to
Thanks for the clarifications Tony and John.

Regards,
Doug

"John Uhden" <juh...@cadlantic.com> wrote in message news:84ADE026831E0A30...@in.WebX.maYIadrTaRb...

Jason Piercey

unread,
Jun 3, 2002, 9:43:51 AM6/3/02
to
My original intent was to test if the drawing is open, not if it can be
written to. I wasn't planning on making any changes to the database just
reading it. This has turned out to be an interesting thread for me, I have
learned all kinds of things from this discussion. Thanks everyone.

--
-Jason

Member of the Autodesk Discussion Forum Moderator Program

> Which of the two questions (if not both) Jason should

Bobby C. Jones

unread,
Jun 3, 2002, 3:35:27 PM6/3/02
to
It was a re-invent...but probably a re-invent spurred from residual memories
from seeing it in AutoLay :-)

--
Bobby C. Jones
www.acadx.com

"Eric Schneider" <eschn...@spamfree.jensenprecast.com> wrote in message
news:82C4352A05E5A964...@in.WebX.maYIadrTaRb...
> Almost identical to this snippet from AutoLay[X.X].lsp. Just wondering if
> you re-invented it or adapted it?
>
> ;;;returns ActiveX object if exist, else nil
> (defun al:exist (collection item / rslt)
> (if
> (not
> (vl-catch-all-error-p
> (setq rslt
> (vl-catch-all-apply 'vla-item
> (list collection item)
> );trap error
> );end setq
> );return T if successful, else nil
> );end not
> rslt; return object or nil
> );end if
> );end defun
> --
>
> Regards,
> Eric S.
> A2k/W2k
>
>


Eric Schneider

unread,
Jun 3, 2002, 3:14:45 PM6/3/02
to

Eric Schneider

unread,
Jun 3, 2002, 3:29:07 PM6/3/02
to
NIL is actually an empty list and, as previously mentioned, evaluates the
same as an empty list or '() or (list).

Command: (listp nil)
T

Bobby C. Jones

unread,
Jun 3, 2002, 3:42:12 PM6/3/02
to
BTW - R. Robert Bell and I were discussing this in private and I have to
agree with the both of you, I prefer the (NOT (VL-....) to explicitly
returning NIL in the IF statement...

John Uhden

unread,
Jun 3, 2002, 3:55:41 PM6/3/02
to
This would be a Kosterized version:

(defun al:exist (collection item / rslt)
(and

(setq rslt
(vl-catch-all-apply 'vla-item
(list collection item)
)
)
(vl-catch-all-error-p rslt)
(setq rslt nil)
); end and
rslt
)

--
John Uhden, Cadlantic/formerly CADvantage
http://www.cadlantic.com
Sea Girt, NJ

"Eric Schneider" <eschn...@spamfree.jensenprecast.com> wrote in message
news:82C4352A05E5A964...@in.WebX.maYIadrTaRb...

Doug Broad

unread,
Jun 3, 2002, 8:02:27 PM6/3/02
to
;This would be a Broadderized version <G>
(defun exist_in (collection item / rslt)
(vl-catch-all-apply
(function
(lambda ()
(setq rslt (vla-item collection item)))))
rslt)

;If an error occurs, it will happen before the rslt
is bound, and therefore will be nil.

;|But if I may again muddy the water, it is possible
to have more than one item in a collection with the
same name as well as it is possible that the name
not exist. For drawings, it is possible to
have more than one open with the same name. It is
possible in fact to have several drawings open
with the same name and path (as long as one is not
titled). I found a wealth of information as I pushed
an prodded ACAD this weekend. If any of you are still
interested, let me know and I'll start a new thread.
This one is getting too deep to scroll for. Eric,
you should know that we all enjoy re-inventing the
wheel. I for one, though, have never looked in
AutoLay(sorry).

Regards,
Doug

"John Uhden" <juh...@cadlantic.com> wrote in message news:395BE4EA0BC98CD1...@in.WebX.maYIadrTaRb...

R. Robert Bell

unread,
Jun 3, 2002, 8:58:20 PM6/3/02
to
How can this be the Broadderized version since I posted this **wayyyyyy* up
the thread, with due credit to Tony? BwaHaHa!!!

--
R. Robert Bell, MCSE
www.AcadX.com


"Doug Broad" <dbr...@earthlink.net> wrote in message

news:4D975ABF4CF17D0F...@in.WebX.maYIadrTaRb...

R. Robert Bell

unread,
Jun 3, 2002, 11:30:44 PM6/3/02
to
Let's see if I have this right... Doug plagiarizes me, I plagiarize Tony,
Tony... <nevermind>...

--
R. Robert Bell, MCSE
www.AcadX.com

"John Uhden" <juh...@cadlantic.com> wrote in message

news:39829E25FE47380C...@in.WebX.maYIadrTaRb...
| Hey, plagiarism is the highest form of flattery, right?


|
| --
| John Uhden, Cadlantic/formerly CADvantage
| http://www.cadlantic.com
| Sea Girt, NJ
|
|

| "R. Robert Bell" <NOT.r...@acadx.com> wrote in message
| news:D43884F5A1F04DAC...@in.WebX.maYIadrTaRb...

John Uhden

unread,
Jun 3, 2002, 11:30:01 PM6/3/02
to
Hey, plagiarism is the highest form of flattery, right?

--


John Uhden, Cadlantic/formerly CADvantage
http://www.cadlantic.com
Sea Girt, NJ

"R. Robert Bell" <NOT.r...@acadx.com> wrote in message
news:D43884F5A1F04DAC...@in.WebX.maYIadrTaRb...

John Uhden

unread,
Jun 3, 2002, 11:36:46 PM6/3/02
to
I get it... maybe we need a "Catch-All" NG. :]

--
John Uhden, Cadlantic/formerly CADvantage
http://www.cadlantic.com
Sea Girt, NJ

"Doug Broad" <dbr...@earthlink.net> wrote in message
news:4D975ABF4CF17D0F...@in.WebX.maYIadrTaRb...

R. Robert Bell

unread,
Jun 3, 2002, 11:40:24 PM6/3/02
to
(Sure) most recent post gets the "nice work"... <mutter, mutter> ;-P

--
R. Robert Bell, MCSE
www.AcadX.com


"John Uhden" <juh...@cadlantic.com> wrote in message

news:346D0DC341FB840D...@in.WebX.maYIadrTaRb...
| Come to think of it, he plagiarized my use of (function), I think. That
does
| flatter me. Nice work, Doug!


|
| --
| John Uhden, Cadlantic/formerly CADvantage
| http://www.cadlantic.com
| Sea Girt, NJ
|
|
| "R. Robert Bell" <NOT.r...@acadx.com> wrote in message

| news:24D5C72696CAE520...@in.WebX.maYIadrTaRb...

John Uhden

unread,
Jun 3, 2002, 11:38:48 PM6/3/02
to
Come to think of it, he plagiarized my use of (function), I think. That does
flatter me. Nice work, Doug!

--


John Uhden, Cadlantic/formerly CADvantage
http://www.cadlantic.com
Sea Girt, NJ


"R. Robert Bell" <NOT.r...@acadx.com> wrote in message

news:24D5C72696CAE520...@in.WebX.maYIadrTaRb...

Doug Broad

unread,
Jun 4, 2002, 6:08:03 AM6/4/02
to
Robert, :-(
Sorry about the accidental theft<reinvented that wheel again>
But I used different spellings and hit the return at different
points. <yuck yuck>
Sorry Robert and Tony. This thread is so long, I forgot
what had been posted and was just responding<with humorous effort>
to John's post. Thought it could have been shorter. Forgot
about your posts. My short/long term memory is going....going..........

Heck, can we really copyright these basic building block
code formulations anyway? Someone, somewhere, probably
used the same construct prior to Tony or without seeing
it from Tony don't you think? I've made an effort to integrate
FUNCTION since I learned about it last summer(from one of you
no doubt). Can we avoid, either consciously or unconsciously, being
influenced by one another?

This construct by Tony and posted Robert is the best in my opinion
for the task. BTW, I like the name ITEM better than EXISTS_IN.
Was that the same name Tony gave it?

Now, who else can I copy?

Regards,
Doug


"R. Robert Bell" <NOT.r...@acadx.com> wrote in message news:D43884F5A1F04DAC...@in.WebX.maYIadrTaRb...

Doug Broad

unread,
Jun 4, 2002, 7:53:05 AM6/4/02
to
;|Robert: Your's(I mean Tony's) was very nice - obviously
I must have been impressed. <G>

BTW This is a Nesterovskized version<VBG>
<Disclaimer> Speaking only of his probable style.
<Intended as a compliment>
AFAIK they are original (Maybe???)
Any single argument|;

(defun catch1 (fun a / rslt)
(vl-catch-all-apply
(function
(lambda ()
(setq rslt (fun a)))))
rslt)

;;Any 2 arg function
(defun catch2 (fun a b / rslt)
(vl-catch-all-apply
(function
(lambda ()
(setq rslt (fun a b)))))
rslt)

;;Any function with arbitrary args
(defun catchn (fun args / r)
(if (not(vl-catch-all-error-p
(setq r (vl-catch-all-apply 'fun args))))
r))

;;Any quoted expression you want to error trap.
(defun vl-error-trap (expr)
(vl-catch-all-apply
'(lambda () (eval expr))
))

;|
Examples
(catch1 vla-get-count *docs* )
(catch2 vla-item *docs* 0)
(catchn vla-item (list *docs 0))
(catchn vla-add-arc (list *mspace* .......))
(vl-error-trap '(command "line" "0,0" "1,1" "Kaboom"))

These might<possibly> be better than making a wrapper
for every method/property/event that you want to trap.
They may not have any particular advantage over wrapping much
larger programs with vl-catch-all-apply. As noted in
the thread above, the catchn function would not work
with many functions (ex: COMMAND)

Also I'm not sure FUNCTION can do anything
to really optimize these expression since a function
is passed as an argument. They may be more secure from
prying eyes, however, in an error trace.
|;

Regards,
Doug

"R. Robert Bell" <NOT.r...@acadx.com> wrote in message news:B09BB507E7AA7E9B...@in.WebX.maYIadrTaRb...

Eric Schneider

unread,
Jun 4, 2002, 11:28:39 AM6/4/02
to
I re-invent code all the time. It seems to be like an evolution of the code
from the start of a project to the end. After all, there are a finite
(seemingly infinite due to embellishments) number of ways through the woods.
There are a finite number of commands available and only a few ways are
efficient (including readable and thinkable). It is only natural that we
draw common conclusions.

R. Robert Bell

unread,
Jun 4, 2002, 10:33:53 AM6/4/02
to
I *knew* spelling was gonna get mentioned... ;-)

FWIW, I don't think it is reasonable to attempt to copyright basic functions
such as this. Where would the madness stop?! For instance, there was a post
to the AUGI guilds where an author (from a book!) had actually placed a
copyright on a basic VBA error handling structure (selection sets)! Of
course, I was able to reduce it, so blatantly removed the "copyright" in
that thread. But I do endeavor to place credit where credit is due for the
techniques I employ.

The function name ax:Item was actually ripped from Bobby's posted
function...

--
R. Robert Bell, MCSE
www.AcadX.com


"Doug Broad" <dbr...@earthlink.net> wrote in message

news:42C31C808694AE76...@in.WebX.maYIadrTaRb...

Bobby C. Jones

unread,
Jun 4, 2002, 12:11:46 PM6/4/02
to
I say that the madness shouldn't stop...ever...For instance, I may be able
to take credit for the Item portion of the name, but the ax: I stole from
Frank...Now that I think about it, I also probably stole the Item portion
from someone and just forgot who...How would that copyright look!?!

ax: portion of function name Copyright Frank Oquendo 2002
Item portion of function name Copyright Unknown source 2002
ax:Item combined function name Copyright Bobby C. Jones 2002
(defun ax:Item () ...)

If we all don't start copyrighting every single part of every single
function now, there's no telling who will be stealing what!


--
Bobby C. Jones
www.acadx.com

"R. Robert Bell" <NOT.r...@acadx.com> wrote in message
news:8D472F8CCFDE7C4C...@in.WebX.maYIadrTaRb...

John Uhden

unread,
Jun 4, 2002, 1:02:03 PM6/4/02
to
I take it that if the code is "given" without explicitly stating that the
copyright must be included, then there are no strings attached. That's pretty
much what this place is for... give'n'take. The only strings-attached source
code I recall seeing here was one from Tony a while back, and maybe that wasn't
even source code <don't actually remember>.

--
John Uhden, Cadlantic/formerly CADvantage
http://www.cadlantic.com
Sea Girt, NJ


"Bobby C. Jones" <bob...@acadx.com> wrote in message
news:7A337BCEDDC3224E...@in.WebX.maYIadrTaRb...

Bobby C. Jones

unread,
Jun 4, 2002, 1:21:40 PM6/4/02
to
I agree with you John...I guess that the sarcasm in my post wasn't thick
enough :-)

Doug Broad

unread,
Jun 4, 2002, 1:26:56 PM6/4/02
to
Thanks Bobby and Robert for the good laugh. I needed that.

Seriously though, I do try to give credit. Stuff I cut and paste
from the newsgroup to my disk gets put in LSP files a header
like:
;;Newsgroup: Autodesk.autocad.customization
;;Thread: Reactors and LDT3
;;Date: 5/17/02
;;Posted by: John Uhden
;;Author: John Uhden
;;Function(s):
;;Purpose(s): Demonstration of how to add functions to startup.

<snip>

15 from Bobby's, 9 from Roberts and 6 from John U. at this
location and more at school. My goal was to give my students
good examples of programming style and some useful functions
that they wouldn't need to write themselves.


"Bobby C. Jones" <bob...@acadx.com> wrote in message news:7A337BCEDDC3224E...@in.WebX.maYIadrTaRb...

Bobby C. Jones

unread,
Jun 4, 2002, 3:58:10 PM6/4/02
to
15 of mine! Doug, You've got a larger library of my code than I do <g>

John Uhden

unread,
Jun 4, 2002, 5:46:23 PM6/4/02
to
Don't know if you guys ever played in the old ACAD Forum, but you used to be
able to post code, like in CF, and it would show the number of downloads. Now I
don't remember the actual names, so I'll take the liberty to substitute current
names...

Doug: "Anyone got a function to find the hypercenter of a globule?"
John: "Sure, Doug. Look in Lib12 for HyperGlob.lsp. I posted it a month ago."
Doug: "John - I just downloaded it and it gave me me an error."
John: "I don't understand; it's been downloaded 37 times with no other
complaints!?"
Bobby: "Yeah... I had downloaded it 36 times and never did get it to work. :/"

--
John Uhden, Cadlantic/formerly CADvantage
http://www.cadlantic.com
Sea Girt, NJ

"Bobby C. Jones" <bob...@acadx.com> wrote in message
news:9C31ADEE827BF520...@in.WebX.maYIadrTaRb...

R. Robert Bell

unread,
Jun 4, 2002, 6:47:16 PM6/4/02
to
BwaHaHa!!

(I see this thread headed for other pastures...)

--
R. Robert Bell, MCSE
www.AcadX.com

"John Uhden" <juh...@cadlantic.com> wrote in message

news:7766B71F773D7C78...@in.WebX.maYIadrTaRb...

John Uhden

unread,
Jun 4, 2002, 7:05:11 PM6/4/02
to
But the grazers over there might not get it. :(

--
John Uhden, Cadlantic/formerly CADvantage
http://www.cadlantic.com
Sea Girt, NJ

"R. Robert Bell" <NOT.r...@acadx.com> wrote in message

news:CC5E5EDC7A356B73...@in.WebX.maYIadrTaRb...

Anne Brown

unread,
Jun 4, 2002, 8:34:41 PM6/4/02
to
The good old days <G>

Anne
Compuserve ACAD Forum Wizop

John Uhden wrote:
>
> Don't know if you guys ever played in the old ACAD Forum, but you used to be

> able to post code, like in CF, and it would show the number of downloads. (snip)

John Uhden

unread,
Jun 4, 2002, 10:28:30 PM6/4/02
to
Thanks, Anne, for now *and* then.

--
John Uhden, Cadlantic/formerly CADvantage
http://www.cadlantic.com
Sea Girt, NJ


"Anne Brown" <discussio...@autodesk.com> wrote in message
news:3CFD5CA1...@autodesk.com...

Bobby C. Jones

unread,
Jun 5, 2002, 9:25:50 AM6/5/02
to
LOL! Now that's classic!

Unfortunately I was much to poor to afford CompuServe at that time...didn't
start hitting news groups until I had *free* access to C.C.A. at the office
via a listserver that delivered all of the messages to my email inbox. What
I didn't realize was that the company was charged on a per document basis
for each email that was sent or received over the internet. I discovered
this fact one day when the head of the IS department entered my office all
out of breath from sprinting down the hallway to inform me that one of my
incoming SMTP internet email messages had hung in the server overnight and
had effectively shut down external email communications for the entire
company. While unclogging the mess, one of the techs discovered a backlog
of nearly 100 *not so free* email messages for me...I was working for Exxon
at the time....

James Buzbee

unread,
Jun 5, 2002, 9:31:12 AM6/5/02
to
>I was working for Exxon at the time....

... and after I lost THAT job ... ;-)

jb


0 new messages