+ Reply to Thread
Page 1 of 2 1 2 LastLast
Results 1 to 10 of 11
  1. #1
    Forum Newbie
    Using
    AutoCAD 2009
    Join Date
    Sep 2015
    Posts
    5

    Default Problem using variable within Script (.scr)

    Registered forum members do not see this ad.

    Hi, this is my first post on the forum & I'm also pretty new to AutoCAD scripts & Lisp routines, so please bear with me.

    Basically I have the following script:

    (setq dn (strcat (getvar "dwgprefix") "New Drawing.dwg"))
    (vl-propagate 'dn)
    _.saveas 2010 !dn

    This script saves my current drawing as 'New Drawing.dwg' within my current directory, and works fine.
    When I try to modify the script to the following, which attempts to open instead instead of save, it doesn't work, just prompts for drawing name: -

    (setq dn (strcat (getvar "dwgprefix") "New Drawing.dwg"))
    (vl-propagate 'dn)
    _.open !dn

    The saveas & open dialogues look very similar, so please could someone explain why I can reference a variable for the _.saveas filename, but not for the _.open filename, or have I got the syntax completely wrong for the _.open command?

  2. #2
    Super Member rlx's Avatar
    Computer Details
    rlx's Computer Details
    Operating System:
    W10
    Computer:
    i74ghz/ssd500/2tbhdd
    Discipline
    Electrical
    rlx's Discipline Details
    Occupation
    electrical designer dragon
    Discipline
    Electrical
    Details
    I dont excel in anything but I rearly give up
    Using
    AutoCAD 2016
    Join Date
    Nov 2014
    Location
    Bergen op Zoom , Netherlands
    Posts
    637

    Default

    you could try (setvar "filedia" 0) before the open command (disable file dialog's ) just put it back on (setvar "filedia" 1) when your finished (just good housekeeping)

    gr.Rlx

  3. #3
    Forum Newbie
    Using
    AutoCAD 2009
    Join Date
    Sep 2015
    Posts
    5

    Default

    Quote Originally Posted by rlx View Post
    you could try (setvar "filedia" 0) before the open command (disable file dialog's ) just put it back on (setvar "filedia" 1) when your finished (just good housekeeping)

    gr.Rlx
    rlx, many thanks for your reply, but no joy, I still just get the prompt 'Enter name of drawing to open' when I run the amended script (below): -

    (setq dn (strcat (getvar "dwgprefix") "New Drawing.dwg"))
    (vl-propagate 'dn)
    (setvar "filedia" 0)
    _.open !dn

    Any other ideas?

  4. #4
    Senior Member jonathann3891's Avatar
    Computer Details
    jonathann3891's Computer Details
    Operating System:
    Window 7 64 Bit
    Discipline
    Structural
    jonathann3891's Discipline Details
    Occupation
    Oil & Gas
    Discipline
    Structural
    Using
    AutoCAD 2012
    Join Date
    Dec 2008
    Location
    Houston, TX
    Posts
    126

    Default

    This lisp will fail if the drawing your running the script from is not saved in the same directory as "New Drawing"

  5. #5
    Super Member rlx's Avatar
    Computer Details
    rlx's Computer Details
    Operating System:
    W10
    Computer:
    i74ghz/ssd500/2tbhdd
    Discipline
    Electrical
    rlx's Discipline Details
    Occupation
    electrical designer dragon
    Discipline
    Electrical
    Details
    I dont excel in anything but I rearly give up
    Using
    AutoCAD 2016
    Join Date
    Nov 2014
    Location
    Bergen op Zoom , Netherlands
    Posts
    637

    Default

    I've written a batch generator for plotting and scripts and there I use the following

    Code:
    (progn
          (write-line "._Open" fp)
          ;indien van toepassing 'do U wish 2 save changes?'
          (setq cmd "(if (> (getvar \"dbmod\") 0)(command\"yes\"))")
          (write-line  cmd fp)
          (write-line (strcat "(command \""  item "\"))") fp)
          ;indien de te openen tekening read-only is extra enter
          (setq cmd "(while (wcmatch (getvar \"cmdnames\") \"*OPEN*\")(command \"\"))")
          (write-line cmd fp)
        )
    I have an example for the scriptfile itself at work so i'll post that tomorrow

    simply put , when you open a file , if the current drawing needs saving , autocad will ask , do you want to save the current drawing before i open the next dring. Your script has to be prepared for that and add an extra yes or no before it can open the next drawing.



    gr.Rlx

  6. #6
    Forum Newbie
    Using
    AutoCAD 2009
    Join Date
    Sep 2015
    Posts
    5

    Default

    Quote Originally Posted by jonathann3891 View Post
    This lisp will fail if the drawing your running the script from is not saved in the same directory as "New Drawing"
    The open/current drawing at the time I run the script is saved in the same directory as "New Drawing".
    I would expect an error if I tried to run the script from a drawing in a different location, as 'dwgprefix' would report this different location.

  7. #7
    Forum Newbie
    Using
    AutoCAD 2009
    Join Date
    Sep 2015
    Posts
    5

    Default

    Quote Originally Posted by rlx View Post
    I've written a batch generator for plotting and scripts and there I use the following

    Code:
    (progn
          (write-line "._Open" fp)
          ;indien van toepassing 'do U wish 2 save changes?'
          (setq cmd "(if (> (getvar \"dbmod\") 0)(command\"yes\"))")
          (write-line  cmd fp)
          (write-line (strcat "(command \""  item "\"))") fp)
          ;indien de te openen tekening read-only is extra enter
          (setq cmd "(while (wcmatch (getvar \"cmdnames\") \"*OPEN*\")(command \"\"))")
          (write-line cmd fp)
        )
    I have an example for the scriptfile itself at work so i'll post that tomorrow

    simply put , when you open a file , if the current drawing needs saving , autocad will ask , do you want to save the current drawing before i open the next dring. Your script has to be prepared for that and add an extra yes or no before it can open the next drawing.



    gr.Rlx
    Thanks rlx, but I have tried on a drawing without any changes (no save required), and have also tried adding the double space after the open command to accept any prompts automatically, so the script does not stall as you suggested.
    I can't get my head around why '_.saveas 2010 !dn ' works fine, but '_.open !dn ' doesn't?

  8. #8
    Super Member rlx's Avatar
    Computer Details
    rlx's Computer Details
    Operating System:
    W10
    Computer:
    i74ghz/ssd500/2tbhdd
    Discipline
    Electrical
    rlx's Discipline Details
    Occupation
    electrical designer dragon
    Discipline
    Electrical
    Details
    I dont excel in anything but I rearly give up
    Using
    AutoCAD 2016
    Join Date
    Nov 2014
    Location
    Bergen op Zoom , Netherlands
    Posts
    637

    Default

    I've started my batch programm ages ago and still i dont feel like i'm in control so dont feel bad ;-). Maybe you could give some more info about what exactly you try to achieve. Awell , for now i'll finish my wine and go to bed and i'll be back with you 2morrow

    gr.Rlx

  9. #9
    Super Member rlx's Avatar
    Computer Details
    rlx's Computer Details
    Operating System:
    W10
    Computer:
    i74ghz/ssd500/2tbhdd
    Discipline
    Electrical
    rlx's Discipline Details
    Occupation
    electrical designer dragon
    Discipline
    Electrical
    Details
    I dont excel in anything but I rearly give up
    Using
    AutoCAD 2016
    Join Date
    Nov 2014
    Location
    Bergen op Zoom , Netherlands
    Posts
    637

    Default

    here is a random part form a script that was generated to plot sa bunch of drawings


    Code:
    ._Open
    (if (> (getvar "dbmod") 0)(command"yes"))
    (command "e:/project/010626_lxv/0400/output lg/04ldk000403cs0001.dwg"))
    (while (wcmatch (getvar "cmdnames") "*OPEN*")(command ""))
    (load "RlPrint")
    rlprint
    \\spboz003\PBOZ0012
    A4 (210 x 297 mm)
    BlackSmall.ctb
    ._Open
    (if (> (getvar "dbmod") 0)(command"yes"))
    (command "e:/project/010626_lxv/0400/output lg/04ldk000403ds0001.dwg"))
    (while (wcmatch (getvar "cmdnames") "*OPEN*")(command ""))
    (load "RlPrint")
    rlprint
    \\spboz003\PBOZ0012
    A4 (210 x 297 mm)
    BlackSmall.ctb
    ._Open
    etc

    it opens a drawing , if current drawing needs saving it gives an axtra "yes". Next it gives the filename of the next drawing to be opened. It can happen that a drawing is read-only so while the open command is active it gives a return. Then it loads and runsmy print routine. The drawing is not saved when done plotting so i directly move on to open the nex drawing.


    This all works fine when sdi=1. if it is zero i use a different approach.


    When your script doesn't work , can you see at what point it stops? If you use vl-propagate you assume vl-load is loaded at all times. Is this true? you also assume setvar 'texteval' is on. You could try (eval dn)


    Just some thoughts from a simple dragon :-)


    well , back to work for me. Hope this helps or another user has some tips to help you on your way.


    gr. R.

  10. #10
    Forum Newbie
    Using
    AutoCAD 2009
    Join Date
    Sep 2015
    Posts
    5

    Default

    Registered forum members do not see this ad.

    rlx, you are a star!

    By setting 'texteval' to '1', and adding an extra space after the variable '!dn' with the open command, the script works correctly.
    After a bit of testing, I can confirm it was definitely the 'texteval' being set to '0' (default?) instead of '1', that was causing me issues.

    Many thanks for your help, much appreciated!

    Regards
    Ashley

Similar Threads

  1. Problem with variable restoration
    By woodman78 in forum AutoLISP, Visual LISP & DCL
    Replies: 11
    Last Post: 13th Jun 2015, 03:44 pm
  2. Need quick help adding variable to script startup! THX
    By tmelancon in forum AutoLISP, Visual LISP & DCL
    Replies: 9
    Last Post: 17th Jan 2014, 01:34 pm
  3. Calling a variable from a Script?
    By DEG in forum The CUI, Hatches, Linetypes, Scripts & Macros
    Replies: 9
    Last Post: 8th Dec 2012, 10:11 pm
  4. pls help...how to use variable in script
    By nids_1978 in forum AutoLISP, Visual LISP & DCL
    Replies: 5
    Last Post: 7th Jun 2010, 12:35 pm
  5. Variable in Script
    By Freerefill in forum AutoLISP, Visual LISP & DCL
    Replies: 15
    Last Post: 18th Sep 2009, 01:09 pm

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts