Author Topic: script won't open more than one drawing.  (Read 4290 times)

0 Members and 1 Guest are viewing this topic.

Hangman

  • Swamp Rat
  • Posts: 566
script won't open more than one drawing.
« on: June 18, 2007, 06:15:15 PM »
Alright, take me back to scripting 101.  I'm at a loss here.
I've read several places that scripts cannot run a command that uses a dialog box.  But all the scripts I see use the command "_.open".
This command opens a dialog box.  I am assuming this is the problem with my script.
Code: [Select]
;;;
;;;
vl-load-com
;;;
  (defun Details (/ )
    (setq DwgList (vl-directory-files DtlPath (strcat DtlType "*.dwg") 1)); DWGlist is DtlPath + DtlType*.dwg
    (setq DwgList (vl-remove-if (function (lambda (x) (wcmatch (strcase x) "*INFO*,*OLD*"))) DwgList)); Remove from list everything with ...
    (setq DwgList (vl-sort DwgList '<))
    (setq DwgCount (length DwgList))
    (setq Counter 0)
    (while (< Counter DwgCount)
      (progn
        (setq Script (strcat DtlPath "\\TDScript.scr"))
        (setq ScriptFile (open Script "W"))
        (repeat (length DwgList)
          (setq DwgName (vl-filename-base (nth Counter DwgList)))
          (setq DwgName (strcat DwgName ".dwg"))
          (write-line (strcase (strcat "_.open \"" DtlPath "\\" DwgName "\"") T) ScriptFile)
          (write-line "graphscr")
          (write-line "TypDtlUpdate" ScriptFile)
;          (write-line "_.close" ScriptFile)
;          (write-line "_.qsave _.close" ScriptFile)
          (write-line " " ScriptFile)
          (setq Counter (1+ Counter)))
        (close ScriptFile)))
    (command "_.script" Script))
;;;
  (defun Schedules (/ )
    (setq DtlType (substr DtlType 1 5))
    (setq DwgList (vl-directory-files SchPath (strcat DtlType "*.dwg") 1)); DWGlist is SchPath + SchType*.dwg
    (setq DwgList (vl-remove-if (function (lambda (x) (wcmatch (strcase x) "*INFO*,*OLD*"))) DwgList)); Remove from list everything with ...
    (setq DwgList (vl-sort DwgList '<))
    (setq DwgCount (length DwgList))
    (setq Counter 0)
    (while (< Counter DwgCount)
      (progn
        (setq Script (strcat SchPath "\\SchScript.scr"))
        (setq ScriptFile (open Script "W"))
        (repeat (length DwgList)
          (setq DwgName (vl-filename-base (nth Counter DwgList)))
          (setq DwgName (strcat DwgName ".dwg"))
          (write-line (strcase (strcat "_.open \"" SchPath "\\" DwgName "\"") T) ScriptFile)
          (write-line "graphscr")
          (write-line "TypDtlUpdate" ScriptFile)
;          (write-line "_.close" ScriptFile)
;          (write-line "_.qsave _.close" ScriptFile)
          (write-line " " ScriptFile)
          (setq Counter (1+ Counter)))
        (close ScriptFile)))
    (command "_.script" Script))
;;;
(defun C:UpdateTypDetails (/ DtlPath DtlType SchType DwgList DwgCount Script ScriptFile
                             DwgName SchPath
                          )
  (defun $error (msg /)
    (if (or (= msg "Function cancelled")
            (/= msg "quit / exit abort"))
        (princ (strcat "Error: " msg)))
    (princ)
  );end error
;;;
  (setq DtlPath "X:\\DETAILS")
  (setq SchPath "X:\\SCHED")
;;;
  (textscr)
  (prompt "
            ATILT
            BRACED     > BR
            EBF
            FRMG       > FR
            FTG
            MOMENT     > MOM
            RFR
            SHEAR      > SH
            STEEL      > ST
            STEELSTUDS > SS
            TILT
            TYP
            WOOD
            SCHEDULE   > SCHED \n\n")
  (initget 7 "? ATILT BRaced EBF FRmg FTG MOMent RFR SHear STeel STEELSTUD,SS TILT TYP WOOD SCHEDule")
  (setq DtlType (getkword "\nEnter detail type:  "))
;;;
  (if (or (= DtlType "SCHEDule")(= DtlType "SCHED"))
    (Schedules)
    (Details))
;;;

;  (ALERT (strcat "Script File created in: " DtlPath))
  (while (< (getvar "cmdactive") 2)
    (vl-file-delete (strcat DtlPath "\\TDScript.scr"))
    (vl-file-delete (strcat SchPath "\\SchScript.scr")))
  (princ)
); END defun C: ...

This is a sample of my script that is created:
Code: [Select]
_.open "x:\sched\sched01a - legend of symbols.dwg"
TypDtlUpdate
 
_.open "x:\sched\sched01b - legend of symbols.dwg"
TypDtlUpdate
 
_.open "x:\sched\sched02a - footing sched 5000psf.dwg"
TypDtlUpdate
 
_.open "x:\sched\sched02b - footing sched 4500psf.dwg"
TypDtlUpdate


For some reason, the script will run the first drawing finishing the lisp "TypDtlUpdate", which closes the drawing, then as soon as it gets to the _.open for the next drawing, it stops.
I'm puzzled because the first drawing uses the command  _.open  as well, so why wouldn't the script stop there ??
I have set my system variable  FileDia to 0 so the dialog box for  _.open  will not come up, but it didn't change the behavior of the script, it still stopped at the command.
I can't find anything explaining why my script will not continue to run.
I have double checked the lisp routine "TypDtlUpdate" and it runs smoothly, right to the end of it as it is suppose to.  So I know this problem has to do with what I have posted here, I just can't find the culprit.
Can someone here please look at this and tell me what I have causing the problem ??

Thank you.
Hangman  8)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Drafting Board, Mechanical Arm, KOH-I-NOOR 0.7mm
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Hangman

  • Swamp Rat
  • Posts: 566
Re: script won't open more than one drawing.
« Reply #1 on: June 18, 2007, 06:36:04 PM »
Doht !!!  I need to make a clarification.
I know the space in the line   (write-line " " ScriptFile)
is designed to terminate script files.  I forgot to take that back out when I was testing the script.
Here is an updated look without that line.
Code: [Select]
_.open "x:\details\rfr01-deck across masonry.dwg"
TypDtlUpdate
_.open "x:\details\rfr02-deck across masonry.dwg"
TypDtlUpdate
_.open "x:\details\rfr03-deck into masonry.dwg"
TypDtlUpdate
_.open "x:\details\rfr04-joists on masonry.dwg"
TypDtlUpdate
Hangman  8)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Drafting Board, Mechanical Arm, KOH-I-NOOR 0.7mm
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

kpblc

  • Bull Frog
  • Posts: 396
Re: script won't open more than one drawing.
« Reply #2 on: June 18, 2007, 07:37:17 PM »
if you really want to use command functions, try to execute
Code: [Select]
_.-open <FileName>
Sorry for my English.

Hangman

  • Swamp Rat
  • Posts: 566
Re: script won't open more than one drawing.
« Reply #3 on: June 18, 2007, 07:44:15 PM »
Well, thank you for the thought, but unfortunately, I get "Unknown command".
Anyone have any other ideas ??  I'm going through about 120 drawings, one at a time at the moment, any other ideas would be greatly appreciated.
Hangman  8)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Drafting Board, Mechanical Arm, KOH-I-NOOR 0.7mm
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

BAshworth

  • Guest
Re: script won't open more than one drawing.
« Reply #4 on: June 18, 2007, 08:21:40 PM »
I'm going home... *sorry*

bowa

  • Guest
Re: script won't open more than one drawing.
« Reply #5 on: June 19, 2007, 08:39:26 AM »
You should simply be able to use "open" from a script file. It will use the command line version of the 'open' command rather than the dialog. I have a routine that regularly generates script files in the form of:

open
\\apps2\glass\p1000\3199
(load "GLASS")
GLDXF
close
open
\\apps2\glass\p1000\3299
(load "GLASS")
GLDXF
close


You may also want to close each file after the lisp routine has run. No need to keep 120 of them open on your machine.

kpblc

  • Bull Frog
  • Posts: 396
Re: script won't open more than one drawing.
« Reply #6 on: June 19, 2007, 09:07:05 AM »
I'd like to know what is the 'TypDtlUpdate' function. Perhaps there are some more another methods to solve the problem...
Sorry for my English.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: script won't open more than one drawing.
« Reply #7 on: June 19, 2007, 09:24:17 AM »
I hacked away at your routine to come up with this. see ; CAB for changes.
I apologise as it is not tested, leaving it up to you.
What exactly is the TypDtlUpdate routine? Can you post it?
Also post the scr file when created.

Code: [Select]
;;;
;;;
(vl-load-com) ; CAB
;;;
  (defun MakeScr (DtlPath DtlType / COUNTER DWGCOUNT DWGLIST DWGNAME SCHPATH SCRIPT SCRIPTFILE) ; CAB
    (setq DwgList (vl-directory-files DtlPath (strcat DtlType "*.dwg") 1)); DWGlist is DtlPath + DtlType*.dwg
    (setq DwgList (vl-remove-if (function (lambda (x) (wcmatch (strcase x) "*INFO*,*OLD*"))) DwgList)); Remove from list everything with ...
    (setq DwgList (vl-sort DwgList '<))
    (setq DwgCount (length DwgList))
    (setq Counter 0)
    (while (< Counter DwgCount)
      (progn
        (if (= DtlType "SCHEDule") ; CAB
          (setq Script (strcat SchPath "\\SchScript.scr"))
          (setq Script (strcat DtlPath "\\TDScript.scr"))
        ) ; CAB
        (setq ScriptFile (open Script "W"))
        (repeat (length DwgList)
          (setq DwgName (vl-filename-base (nth Counter DwgList)))
          (setq DwgName (strcat DwgName ".dwg"))
          (write-line (strcase (strcat "_.open \"" DtlPath "\\" DwgName "\"") T) ScriptFile)
          (write-line "graphscr")
          (write-line "TypDtlUpdate" ScriptFile) ; CAB  <--<<  What is this?
          (write-line "_.close" ScriptFile) ; CAB
          (write-line "_Y" ScriptFile) ; CAB
          (write-line " " ScriptFile)
          (setq Counter (1+ Counter))
        )
        (close ScriptFile)
      )
    )
    (command "_.script" Script)
  )
;;;
; CAB deleted
;;;
(defun C:UpdateTypDetails (/ UsrSel) ; CAB
  (defun $error (msg /)
    (if (or (= msg "Function cancelled")
            (/= msg "quit / exit abort"))
        (princ (strcat "Error: " msg)))
    (princ)
  );end error
;;;
; CAB deleted
;;;
  (textscr)
  (prompt "
            ATILT
            BRACED     > BR
            EBF
            FRMG       > FR
            FTG
            MOMENT     > MOM
            RFR
            SHEAR      > SH
            STEEL      > ST
            STEELSTUDS > SS
            TILT
            TYP
            WOOD
            SCHEDULE   > SCHED \n\n")
  (initget 1 "? ATILT BRaced EBF FRmg FTG MOMent RFR SHear STeel STEELSTUD,SS TILT TYP WOOD SCHEDule") ; CAB
  (setq UsrSel (getkword "\nEnter detail type:  "))
;;;
  (if (= UsrSel "SCHEDule") ; CAB
    (MakeScr "X:\\SCHED" (substr UsrSel 1 5)) ; CAB
    (MakeScr "X:\\DETAILS" UsrSel) ; CAB
  )
;;;

;  (ALERT (strcat "Script File created in: " DtlPath))
  ;| CAB
  (while (< (getvar "cmdactive") 2)
    (vl-file-delete (strcat DtlPath "\\TDScript.scr"))
    (vl-file-delete (strcat SchPath "\\SchScript.scr")))
    CAB |;
 
  (princ)
); END defun C: ...
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Hangman

  • Swamp Rat
  • Posts: 566
Re: script won't open more than one drawing.
« Reply #8 on: June 19, 2007, 10:55:40 AM »
You should simply be able to use "open" from a script file. It will use the command line version of the 'open' command rather than the dialog.

That's what I was thinking.  That's why I'm puzzled by the result & came here, Any brains are better than mine. :D

You may also want to close each file after the lisp routine has run. No need to keep 120 of them open on your machine.
The lisp routine  TypDtlUpdate  saves the drawing and closes it so I don't need that in the script.  (Or perhaps I do need it.  Although, I have tested it with the qsave & close, but it didn't help it any, it still would run one drawing and then stop).


I'd like to know what is the 'TypDtlUpdate' function. Perhaps there are some more another methods to solve the problem...
What exactly is the TypDtlUpdate routine? Can you post it?
Also post the scr file when created.

The TypDtlUpdate is a rather large cumbersome routine, written a while back when I didn't know much about Lisp.  (Not that I know anything more now than I did then).
I'm embarrassed to show it, it really is spaghetti code.  I'm not done with it yet either.  There are a couple of things I still need to add, once I figure out how it goes together.
I am currently using it on these 120 drawings, one at a time.
K, here it is, don't laugh.   :oops:  (see attached).
Basically, the TypDtlUpdate sets a new dimension style, text styles, & (It is suppose to move the dimensions, leaders and text to the new styles, but I haven't figured out how to move them yet).
It then cleans up any tab layouts that are un-necessary, purges the drawing, drops in a default title, qsaves & closes the drawing.  It's designed for typical details that were created back in 1994 and are still in use today.  The details are however, very outdated by our office standards so I was asked to update them without much time to do this task.  There are roughly 800 + drawings & schedules.  There are two engineers & I that are going through these drawings and deleting some we no longer need, revising others, and incorporating old with new where it is needed.

By the way, Thank you for you questions, your advice & your help on this, I really do appreciate it.
Hangman  8)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Drafting Board, Mechanical Arm, KOH-I-NOOR 0.7mm
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: script won't open more than one drawing.
« Reply #9 on: June 19, 2007, 11:16:20 AM »
qsaves & closes the drawing. .
A lisp must not close the drawing it is running in as it terminates the lisp prematurely.

To use that or any lisp in a script, let the lisp finish. Then let the script close the drawing.
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Hangman

  • Swamp Rat
  • Posts: 566
Re: script won't open more than one drawing.
« Reply #10 on: June 19, 2007, 01:18:03 PM »
qsaves & closes the drawing. .
A lisp must not close the drawing it is running in as it terminates the lisp prematurely.

To use that or any lisp in a script, let the lisp finish. Then let the script close the drawing.

CAB, Question for you regarding this:
If the code is written as follows, would it still be bad to have the lisp close the drawing, even though the close is the last command the lisp gives ??
Code: [Select]
...
;;; resetting environment to original settings
  (setvar "cmdecho" echoprv)
  (setvar "osmode" osnpprv)
  (setvar "filedia" fileprv)
  (setvar "attreq" attrprv)
  (command ".undo" "e")
  (command ".qsave")
  (princ)
  (command "close")
); End program



CAB, I have three other questions for you regarding the updated code you posted back.
First, what does the stuff in front of the forward slash (/) do ??  Not the DtlPath & the DtlType, but in general, items that are placed in this position are the for what reason ??
I remember reading about it once, but I can't find anything now regarding this.
Code: [Select]
  (defun MakeScr ([color=red]DtlPath DtlType[/color] / COUNTER DWGCOUNT DWGLIST DWGNAME SCHPATH SCRIPT SCRIPTFILE) ; CAB

Secondly, What does the  _Y  do in a script ??  I can't find any reference material regarding these types of code in a script.
Code: [Select]
(write-line "_Y" ScriptFile) ; CAB

Thirdly, How does the path in quotes work for a reference to another defined function ??  And doesn't the piece after the path in quotes have to be set to something ??
On a side note, when I ran this, I received an error:  stringp: nil   I was able to narrow the error down to this block of code here.
Code: [Select]
(if (= UsrSel "SCHEDule") ; CAB
    (MakeScr "X:\\SCHED" (substr UsrSel 1 5)) ; CAB
    (MakeScr "X:\\DETAILS" UsrSel) ; CAB
  )
« Last Edit: June 19, 2007, 01:19:04 PM by Hangman »
Hangman  8)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Drafting Board, Mechanical Arm, KOH-I-NOOR 0.7mm
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: script won't open more than one drawing.
« Reply #11 on: June 19, 2007, 02:59:44 PM »
If the code is written as follows, would it still be bad to have the lisp close the drawing, even though the close is the last command the lisp gives ??

At the least it's bad form. If it causes an error it will stop the script. There are ways to overcome the need for close.
Like setting a variable from the script & testing it in the lisp to conditionally use the close command.

First, what does the stuff in front of the forward slash (/) do ??

Well start reading here http://intervision.hjem.wanadoo.dk
Start in Part I, but the answer to you question in here 'Function syntax and evaluation' in Part II


Secondly, What does the  _Y  do in a script ??

Any command issued in the script that ask the user for input will require an answer.
If you altered the drawing and issue a CLOSE command there is a prompt to "Save changes? (Y/N)"
You need to answer with Y or N. As you know the _ is for language support and (.) is to force the
use of the Autocad command & not use any over ridden command.


Thirdly, How does the path in quotes work for a reference to another defined function ??

This will be answered when you read Part II referenced above.
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.