Problem using GETFILED

Problem using GETFILED

Anonymous
Not applicable
755 Views
21 Replies
Message 1 of 22

Problem using GETFILED

Anonymous
Not applicable
With AutoCAD 14, if I type the following at the command prompt:

(setq a (getfiled "Select a Drawing file" "" "dwg" 8))

I get the dialog box to select the file. As long as I do not change the
directory or folder
AutoCAD returns the filename that I selected with no path.

If I do the exact same thing in AutoCAD 2000, I get the full path.

How can I get the filename only?

Thanks
Dennis
0 Likes
756 Views
21 Replies
Replies (21)
Message 2 of 22

Anonymous
Not applicable
You can use VL-FILENAME-BASE to strip the directory from a filename. It also
strips the extension though. If that's a problem, you can use something like
this to keep the extension (assuming the return value from GETFILED is
stored in the variable fn):

(substr fn (+ (strlen (vl-filename-directory fn)) 2))

Or if you have the express tools, just use ACET-FILENAME-PATH-REMOVE

--
Get free software and more at:
http://msnhomepages.talkcity.com/protectionfault/foquendo

"Dennis S. Nunes" wrote in message
news:[email protected]...
> With AutoCAD 14, if I type the following at the command prompt:
>
> (setq a (getfiled "Select a Drawing file" "" "dwg" 8))
>
> I get the dialog box to select the file. As long as I do not change the
> directory or folder
> AutoCAD returns the filename that I selected with no path.
>
> If I do the exact same thing in AutoCAD 2000, I get the full path.
>
> How can I get the filename only?
>
> Thanks
> Dennis
>
>
0 Likes
Message 3 of 22

Anonymous
Not applicable
Dennis,

I'm not sure what you have in mind to do with the filename, but here are
some options that might give you some ideas. They tend to be a bit long,
though.
--
Dave D

;For drawing name only in the current drawing directory, but is
;incorrect for any other directory with a different length name.

(defun c:getfil1 ()
(if (setq a (getfiled "Select a Drawing file" "" "dwg" 8))
(progn
(setq l (1+ (strlen (getvar "dwgprefix"))))
(setq a (substr a l))
(princ a)
)
(prompt "\nYou cancelled. ")
)
(princ)
)

;For drawing name only in any drawing directory:

(defun c:getfil2 ()
(if (setq a (getfiled "Select a Drawing file" "" "dwg" 8))
(progn
(setq l (strlen a) b x)
(while (/= b "\\")
(setq l (1- l))
(setq b (substr a l 1))
)
(setq a (substr a (1+ l)))
(princ a)
)
(prompt "\nYou cancelled. ")
)
(princ)
)

;For R14 behavior with GetFileD:

(defun c:getfil3 ()
(if (setq a (getfiled "Select a Drawing file" "" "dwg" 8))
(progn
(setq l (strlen a) b x)
(while (/= b "\\")
(setq l (1- l))
(setq b (substr a l 1))
)
(if (wcmatch (substr a 1 l) (getvar "dwgprefix"))
(setq a (substr a (1+ l)))
)
(princ a)
)
(prompt "\nYou cancelled. ")
)
(princ)
)

Dennis S. Nunes wrote in article
<[email protected]>...
> With AutoCAD 14, if I type the following at the command prompt:
>
> (setq a (getfiled "Select a Drawing file" "" "dwg" 8))
>
> I get the dialog box to select the file. As long as I do not change the
> directory or folder
> AutoCAD returns the filename that I selected with no path.
>
> If I do the exact same thing in AutoCAD 2000, I get the full path.
>
> How can I get the filename only?
>
> Thanks
> Dennis
>
>
>
0 Likes
Message 4 of 22

Anonymous
Not applicable
(cadr (fnsplitl a))

"Dennis S. Nunes" wrote:
>
> With AutoCAD 14, if I type the following at the command prompt:
>
> (setq a (getfiled "Select a Drawing file" "" "dwg" 8))
>
> I get the dialog box to select the file. As long as I do not change the
> directory or folder
> AutoCAD returns the filename that I selected with no path.
>
> If I do the exact same thing in AutoCAD 2000, I get the full path.
>
> How can I get the filename only?
>
> Thanks
> Dennis

--
|
----+----------------------------------------------
| Byron Blattel
| CADwerx---Applications for AutoCAD
|
| e-mail: [email protected]
|
|
0 Likes
Message 5 of 22

Anonymous
Not applicable
Frank,

Where did you come up with ACET-FILENAME-PATH-REMOVE, and how is it used?
It isn't in the listing that I have.
--
Dave D

Frank Oquendo wrote in article
<[email protected]>...
> You can use VL-FILENAME-BASE to strip the directory from a filename. It
also
> strips the extension though. If that's a problem, you can use something
like
> this to keep the extension (assuming the return value from GETFILED is
> stored in the variable fn):
>
> (substr fn (+ (strlen (vl-filename-directory fn)) 2))
>
> Or if you have the express tools, just use ACET-FILENAME-PATH-REMOVE
>
> --
> Get free software and more at:
> http://msnhomepages.talkcity.com/protectionfault/foquendo
0 Likes
Message 6 of 22

Anonymous
Not applicable
(defun strip-path (str)
(if (wcmatch str "*[\\/]*") (strip-path (substr str 2)) str)
)

e.g.

(strip-path "c:\\acad\\sample\\yadayadayada\\drawing.dwg")

returns "drawing.dwg"

__________________________________

Michael Puckett
[email protected]
> Not < an Autodesk hall monitor.
Imagination makes all things possible.
__________________________________

"Dennis S. Nunes" wrote in message
news:[email protected]...
With AutoCAD 14, if I type the following at the command prompt:

(setq a (getfiled "Select a Drawing file" "" "dwg" 8))

I get the dialog box to select the file. As long as I do not change the
directory or folder
AutoCAD returns the filename that I selected with no path.

If I do the exact same thing in AutoCAD 2000, I get the full path.

How can I get the filename only?

Thanks
Dennis
0 Likes
Message 7 of 22

Anonymous
Not applicable
It shows up in my APROPOS window when I search on ACET. You just feed it the
full path and it returns only the filename: (acet-filename-path-remove
(findfile "acad.exe")) yields "acad.exe" whereas findfile returns the full
path. I'm using ACETUTIL.ARX ver 1.35. You can check your version by calling
(acet-util-ver)

--
Get free software and more at:
http://msnhomepages.talkcity.com/protectionfault/foquendo

"David Doane" wrote in message
news:01bf7002$9fb8d800$1d57d2d0@lms-1...
> Frank,
>
> Where did you come up with ACET-FILENAME-PATH-REMOVE, and how is it used?
> It isn't in the listing that I have.
> --
> Dave D
>
>
> Frank Oquendo wrote in article
> <[email protected]>...
> > You can use VL-FILENAME-BASE to strip the directory from a filename. It
> also
> > strips the extension though. If that's a problem, you can use something
> like
> > this to keep the extension (assuming the return value from GETFILED is
> > stored in the variable fn):
> >
> > (substr fn (+ (strlen (vl-filename-directory fn)) 2))
> >
> > Or if you have the express tools, just use ACET-FILENAME-PATH-REMOVE
> >
> > --
> > Get free software and more at:
> > http://msnhomepages.talkcity.com/protectionfault/foquendo
>
0 Likes
Message 8 of 22

Anonymous
Not applicable
That splits a path into three components: the directory, the file base and
the extension. I don't think that would help too much in this particualt
case without concatenating the second and third items in the list.

--
Get free software and more at:
http://msnhomepages.talkcity.com/protectionfault/foquendo

"Byron Blattel" wrote in message
news:[email protected]...
> (cadr (fnsplitl a))
>
> "Dennis S. Nunes" wrote:
> >
> > With AutoCAD 14, if I type the following at the command prompt:
> >
> > (setq a (getfiled "Select a Drawing file" "" "dwg" 8))
> >
> > I get the dialog box to select the file. As long as I do not change the
> > directory or folder
> > AutoCAD returns the filename that I selected with no path.
> >
> > If I do the exact same thing in AutoCAD 2000, I get the full path.
> >
> > How can I get the filename only?
> >
> > Thanks
> > Dennis
>
> --
> |
> ----+----------------------------------------------
> | Byron Blattel
> | CADwerx---Applications for AutoCAD
> |
> | e-mail: [email protected]
> |
> |
0 Likes
Message 9 of 22

Anonymous
Not applicable
I believe he said he wanted the filename only, not the filename with
extension 🙂

Frank Oquendo wrote:
>
> That splits a path into three components: the directory, the file base and
> the extension. I don't think that would help too much in this particualt
> case without concatenating the second and third items in the list.



> > "Dennis S. Nunes" wrote:
> > >



> > > How can I get the filename only?
> > >
> > > Thanks
> > > Dennis
> >
0 Likes
Message 10 of 22

