Jump to content

Recommended Posts

Posted

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?

Posted

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

Posted
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?

Posted

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

Posted

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

 

(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

Posted
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.

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

 

(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?

Posted

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

Posted

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

 

 

._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
[url="file://spboz003/PBOZ0012"]\\spboz003\PBOZ0012[/url]
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
[url="file://spboz003/PBOZ0012"]\\spboz003\PBOZ0012[/url]
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.

Posted

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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...