Jump to content

Recommended Posts

Posted

I am not as good as lee in any way shape or form but try this. Changin what you need as far as dxf and your lisp

 

(defun c:rscr (/ wfile rfile ofile)
 (if (and (setq wfile (getfiled "\nSelect File to Write to: " "" "scr" 1))
          (setq rfile (getfiled "\nSelect File from Directory to Read: " "" "dwg" ))
   (progn
     (setq dir (vl-filename-directory rfile))
     (setq ofile (open wfile "w"))
     (foreach x (vl-directory-files (vl-filename-directory rfile) "*.dwg" 1)
       (write-line (strcat "open " dir "\\" x  " (load \"mylisp\") (c:mylisp) close \"Y\"") ofile))
     (close ofile))
   (princ "\n<!> File Selection Error <!>"))
 (princ))

  • Replies 51
  • Created
  • Last Reply

Top Posters In This Topic

  • Lee Mac

    20

  • Commandobill

    12

  • au-s

    5

  • Rsteel13

    4

Posted

Very nice idea Commando,

 

but I think maybe:

 

[b][color=RED]([/color][/b][b][color=BLUE]defun[/color][/b] c:rscr [b][color=RED]([/color][/b][b][color=BLUE]/[/color][/b] wfile rfile ofile dir[b][color=RED])[/color][/b]
 [b][color=RED]([/color][/b][b][color=BLUE]if[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]and[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] wfile [b][color=RED]([/color][/b][b][color=BLUE]getfiled[/color][/b] [b][color=#ff00ff]"\nSelect File to Write to: "[/color][/b] [b][color=#ff00ff]""[/color][/b] [b][color=#ff00ff]"scr"[/color][/b] [b][color=#009900]1[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]
          [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] rfile [b][color=RED]([/color][/b][b][color=BLUE]getfiled[/color][/b] [b][color=#ff00ff]"\nSelect File from Directory to Read: "[/color][/b] [b][color=#ff00ff]""[/color][/b] [b][color=#ff00ff]"dwg"[/color][/b] [b][color=#009900]8[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]
   [b][color=RED]([/color][/b][b][color=BLUE]progn[/color][/b]
     [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] ofile [b][color=RED]([/color][/b][b][color=BLUE]open[/color][/b] wfile [b][color=#ff00ff]"w"[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]
     [b][color=RED]([/color][/b][b][color=BLUE]foreach[/color][/b] x [b][color=RED]([/color][/b][b][color=BLUE]vl-directory-files[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] dir [b][color=RED]([/color][/b][b][color=BLUE]vl-filename-directory[/color][/b] rfile[b][color=RED])[/color][/b][b][color=RED])[/color][/b] [b][color=#ff00ff]"*.dwg"[/color][/b] [b][color=#009900]1[/color][/b][b][color=RED])[/color][/b]
       [b][color=RED]([/color][/b][b][color=BLUE]write-line[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]strcat[/color][/b] [b][color=#ff00ff]"open "[/color][/b] dir [b][color=#ff00ff]"\\"[/color][/b] x  [b][color=#ff00ff]" (load \"[/color][/b]mylisp\[b][color=#ff00ff]") (c:mylisp) close \"[/color][/b]Y\[b][color=#ff00ff]""[/color][/b][b][color=RED])[/color][/b] ofile[b][color=RED])[/color][/b][b][color=RED])[/color][/b]
     [b][color=RED]([/color][/b][b][color=BLUE]close[/color][/b] ofile[b][color=RED])[/color][/b][b][color=RED])[/color][/b]
   [b][color=RED]([/color][/b][b][color=BLUE]princ[/color][/b] [b][color=#ff00ff]"\n<!> File Selection Error <!>"[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]
 [b][color=RED]([/color][/b][b][color=BLUE]princ[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]

Posted

Yes... i realized my mistake after putting it on the board.... thank you. Also you could have the routine run the script so he doesn't have to type it out....

Posted
Also you could have the routine run the script so he doesn't have to type it out....

 

What do you mean? Like use the (command "_script" ... ?

Posted
What do you mean? Like use the (command "_script" ... ?

 

 

I finally finished the code... sigh. We both forgot that the file needs "quotation" lol. and yes.

 

(defun c:rscr (/ wfile rfile ofile dir)
 (if (and (setq wfile (getfiled "\nSelect File to Write to: " "" "scr" 1))
          (setq rfile (getfiled "\nSelect File from Directory to Read: " "" "dwg" ))
   (progn
     (setq ofile (open wfile "w"))
     (foreach x (vl-directory-files (setq dir (vl-filename-directory rfile)) "*.dwg" 1)
       (write-line (strcat "open " "\"" dir "\\" x  " ""\" (load \"mylisp\") (c:mylisp) close \"Y\"") ofile))
     (close ofile))
   (princ "\n<!> File Selection Error <!>"))
 (command "script" wfile)
 (princ))

 

you like?

Posted

Almost, I think:

 

[b][color=RED]([/color][/b][b][color=BLUE]defun[/color][/b] c:rscr [b][color=RED]([/color][/b][b][color=BLUE]/[/color][/b] wfile rfile ofile dir[b][color=RED])[/color][/b]
 [b][color=RED]([/color][/b][b][color=BLUE]if[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]and[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] wfile [b][color=RED]([/color][/b][b][color=BLUE]getfiled[/color][/b] [b][color=#ff00ff]"\nSelect File to Write to: "[/color][/b] [b][color=#ff00ff]""[/color][/b] [b][color=#ff00ff]"scr"[/color][/b] [b][color=#009900]1[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]
          [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] rfile [b][color=RED]([/color][/b][b][color=BLUE]getfiled[/color][/b] [b][color=#ff00ff]"\nSelect File from Directory to Read: "[/color][/b] [b][color=#ff00ff]""[/color][/b] [b][color=#ff00ff]"dwg"[/color][/b] [b][color=#009900]8[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]
   [b][color=RED]([/color][/b][b][color=BLUE]progn[/color][/b]
     [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] ofile [b][color=RED]([/color][/b][b][color=BLUE]open[/color][/b] wfile [b][color=#ff00ff]"w"[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]
     [b][color=RED]([/color][/b][b][color=BLUE]foreach[/color][/b] x [b][color=RED]([/color][/b][b][color=BLUE]vl-directory-files[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] dir [b][color=RED]([/color][/b][b][color=BLUE]vl-filename-directory[/color][/b] rfile[b][color=RED])[/color][/b][b][color=RED])[/color][/b] [b][color=#ff00ff]"*.dwg"[/color][/b] [b][color=#009900]1[/color][/b][b][color=RED])[/color][/b]
       [b][color=RED]([/color][/b][b][color=BLUE]write-line[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]strcat[/color][/b] [b][color=#ff00ff]"open "[/color][/b] [b][color=#ff00ff]"\"[/color][/b][b][color=#ff00ff]" dir "[/color][/b]\\[b][color=#ff00ff]" x  "[/color][/b]\[b][color=#ff00ff]""[/color][/b] [b][color=#ff00ff]"(load \"[/color][/b]mylisp\[b][color=#ff00ff]") (c:mylisp) close \"[/color][/b]Y\[b][color=#ff00ff]""[/color][/b][b][color=RED])[/color][/b] ofile[b][color=RED])[/color][/b][b][color=RED])[/color][/b]
     [b][color=RED]([/color][/b][b][color=BLUE]close[/color][/b] ofile[b][color=RED])[/color][/b][b][color=RED])[/color][/b]
   [b][color=RED]([/color][/b][b][color=BLUE]princ[/color][/b] [b][color=#ff00ff]"\n<!> File Selection Error <!>"[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]
 [b][color=RED]([/color][/b][b][color=BLUE]command[/color][/b] [b][color=#ff00ff]"script"[/color][/b] wfile[b][color=RED])[/color][/b]
 [b][color=RED]([/color][/b][b][color=BLUE]princ[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]

Posted

I have a problem... I have modified the lisp you guys made to run a script instead of a lisp.

 

(defun c:rscr (/ wfile rfile ofile dir)
 (if (and (setq wfile (getfiled "\nSelect File to Write to: " "" "scr" 1))
          (setq runfile (getfiled "\nSelect Script to run: " "" "scr" )
          (setq rfile (getfiled "\nSelect File from Directory to Read: " "" "dwg" ))
   (progn
     (setq ofile (open wfile "w"))
     (foreach x (vl-directory-files (setq dir (vl-filename-directory rfile)) "*.dwg" 1)
       (write-line (strcat "open " "\"" dir "\\" x  "\"" " (setq runfile \"" runfile "\")"
       " (command \"script\" runfile) " "close \"Y\"") ofile))
     (close ofile))
   (princ "\n<!> File Selection Error <!>"))
 (command "script" wfile)
 (princ))

 

The only problem is when it tries to run the runfile script all of the \ in the directory list are gone so it searches for the file with no \ and says can't find file any ideas?

Posted

Well for starters your flag for getfiled was wrong in the settings for runfile. It only returned the file name not the directory. Then your script was trying to use (command) when a script writes to the command line already thus being useless and removing the forward slashes.

 

(defun c:rscr (/ wfile rfile ofile dir)
 (if (and (setq wfile (getfiled "\nSelect File to Write to: " "" "scr" 1))
          (setq runfile (getfiled "\nSelect Script to run: " "" "scr" 3))
          (setq rfile (getfiled "\nSelect File from Directory to Read: " "" "dwg" ))
   (progn
     (setq ofile (open wfile "w"))
     (foreach x (vl-directory-files (setq dir (vl-filename-directory rfile)) "*.dwg" 1)
       (write-line (strcat "open " "\"" dir "\\" x  "\"" 
       " script " "\"" runfile "\"" " " "close \"Y\"") ofile))
     (close ofile))
   (princ "\n<!> File Selection Error <!>"))
 (command "script" wfile)
 (princ))

Posted

set the runfile (getfiled) flag to 0 if you dont want the warning message to pop up

Posted

Sorry, haven't we gone a bit off track here guys - why are we writing to run the script within the script that we are trying to run?

Posted

I guess your right It is a little far off the original topic, just my own side track.

Posted

I was just curious as to why you would want to write the script running into this.

 

imo, I would keep the running of the script separate from its creation.

 

Scripts and LISP don't mix too well, and for the time it takes to run the script manually through ACAD, is it really worth it?

Posted

who said he's running the script manually? And in a sense he's still on track but why he's writing a lisp to write a script that runs a script is beyond me. I just made it happen (with help).

Posted

I'm not saying the topic is off - but I thought it weird that you would write the "script running code" into the script itself.

 

I assumed that he was running the script manually, - but sometimes tbh, you can "over-code" something, when doing it manually is in fact quicker at that point,.

Posted

So going back to an earlier comment by Shawndoe, Lee Macs last post, and my first post. should I forget about trying to invoke on several selected files a lisp routine using a script? Should I instead learn up on Visual basic and being some sort of Open reactor function?

Posted

No, I think a script would accomplish the necessary.

 

But I would write the script using a LISP, and then run the script manually.

Posted

A script is the only way to do it, really, unless you go into more complicated Visual LISP or Visual Basic stuff. I think, though, it could be made more efficient if you knew exactly what you needed to get done. My method, when modifying multiple files, is to run a script which runs a LISP on each file. I have autonomated, simplifed and added options to this process by using a LISP that creates the script and then runs it. Chronologically, it goes like this:

 

User runs a LISP > LISP creates Script and runs it > Script opens each drawing and runs a LISP on said file

 

As an added bonus, the second LISP that is run (the one on each file) is actually the first LISP, or more specifically, a selected function of it. It does not again create a script, it performs another operation that the LISP is capable of.

 

If you'd like to see the core of my LISP, go here:

http://www.cadtutor.net/forum/showthread.php?p=231639#post231632

Posted

Either that or:

 

(vlax-for doc  (vla-get-Documents
                (vlax-get-acad-object))

              ;; -- DO LISP --

)

 

But this disallows command calls.

Posted

Some questions to think about. If this is a quick and dirty one time need to run a routine on selected drawings then the script methode might be a better way to go. If you need to run routines on a regular bases, then you might want to create a more flexable routine.

 

You don't need visual basic to do this VLISP will do it. The key is to use the VL-blackboard. This will allow you to set Variables that can be accessed across drawings. Once you have the routine, and it's arguments if any, on the blackboard you can open the work drawing using vla-open.

 

Next you want a start-up routine that looks on the blackboard for your hand off. If it is on the blackboard, load and execute it. After the Start-up routine runs the drawing will return control automatically back to the control drawing, unless you set the work drawing as active. Don't set the work drawing as active or the routine will wait until you manually close it before resuming. When control has been handed back to drawing1 use vla-close to save and close the work drawing.

 

In the end you need three routines The control routine run from drawing1.dwg, The start-up routine which runs in the work drawings, and your actual work routine that does the things you need done.

 

Some things to note. Do not run the control routine from a drawing that will be called. The other is that the command line will be unavailable. You can run commands, but you can't pause for user input at the command line, DCL entry is still possible.

 

Let me know if you have any questions.

 

Have a good one.

Shawndoe

Posted

Great bit of advice there Shawn, couldn't have put it better myself :D

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