Anonymous
Not applicable
No it returns the filename with extension. I just took his request
literally.

(strcat (cadr (fnsplitl a)) (caddr (fnsplitl a)))

The point was that there is an AutoLISP function available for this
(fnsplitl) at least since R14.

Frank Oquendo wrote:
>
> Was that the behavior of GETFILED prior to A2K? I thought it returned a
> "Whatever".3 filename if you selected from the initial directory.
>
> --
> Get free software and more at:
> http://msnhomepages.talkcity.com/protectionfault/foquendo
>
> "Byron Blattel" wrote in message
> news:[email protected]...
> > I believe he said he wanted the filename only, not the filename with
> > extension 🙂
> >
> > Frank Oquendo wrote:
> > >
> > > That splits a path into three components: the directory, the file base
> and
> > > the extension. I don't think that would help too much in this particualt
> > > case without concatenating the second and third items in the list.
> >
> >
> >
> > > > "Dennis S. Nunes" wrote:
> > > > >
> >
> >
> >
> > > > > How can I get the filename only?
> > > > >
> > > > > Thanks
> > > > > Dennis
> > > >

--
|
----+----------------------------------------------
| Byron Blattel
| CADwerx---Applications for AutoCAD
|
| e-mail: [email protected]
|
|
0 Likes
Message 11 of 22

Anonymous
Not applicable
Was that the behavior of GETFILED prior to A2K? I thought it returned a
"Whatever".3 filename if you selected from the initial directory.

--
Get free software and more at:
http://msnhomepages.talkcity.com/protectionfault/foquendo

"Byron Blattel" wrote in message
news:[email protected]...
> I believe he said he wanted the filename only, not the filename with
> extension 🙂
>
> Frank Oquendo wrote:
> >
> > That splits a path into three components: the directory, the file base
and
> > the extension. I don't think that would help too much in this particualt
> > case without concatenating the second and third items in the list.
>
>
>
> > > "Dennis S. Nunes" wrote:
> > > >
>
>
>
> > > > How can I get the filename only?
> > > >
> > > > Thanks
> > > > Dennis
> > >
0 Likes
Message 12 of 22

Anonymous
Not applicable
Thanks Frank, the (substr fn (+ (strlen (vl-filename-directory fn)) 2))
worked just fine!

Frank Oquendo wrote in message
news:[email protected]...
> You can use VL-FILENAME-BASE to strip the directory from a filename. It
also
> strips the extension though. If that's a problem, you can use something
like
> this to keep the extension (assuming the return value from GETFILED is
> stored in the variable fn):
>
> (substr fn (+ (strlen (vl-filename-directory fn)) 2))
>
> Or if you have the express tools, just use ACET-FILENAME-PATH-REMOVE
>
> --
> Get free software and more at:
> http://msnhomepages.talkcity.com/protectionfault/foquendo
>
> "Dennis S. Nunes" wrote in message
> news:[email protected]...
> > With AutoCAD 14, if I type the following at the command prompt:
> >
> > (setq a (getfiled "Select a Drawing file" "" "dwg" 8))
> >
> > I get the dialog box to select the file. As long as I do not change the
> > directory or folder
> > AutoCAD returns the filename that I selected with no path.
> >
> > If I do the exact same thing in AutoCAD 2000, I get the full path.
> >
> > How can I get the filename only?
> >
> > Thanks
> > Dennis
> >
> >
>
>
0 Likes
Message 13 of 22

Anonymous
Not applicable
No problem. Glad to help.

--
Get free software and more at:
http://msnhomepages.talkcity.com/protectionfault/foquendo

"Dennis S. Nunes" wrote in message
news:[email protected]...
> Thanks Frank, the (substr fn (+ (strlen (vl-filename-directory fn)) 2))
> worked just fine!
>
>
> Frank Oquendo wrote in message
> news:[email protected]...
> > You can use VL-FILENAME-BASE to strip the directory from a filename. It
> also
> > strips the extension though. If that's a problem, you can use something
> like
> > this to keep the extension (assuming the return value from GETFILED is
> > stored in the variable fn):
> >
> > (substr fn (+ (strlen (vl-filename-directory fn)) 2))
> >
> > Or if you have the express tools, just use ACET-FILENAME-PATH-REMOVE
> >
> > --
> > Get free software and more at:
> > http://msnhomepages.talkcity.com/protectionfault/foquendo
> >
> > "Dennis S. Nunes" wrote in message
> > news:[email protected]...
> > > With AutoCAD 14, if I type the following at the command prompt:
> > >
> > > (setq a (getfiled "Select a Drawing file" "" "dwg" 8))
> > >
> > > I get the dialog box to select the file. As long as I do not change
the
> > > directory or folder
> > > AutoCAD returns the filename that I selected with no path.
> > >
> > > If I do the exact same thing in AutoCAD 2000, I get the full path.
> > >
> > > How can I get the filename only?
> > >
> > > Thanks
> > > Dennis
> > >
> > >
> >
> >
>
>
0 Likes
Message 14 of 22

