Author Topic: How to get "dwgname" properly  (Read 2815 times)

0 Members and 1 Guest are viewing this topic.

MeasureUp

  • Bull Frog
  • Posts: 462
How to get "dwgname" properly
« on: July 16, 2014, 07:31:56 PM »
In my code, there are two lines:
Code: [Select]
(vl-load-com)
...
(vl-file-size (getvar "dwgname"))
It works fine until today...
The 2nd line now returns a "nil" instead of a file size.
I now find that I have to rewrite the 2nd line to this:
Code: [Select]
(vl-file-size (strcat (getvar 'DwgPrefix) (getvar "dwgname")))

I test this code by using
1) the same drawing file,
2) same location,
3) same PC,
4) same AutoCAD version (Mech 2014)
And there is no setup changes on my pc or AutoCAD.
The only difference is the time, it works find yesterday, but today.
All my other codes are loaded and work perfectly.

Your helps are much appreciated.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: How to get "dwgname" properly
« Reply #1 on: July 16, 2014, 08:57:00 PM »
Does this work?
Code: [Select]
(vl-file-size (vla-get-fullname (vla-get-ActiveDocument (vlax-get-acad-object))))
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Gasty

  • Newt
  • Posts: 90
Re: How to get "dwgname" properly
« Reply #2 on: July 16, 2014, 09:40:21 PM »
Hi,

This should work too:

(vl-file-size (findfile(getvar "dwgname")))

Gaston Nunez

MeasureUp

  • Bull Frog
  • Posts: 462
Re: How to get "dwgname" properly
« Reply #3 on: July 17, 2014, 01:12:03 AM »
Thanks to CAB & Gasty. Your codes work perfectly.

Actually my 2nd question was that why my code (shown below) worked OK previously and why today there is a problem:
Code: [Select]
(vl-file-size (getvar "dwgname"))

Thanks.

kpblc

  • Bull Frog
  • Posts: 396
Re: How to get "dwgname" properly
« Reply #4 on: July 17, 2014, 01:18:20 AM »
I think vl-file-size returns nil only if file exists and is read-only (by file attributes; not by access rights). You can try to copy your dwg to your %TEMP% folder and get filesize from copy.
Sorry for my English.

MeasureUp

  • Bull Frog
  • Posts: 462
Re: How to get "dwgname" properly
« Reply #5 on: July 17, 2014, 01:49:56 AM »
I think vl-file-size returns nil only if file exists and is read-only (by file attributes; not by access rights). You can try to copy your dwg to your %TEMP% folder and get filesize from copy.

Thanks for your reply.
The drawing file which I was referring to is fully accessible (it is not set to "read-only") and is in "C:\Users\MyName\Documents\".

To me, it should not be a problem - I can't figure it out.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: How to get "dwgname" properly
« Reply #6 on: July 17, 2014, 08:38:33 AM »
Hi,

This should work too:

(vl-file-size (findfile(getvar "dwgname")))

Gaston Nunez
Some caution here, if you have another file with the same name ACAD search may find it first & report unwanted information.
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

dgorsman

  • Water Moccasin
  • Posts: 2437
Re: How to get "dwgname" properly
« Reply #7 on: July 17, 2014, 10:20:21 AM »
Doesn't (findfile ...) check in the folder of the active drawing first?  If so, then since there are unique file name constraints inside folders the active drawing file is the *only* one which can be found.
If you are going to fly by the seat of your pants, expect friction burns.

try {GreatPower;}
   catch (notResponsible)
      {NextTime(PlanAhead);}
   finally
      {MasterBasics;}

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: How to get "dwgname" properly
« Reply #8 on: July 17, 2014, 10:35:24 AM »
I believe you are correct 8) I stand corrected.
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Lee Mac

  • Seagull
  • Posts: 12913
  • London, England
Re: How to get "dwgname" properly
« Reply #9 on: July 17, 2014, 01:23:29 PM »
Actually my 2nd question was that why my code (shown below) worked OK previously and why today there is a problem:
Code: [Select]
(vl-file-size (getvar "dwgname"))

The vl-file-size function does not perform in the same way as the findfile function when supplied with a filename without a filepath, as stated in the documentation:
Quote
If you do not specify a full path name, vl-file-size searches the AutoCAD default drawing directory for the file.

The default drawing directory is not necessary equal to the working directory (DWGPREFIX); the default drawing directory is usually the My Documents folder.

MeasureUp

  • Bull Frog
  • Posts: 462
Re: How to get "dwgname" properly
« Reply #10 on: July 17, 2014, 10:47:38 PM »
Before looking to your replies I think I got into another problem:
When I loaded this code today I found there is a problem with this line:
Code: [Select]
(getenv 'computername)It returns a message of "; error: bad argument type: stringp COMPUTERNAME"
I simply paste the above line to the command line and I get the same result.

Again, it works fine all time but today!
It now only works when it is rewritten as:
Code: [Select]
(getenv "computername")
What is wrong?

PS. I think the answer to this may also solve all my questions in this thread.
« Last Edit: July 18, 2014, 12:01:44 AM by MeasureUp »

Gasty

  • Newt
  • Posts: 90
Re: How to get "dwgname" properly
« Reply #11 on: July 18, 2014, 12:54:01 AM »
Hi,

As the doc says, the argument for getenv and getvar it's a string, so the correct way to call them it's:

(getenv "EnvVar") ; Enviroment variables are usually case sensitive, so take care of that

As for getvar, you can use a quoted system variable name like (getvar 'DWGPREFIX) or a string literal like (getvar "DWGPREFIX") Autocad sys vars are not case sensitive. My preference goes to the last as a quote have a special meaning in lisp. and in Autocad means transparent command.

Gaston Nunez


MeasureUp

  • Bull Frog
  • Posts: 462
Re: How to get "dwgname" properly
« Reply #12 on: July 25, 2014, 01:53:02 AM »
Thanks to everyone's help for getting the file path. I was too busy this week... just have done a project GA drawing.
I forgot that the Enviroment variables are case sensitive.
As Gaston seggusted, I will use double quote for both of S.V. and E.V.
Cheers!