DWGNAME ANOMALY?

Discussion in 'AutoCAD' started by justindavidwerner, Mar 21, 2005.

  1. I type (getvar "DWGNAME") and AutoCAD 2004 command line returns "Drawing1.dwg"
    I type (= DWGNAME "Drawing1.dwg") and it returns nil.

    What the hell?

    p.s. typing (/= DWGNAME "Drawing1.dwg") returns T

    What is the DWGNAME for a brand new drawing?
     
    justindavidwerner, Mar 21, 2005
    #1
  2. justindavidwerner

    Jim Claypool Guest

    try (= (getvar "DWGNAME") "Drawing1.dwg")
     
    Jim Claypool, Mar 21, 2005
    #2
  3. justindavidwerner

    Shane-W Guest

    (= (getvar 'DwgName) "Drawing1.dwg")
     
    Shane-W, Mar 21, 2005
    #3
  4. justindavidwerner

    Jeff Mishler Guest

    _$ (getvar "dwgname")
    "base-ip.dwg"
    _$ (= dwgname "base-ip.dwg")
    nil
    _$ (setq dwgname (getvar "dwgname"))
    "base-ip.dwg"
    _$ (= dwgname "base-ip.dwg")
    T
    _$
     
    Jeff Mishler, Mar 21, 2005
    #4
  5. justindavidwerner

    ECCAD Guest

    And to 'insulate' against Upper / Lower Case.. do:
    (if (= (strcase (getvar "dwgname")) "DRAWING1.DWG")
    (progn
    ...... do whatever

    And to guard against 'Drawing2.dwg'.. etc.
    Do:
    (if (= (strcase (substr (getvar "dwgname") 1 7)) "DRAWING")
    (progn
    ...... do whatever


    Bob
     
    ECCAD, Mar 21, 2005
    #5
  6. justindavidwerner

    Shane-W Guest

    additionally to get a value into a variable name you must use the syntax:

    (setq DWG_Name (getvar 'DWGName))

    Also you cannot use protected names for variables such as
    (setq DWGName (getvar 'DWGName))

    Also I think its a good idea when working with strings to convert them to all uppercase because (/= "a" "A") using (strcase String) for all uppercase
    and
    (strcase String T) for all lowercase

    so finally:


    (setq DWG_Name (strcase (getvar 'DWGName)))
    (= DWG_Name (strcase (getvar 'DWGName)))
    would return T
     
    Shane-W, Mar 21, 2005
    #6
  7. Thank you all for the quick responses.
    That's all I needed I think. I appreciate it.
     
    justindavidwerner, Mar 21, 2005
    #7
  8. OK
    I thought that would be it but I guess not.
    I've written the following into a script:

    LISPINIT 0
    ACADLSPASDOC 0
    (
    (setq DWGN (substr (getvar 'DWGNAME) 1 7))
    (if (= DWGN "Drawing")
    (PROGN
    (COMMAND "FILEDIA" 0)
    (COMMAND "NEW" "y" "D-JOBNO-0G1.1.DWT")
    )
    (PROGN
    (COMMAND "QSAVE")
    (COMMAND "FILEDIA" 0)
    (COMMAND "NEW" "D-JOBNO-0G1.1.DWT")
    )

    )
    )
    (load"G-CREATE") G-CREATE


    The problem is, is that even in a blank drawing (drawing1) the lisp routine is executing the 2nd part even though the 1st part is true. If I put the following on the command line:

    (setq DWGN (substr (getvar 'DWGNAME) 1 7))

    and then (if (= DWGN "Drawing")

    it returns true. So why is it executing the 2nd part?
     
    justindavidwerner, Mar 21, 2005
    #8
  9. Nevermind

    It looks like removing the quotations from "drawing" in the line:

    (if (= DWGN Drawing)

    solved the problem.
     
    justindavidwerner, Mar 21, 2005
    #9
  10. I take it back it didn't solve the problem.
    Help!
     
    justindavidwerner, Mar 21, 2005
    #10
  11. justindavidwerner

    Jeff Mishler Guest

    Although I don't use scripts, I believe that EVERY line in a script is
    evaluated. To run lisp code like this, I think you will need to create a
    lisp file that you can then load and run from the script.
     
    Jeff Mishler, Mar 21, 2005
    #11
  12. I've done what you suggested and this actually causes it to work less. At least before it would do what I wanted albeit not exactly. NOw the template doesn't even come up.
     
    justindavidwerner, Mar 21, 2005
    #12
  13. justindavidwerner

    Murph Guest

    Just what are you wanting? There maybe a way some one can solve the problem
    if we knew just what you are trying to do.

    Murph


    least before it would do what I wanted albeit not exactly. NOw the template
    doesn't even come up.
     
    Murph, Mar 21, 2005
    #13
  14. ps

    The only reason it works is because I have a lisp routine that when you press 0, the layer 0 is made current. As a result I keep getting drawings named FILEDIA.dwg showing up on the server. So it works fine either way once thru (as it creates FILEDIA.dwg) but once I try it again it wants to overwrite FILEDIA.dwg.
     
    justindavidwerner, Mar 21, 2005
    #14
  15. justindavidwerner

    Tom Smith Guest

    To run lisp code like this, I think you will need to create a
    lisp file that you can then load and run from the script.

    No. Althought that would be a good solution, you can put anything in a script that you can type at the command line, including lisp expressions. You can mix and mingle Acad commands and lisp expressions, as long as they would be legal if you typed them manually.

    I normally do things with lisp, and only run scripts when I'm batch processing many drawings. Usually I write a lisp to do the task, then use a script to load and run the lisp.
     
    Tom Smith, Mar 21, 2005
    #15
  16. justindavidwerner

    Tom Smith Guest

    additionally to get a value into a variable name you must use the syntax: (setq DWG_Name (getvar 'DWGName))

    Wrong, that can't work The variable is "dwgname" -- a string -- and you don't use the (quote) function to retrieve a variable. Try (setq DWG_Name (getvar "'dwgname")).
    A good rule, but you're misquoting it.

    Acad variables are not "protected names" as far as lisp is concerned. You should never use the names of built-in lisp suymbols such as T or distance. These names are "reserved" for use by the language and you'll cause problems by stomping on them.

    But DWGNAME is not a symbol known to lisp, so it's fair game. Granted you might want to distinguish between Your variables and theirs, just for clarity, but no harm will be caused by using any symbol name which is not part of the lisp language.
     
    Tom Smith, Mar 21, 2005
    #16
  17. justindavidwerner

    Doug Broad Guest

    Hi Tom,

    My first thought was that it wouldn't work either but
    (getvar 'dwgname) does work. Go figure.


    (quote) function to retrieve a variable. Try (setq DWG_Name (getvar "'dwgname")).
     
    Doug Broad, Mar 21, 2005
    #17
  18. yes.

    it is the same as reading or applying properties with vlisp...

    _$ (vlax-get-property obj 'startpoint)
    #<variant 8197 ...>
    _$ (vlax-get-property obj "startpoint")
    #<variant 8197 ...>
     
    Luis Esquivel, Mar 21, 2005
    #18
  19. justindavidwerner

    Shane-W Guest

    Yes true , shoulda used reserved or whatever , point was to keep your code as unconfusing as possible and avoid using common names for your variables.
    you can get all setvar/getvars with 'VarName

    snippy this morning are we ?
    :)
     
    Shane-W, Mar 21, 2005
    #19
  20. justindavidwerner

    Doug Broad Guest

    Hi Luis,
    How're things going? We just made an offer on a house and it was
    accepted so it looks like we're going to be moving.
    Regards,
    Doug
     
    Doug Broad, Mar 21, 2005
    #20
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.