Anonymous
Not applicable
Where did you find that function anyway? It shows up in the Apropos window
but there's no documentation.

--
Get free software and more at:
http://msnhomepages.talkcity.com/protectionfault/foquendo

"Byron Blattel" wrote in message
news:[email protected]...
> No it returns the filename with extension. I just took his request
> literally.
>
> (strcat (cadr (fnsplitl a)) (caddr (fnsplitl a)))
>
> The point was that there is an AutoLISP function available for this
> (fnsplitl) at least since R14.
>
> Frank Oquendo wrote:
> >
> > Was that the behavior of GETFILED prior to A2K? I thought it returned a
> > "Whatever".3 filename if you selected from the initial directory.
> >
> > --
> > Get free software and more at:
> > http://msnhomepages.talkcity.com/protectionfault/foquendo
> >
> > "Byron Blattel" wrote in message
> > news:[email protected]...
> > > I believe he said he wanted the filename only, not the filename with
> > > extension 🙂
> > >
> > > Frank Oquendo wrote:
> > > >
> > > > That splits a path into three components: the directory, the file
base
> > and
> > > > the extension. I don't think that would help too much in this
particualt
> > > > case without concatenating the second and third items in the list.
> > >
> > >
> > >
> > > > > "Dennis S. Nunes" wrote:
> > > > > >
> > >
> > >
> > >
> > > > > > How can I get the filename only?
> > > > > >
> > > > > > Thanks
> > > > > > Dennis
> > > > >
>
> --
> |
> ----+----------------------------------------------
> | Byron Blattel
> | CADwerx---Applications for AutoCAD
> |
> | e-mail: [email protected]
> |
> |
0 Likes
Message 15 of 22

Anonymous
Not applicable
How did you know about that one!???

I search A2K help and found it only as a reference under atomlist-family -
in an example. Great function!

Thanks,
Mike

"Byron Blattel" wrote in message
news:[email protected]...
> No it returns the filename with extension. I just took his request
> literally.
>
> (strcat (cadr (fnsplitl a)) (caddr (fnsplitl a)))
>
> The point was that there is an AutoLISP function available for this
> (fnsplitl) at least since R14.
>
> Frank Oquendo wrote:
> >
> > Was that the behavior of GETFILED prior to A2K? I thought it returned a
> > "Whatever".3 filename if you selected from the initial directory.
> >
> > --
> > Get free software and more at:
> > http://msnhomepages.talkcity.com/protectionfault/foquendo
> >
> > "Byron Blattel" wrote in message
> > news:[email protected]...
> > > I believe he said he wanted the filename only, not the filename with
> > > extension 🙂
> > >
> > > Frank Oquendo wrote:
> > > >
> > > > That splits a path into three components: the directory, the file
base
> > and
> > > > the extension. I don't think that would help too much in this
particualt
> > > > case without concatenating the second and third items in the list.
> > >
> > >
> > >
> > > > > "Dennis S. Nunes" wrote:
> > > > > >
> > >
> > >
> > >
> > > > > > How can I get the filename only?
> > > > > >
> > > > > > Thanks
> > > > > > Dennis
> > > > >
>
> --
> |
> ----+----------------------------------------------
> | Byron Blattel
> | CADwerx---Applications for AutoCAD
> |
> | e-mail: [email protected]
> |
> |
0 Likes
Message 16 of 22

Anonymous
Not applicable
Don't recall, might have been Owen's site or maybe just playing around
with (atoms-family) 🙂

|
----+----------------------------------------------
| Byron Blattel
| CADwerx---Applications for AutoCAD
|
| e-mail: [email protected]
|
|
0 Likes
Message 17 of 22

Anonymous
Not applicable
David Doane wrote:

> Where did you come up with ACET-FILENAME-PATH-REMOVE, and how is it used?

This function is exported from 'acetutil.fas', not 'acetutil.arx'.

