Author Topic: Return current drawing name from the command prompt  (Read 8230 times)

0 Members and 1 Guest are viewing this topic.

Andrew H

  • Guest
Return current drawing name from the command prompt
« on: July 19, 2004, 04:50:55 PM »
How do you return the current drawing name to the command prompt for use in a script file? Does anyone have a lisp that will do this, or is there a simple variable AutoCAD already stores that can be used to get this?

Example

Current drawings name = drawing1.dwg

I want to be able to issue a command via script to return this drawing name, but I want to be able to delete/not include the .dwg extension and type in my own extension as in .txt etc... Is this possible? I also need to type in the save path as in C:/drawing txt files, which the current drawing location may or may not be in that location and have the current drawing (drawing1.txt) be in that location.

C:/drawing txt files/drawing1.txt



I'm trying to learn how to write my own lisp and script files, so I only want as little help with this as possible. I think I have all the other information I need for writing my script file, but I have to have the above mentioned information before I can move on. Thanks to all the gurus in advance.

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
Return current drawing name from the command prompt
« Reply #1 on: July 19, 2004, 05:03:53 PM »
Look at the vl-filename-* functions.

(vl-filename-base filename)
Quote

Returns the name of a file, after stripping out the directory path and extension

(vl-filename-base filename)

Quote

Returns the directory path of a file, after stripping out the name and extension

(vl-filename-directory filename)

Quote

Returns the extension from a file name, after stripping out the rest of the name

(vl-filename-extension filename)


You system variables are DWGNAME, DWGPREFIX and DWGTITLED
TheSwamp.org  (serving the CAD community since 2003)

Andrew H

  • Guest
Return current drawing name from the command prompt
« Reply #2 on: July 19, 2004, 05:20:01 PM »
vl-filename-* functions?

Please note: I really appreciate the help, but I am a complete newbie to these hidden commands (commands used to write lisps and scripts) and have no idea what all commands are. Where would I look to get a look at all these types of commands?

If I understand you correctly then:

I would use the "DWGNAME" command in the script file to return the drawing name without the path or extension?

I would use the "DWGPREFIX" command in the script file to return the drawing name without the extension only (will still include the drawing path)?

I would use the "DWGTITLED" command in the script file to return the drawing name with the path and extension?


script file might look something like this (while using a stand alone program that would take care of all the filedia 0 and opening the multiple drawings, etc...):

(setq tempdwgname (DWGNAME))
C:/Drawing Text Files/(getvar (tempdwgname).txt

If I'm close, then I at least understand the concepts and just need to learn the usage of the commands you listed, but if I'm way off then I really need some major help.

Thanks for the info thus far.

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
Return current drawing name from the command prompt
« Reply #3 on: July 19, 2004, 05:40:05 PM »
I'm not sure where you're going with this but.........

here's a simple function that returns the current dwg name _if_ it has been saved.
Code: [Select]

(defun get-dwgname ()
  (if (= (getvar 'dwgtitled) 1)
    (vl-filename-base (getvar 'dwgname))
    )
  )

You could call this from your script, assuming the the .lsp has been loaded like so.
(setq dn (get-dwgname))
Quote

Command: (setq dn (get-dwgname))
"new_drawing"


Look up the above mentioned variables in the acad help.
TheSwamp.org  (serving the CAD community since 2003)

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Return current drawing name from the command prompt
« Reply #4 on: July 19, 2004, 06:03:30 PM »
In addition to the excellent info already posted I offer this for you to examine and play with:

Code: [Select]
(apply 'strcat
    (mapcar 'getvar
       '(dwgprefix dwgname)
    )
)


Cheers.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

Andrew H

  • Guest
Return current drawing name from the command prompt
« Reply #5 on: July 19, 2004, 06:09:35 PM »
MP...
That returns the current drawing name and path and extension (but I noticed the / in the return = //) Why?



Mark Thomas...
Thank you for all the help. This should get me going again.

I was having trouble figuring out the fact I needed to call in a lisp from my script file.

In my script file can I include the lisp and load it without having to do that from the command prompt before running the script (this may have been your original intent, but I'm still learning) or would it be easier to create the lisp as a command and load it into the startup suite of the ap command?

inmyscriptfile.scr
{everything before this would be whatever the command is asking for before it asked for the new file name and path}
(defun get-dwgname ()
   (if (= (getvar "dwgtitled) 1)
      (vl-filename-base (getvar "dwgname"))
      )
   )
(setq dn (get-dwgname))
"new_drawing"


When I get to the part of the command where it's asking for the new file name (including the new extension and path) how would I retrieve the above mentioned functions which would then include my desired path and extension?

I.E. C:/Drawing Text Files/Drawing1.txt (which would be from a drawing originally named Drawing1.dwg) This path and extension would be used all the time, but the file name would update according to which drawing is open. If drawing Drawing2.dwg was open the file name would be Drawing2.txt and would be located in the C:/Drawing Text Files/ folder, and Drawing3.dwg would equal Drawing3.txt and Andrew.dwg would equal Andrew.txt, etc…etc...

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
Return current drawing name from the command prompt
« Reply #6 on: July 19, 2004, 06:28:32 PM »
Ok, I think I see what you're after now. In your script add this code.
Code: [Select]

(strcat
  "C:/Drawing Text Files/"
  (vl-filename-base (getvar 'dwgname))
  ".txt")


it will return "C:/Drawing Text Files/<current dwg name>.txt"
TheSwamp.org  (serving the CAD community since 2003)

DEVITG

  • Bull Frog
  • Posts: 481
Return current drawing name from the command prompt
« Reply #7 on: July 20, 2004, 09:53:11 PM »
how about the Vl load com????
Location @ Córdoba Argentina Using ACAD 2019  at Window 10