We've added a filename manipulation class to our ARX libraries, so we'll be
moving most of the '(acet-filename-...)' functions to 'acetutil.arx' (and
I'll update the documentation).
--
Frank Whaley
Autodesk, Inc.
[email protected]
http://www.autodesk.com/expresstools
Express Tools - Your wish is our (command ...)
0 Likes
Message 18 of 22

Anonymous
Not applicable
Well, ain't you the hotsy-totsy?

Like I've said before, if you're as tight with everything else as you are
with your code, when you break wind only the dogs can hear it.

So using your little tech-ni-que, and exhibit might look like:

;;;For drawing name only in any drawing directory:

(defun c:getfila ()
(if (setq a (getfiled "Select a Drawing file" "" "dwg" 8))
(progn
(while (wcmatch a "*[\\/]*") (setq a (substr a 2)))
(princ a)
)
(prompt "\nYou canceled. ")
)
(princ)
)

;;;For R14 behavior with GetFileD:

(defun c:getfilb ()
(if (setq a (getfiled "Select a Drawing file" "" "dwg" 8))
(progn
(if (wcmatch a (strcat (getvar "dwgprefix")"*"))
(while (wcmatch a "*[\\/]*") (setq a (substr a 2)))
)
(princ a)
)
(prompt "\nYou canceled. ")
)
(princ)
)

Of course you will probably cut that by two-thirds as well.

I'm goin' back to sleep .......
--
Dave D

Michael Puckett wrote in article
<[email protected]>...
> (defun strip-path (str)
> (if (wcmatch str "*[\\/]*") (strip-path (substr str 2)) str)
> )
>
> e.g.
>
> (strip-path "c:\\acad\\sample\\yadayadayada\\drawing.dwg")
>
> returns "drawing.dwg"
>
> __________________________________
>
> Michael Puckett
> [email protected]
> > Not < an Autodesk hall monitor.
> Imagination makes all things possible.
> __________________________________
>
> "Dennis S. Nunes" wrote in message
> news:[email protected]...
> With AutoCAD 14, if I type the following at the command prompt:
>
> (setq a (getfiled "Select a Drawing file" "" "dwg" 8))
>
> I get the dialog box to select the file. As long as I do not change the
> directory or folder
> AutoCAD returns the filename that I selected with no path.
>
> If I do the exact same thing in AutoCAD 2000, I get the full path.
>
> How can I get the filename only?
>
> Thanks
> Dennis
>
>
>
>
>
0 Likes
Message 19 of 22

Anonymous
Not applicable
I have the same version, but what the heck is an APROPOS window??

It does work as you described. Thanks for the tip.
--
Dave D

Frank Oquendo wrote in article
<[email protected]>...
> It shows up in my APROPOS window when I search on ACET. You just feed it
the
> full path and it returns only the filename: (acet-filename-path-remove
> (findfile "acad.exe")) yields "acad.exe" whereas findfile returns the
full
> path. I'm using ACETUTIL.ARX ver 1.35. You can check your version by
calling
> (acet-util-ver)
>
> --
> Get free software and more at:
> http://msnhomepages.talkcity.com/protectionfault/foquendo
>
>
> "David Doane" wrote in message
> news:01bf7002$9fb8d800$1d57d2d0@lms-1...
> > Frank,
> >
> > Where did you come up with ACET-FILENAME-PATH-REMOVE, and how is it
used?
> > It isn't in the listing that I have.
> > --
> > Dave D
0 Likes
Message 20 of 22

Anonymous
Not applicable
OK. Found the APROPOS window. Never use Vlide. I just saw another post
concerning it and took a look-see.
--
Dave

Frank Oquendo wrote in article
<[email protected]>...
> It shows up in my APROPOS window when I search on ACET. You just feed it
the
> full path and it returns only the filename: (acet-filename-path-remove
> (findfile "acad.exe")) yields "acad.exe" whereas findfile returns the
full
> path. I'm using ACETUTIL.ARX ver 1.35. You can check your version by
calling
> (acet-util-ver)
>
> --
> Get free software and more at:
> http://msnhomepages.talkcity.com/protectionfault/foquendo
>
>
> "David Doane" wrote in message
> news:01bf7002$9fb8d800$1d57d2d0@lms-1...
> > Frank,
> >
> > Where did you come up with ACET-FILENAME-PATH-REMOVE, and how is it
used?
> > It isn't in the listing that I have.
> > --
> > Dave D
0 Likes