Author Topic: Script search for dwgs ...  (Read 7983 times)

0 Members and 1 Guest are viewing this topic.

Hangman

  • Swamp Rat
  • Posts: 566
Script search for dwgs ...
« on: February 13, 2007, 05:00:00 PM »
Not sure if this topic would go here, ...

I bought a book a few days ago to learn some WScripting, but with my Calculus class, Revit, and other stuff I have to learn and use, I can't seem to cram any more learning into the two brain cells I have left.   :ugly:   My head hurts. 
I'll learn it eventually, but in the mean time, could you guru's put something together for me ??

I need a routine that will ask the user for a job number:  (user enters)  06132.A2
The routine then seperates the first two digits to distinguish the directory structure:  (06 is for the 'Drawings 2006' directory)
      Drawings 2004
      Drawings 2005
      Drawings 2006
      Drawings 2007
The routine then finds the directory:   X:\Drawings 2006\06132.A2
The routine then searches the directory for all drawings of type:   06132*S*.dwg
(Here's the tricky part.  Our drawings are labeled a bit differently, depending on the Architects format.
 So we could have drawings labeled like:
06132-S-01
06132_S001
06132.A2-S0-01
06132A2S001
06132-A2_S-001    )

The routine then filters out:
      If the name has an 'OLD' or '-OLD' or '_OLD'  (so, like 06132-A2_S0-01_OLD.dwg)
      Then do not select / count it.
The routine then creates a counter or gets each drawing name (I don't know how it would work here)
The routine then opens the first drawing  (ie: 06132-A2_S0-1.dwg)
The routine then runs a LiSP on the drawing
The LiSP closes the drawing when finished.  Or if the routine must close the drawing to keep things working properly, so be it.
The routine then opens the next drawing  (ie: 06132-A2_S1-1.dwg)
The routine then runs a LiSP on the drawing
The LiSP closes the drawing when finished.  Or ...
The routine then opens the next drawing  (ie: 06132-A2_S2-1.dwg)
The routine then runs a LiSP on the drawing
The LiSP closes the drawing when finished.  Or ...
The routine then opens the next drawing  (ie: 06132-A2_S2-2.dwg)
The routine then runs a LiSP on the drawing
The LiSP closes the drawing when finished.  Or ...
The routine then opens the next drawing  (ie: 06132-A2_S4-1.dwg)
The routine then ends after the last drawing has been processed, be it 5 drawings or 15 drawings.

Phew, ...  So what think you ??  Could you put something like this together for me ??  I know it's asking a lot.  And if you don't have the time, that's fine.  We've gone this far without it, we can go on.  But it sure would be nice.   ;-)
Thanks.
Hangman  8)

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

Guest

  • Guest
Re: Script search for dwgs ...
« Reply #1 on: February 13, 2007, 05:06:28 PM »
I could easily do it in VBA - may or may not help you.  What does the LSP do to each drawing?

Hangman

  • Swamp Rat
  • Posts: 566
Re: Script search for dwgs ...
« Reply #2 on: February 13, 2007, 05:25:26 PM »
It's a purge/bind program.  It saves the drawing to a BIND folder, purges the drawing and binds any xrefs.
Is VBA similar to Scripting ??  I am working my way towards VBA, ...  well actually, I don't know where I want to go next.  My ultimate goal is to know several languages, mainly .NET & C++.  I'm getting there with LiSP, still have a ways to go but I'm getting there.  I've learned a lot from this forum.  I've got a couple idea's for WSH for simple office use, so I figured I'd start with scripting, work my way into VBA and eventually .NET & C++.  What'cha think, are they lofty goals ??
Hangman  8)

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

Hangman

  • Swamp Rat
  • Posts: 566
Re: Script search for dwgs ...
« Reply #3 on: February 13, 2007, 05:27:42 PM »
Actually, the routine should be good for just about any LiSP routine.  If you have several drawings you want to put out as DWF's or DXF's.  Just write a lisp routine for it and have the Script routine find the drawings and run the lisp.
Hangman  8)

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

uncoolperson

  • Guest
Re: Script search for dwgs ...
« Reply #4 on: February 13, 2007, 05:33:28 PM »
not vba/lisp/script... but would the program in this thread help out?

http://www.theswamp.org/index.php?topic=10211.0

Hangman

  • Swamp Rat
  • Posts: 566
Re: Script search for dwgs ...
« Reply #5 on: February 13, 2007, 06:05:00 PM »
... would the program in this thread help out?

http://www.theswamp.org/index.php?topic=10211.0

Well, I'm not recognizing anything in there, but that don't mean much.  I don't recognize much let alone remember anything these days.   8-)
I can't find the MsgBox or EntryBox in there.  :D

Hey uncool, ...  when did you pass the ASE Electrical ??  That's my reason behind the Calculus, working toward a bachelors in Electrical engineering at the moment.
Hangman  8)

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

uncoolperson

  • Guest
Re: Script search for dwgs ...
« Reply #6 on: February 13, 2007, 06:16:08 PM »
... would the program in this thread help out?

http://www.theswamp.org/index.php?topic=10211.0

Well, I'm not recognizing anything in there, but that don't mean much.  I don't recognize much let alone remember anything these days.   8-)
I can't find the MsgBox or EntryBox in there.  :D

Hey uncool, ...  when did you pass the ASE Electrical ??  That's my reason behind the Calculus, working toward a bachelors in Electrical engineering at the moment.

that was a program i threw together to do batch processes on files.

there's an entry box that uses wildcard matching to filter the files, can filter by last saved date, and file owner (usually last saved person), it searches directories recursively and shows the results in a handy tree diagram (or whatever it's called)... check and uncheck to add to the list to be used... type in the commands (lisp too!) you want to be run... and press go

as for the ase test, I passed that in november... pretty easy, don't need to know much about electricity (lucky for me, cause i don't)... just basics and how cars use it (more stuff i don't really know)...
« Last Edit: February 13, 2007, 06:18:03 PM by uncoolperson »

Hangman

  • Swamp Rat
  • Posts: 566
Re: Script search for dwgs ...
« Reply #7 on: February 13, 2007, 06:28:10 PM »

there's an entry box that uses wildcard matching to filter the files, can filter by last saved date, and file owner (usually last saved person), it searches directories recursively and shows the results in a handy tree diagram (or whatever it's called)... check and uncheck to add to the list to be used... type in the commands (lisp too!) you want to be run... and press go


Duh !!!   :ugly:  I'm sitting here looking at the two JPG files on that thread and looking for code.  No wonder I didn't recognize anything in there, the four lines on code down on the bottom of the thread didn't mean a thing to me.   :lol:

ok, NOW that I think I understand what I'm looking at, YEAH, it might help.  At least a portion.  I like the selection box you have to select which drawings you want to process.  Now this code is in VBA right ?.  Like I asked earlier, is that similar to scripting ?  Could I use your code and make a total mess out of it trying to create my little routine ??
Hangman  8)

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

uncoolperson

  • Guest
Re: Script search for dwgs ...
« Reply #8 on: February 13, 2007, 06:53:36 PM »

there's an entry box that uses wildcard matching to filter the files, can filter by last saved date, and file owner (usually last saved person), it searches directories recursively and shows the results in a handy tree diagram (or whatever it's called)... check and uncheck to add to the list to be used... type in the commands (lisp too!) you want to be run... and press go


Duh !!!   :ugly:  I'm sitting here looking at the two JPG files on that thread and looking for code.  No wonder I didn't recognize anything in there, the four lines on code down on the bottom of the thread didn't mean a thing to me.   :lol:

ok, NOW that I think I understand what I'm looking at, YEAH, it might help.  At least a portion.  I like the selection box you have to select which drawings you want to process.  Now this code is in VBA right ?.  Like I asked earlier, is that similar to scripting ?  Could I use your code and make a total mess out of it trying to create my little routine ??

it's c#...but maybe you can make some sense of it.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Script search for dwgs ...
« Reply #9 on: February 13, 2007, 06:54:01 PM »
Do it in whatever language you feel comfortable in, or whichever you want to learn.  This can be done with lisp.  I would use the lisp to write a script file, then at the end of the first lisp run the script that will open all the drawings up, and call all the commands you want executed (lisp or native).
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

Hangman

  • Swamp Rat
  • Posts: 566
Re: Script search for dwgs ...
« Reply #10 on: February 13, 2007, 07:12:34 PM »
Do it in whatever language you feel comfortable in, or whichever you want to learn.  This can be done with lisp.  I would use the lisp to write a script file, ...

I would really like to put this in WScript, just mainly because I've got a book and I can then sit down with this code and decipher it and see how it works.  But, ...
You would use lisp to write a script file !?.  (that's interesting, how do you do this ??)

I would use the lisp to write a script file, then at the end of the first lisp run the script that will open all the drawings up, and call all the commands you want executed (lisp or native).

(with a big cheesy grin)   :D  Would I be pushing my luck if I said, "Show Me!" ??   :evil:
Hangman  8)

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

Derwin

  • Guest
Re: Script search for dwgs ...
« Reply #11 on: February 13, 2007, 07:22:51 PM »
hi. i have written such a thing for our shop.
i do all you recquire excepting the automated tasks within each drawing, (another function does that), instead if i open a bunch of files, they need to be made homogenous, and only 1 in 10 will be extreme enough to recquire manual intervention.
most of what you ask for is quite easy. the hardest stage in your recquirement is the parsing of the filenames, the bit where you have to double guess the filenaming conventions of your drafters. no one but yourself will appreciate the importance of proper (ie: formalised) naming.  I think my sucess was dependant upon providing SAVING functions as well, so both the saving+opening could use the same algorithm to 'understand' the filenames. when the guys here started using these functions, because they were saved time + keystrokes they never went back to 'inventing' names or on a whim modifying the 'format', or even using SAVE, and so everything moves slightly smoother. we also havnt lost *any* drawings by accidentally misreading and reusing a previously used filename.
also, if you can understand some lisp, but little of anything else, then write it in lisp, and do yourself a favour. Youll learn more and make it easier to understand C# and the rest if/when you choose to go there.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Script search for dwgs ...
« Reply #12 on: February 13, 2007, 07:26:17 PM »
Here is the one I use.  You will have to code the front end where it selects all the drawings you want, but this the complete program I use to write/execute a script file.
Code: [Select]
(defun BScript (Routines / Opt DirPath DiaLoad DwgLIst tmpList Tog1 ScrFile Opened FullPath SvOpt
                           oldSdi oldLisp oldcmd oldFile flag)
; Writes a script to run multiple routines on a selection of drawings.
; If you want the drawing saved, add to routines area.
; use like (BScript '("pua" "UpdNum" "_.qsave"))
; Sub-Routines 'Directory-dia


(setq oldFile (getvar "filedia"))
(setq oldcmd (getvar "cmddia"))
(if (setq DirPath (Directory-dia "Select directory to batch process drawings."))
 (progn
  (setvar "filedia" 0)
  (setvar "cmddia" 0)
  (setq DiaLoad (load_dialog "CloseDwg.dcl"))
  (if (not (new_dialog "MultiSelect" DiaLoad))
   (exit)
  )
  (setq DwgList (vl-directory-files DirPath "*.dwg" 1))
  (setq DwgList (vl-sort DwgList '<))
  (set_tile "text1" "Select toggle to do all drawings.")
  (start_list "listbox" 3)
  (mapcar 'add_list DwgList)
  (end_list)
  (action_tile "accept"
  "(progn
   (setq tmpList (get_tile \"listbox\"))
   (setq Tog1 (get_tile \"toggle1\"))
   (done_dialog 1)
  )"
  )
  (action_tile "cancel" "(done_dialog 0)")
  (if (= (start_dialog) 1)
   (progn
    (if (= Tog1 "0")
     (setq tmpList (read (strcat "(" tmpList ")")))
     (repeat (length DwgList)
      (if (not cnt1)
       (setq cnt1 0)
       (setq cnt1 (1+ cnt1))
      )
      (setq tmpList (cons cnt1 tmpList))
     )
    )
    (setq ScrFile "C:/MyCustom/Scripts/tmpScript.scr")
    (setq Opened (open ScrFile "W"))
    (foreach Num tmpList
     (setq FullPath (strcat DirPath (nth Num DwgList)))
     (write-line "_.open" Opened)
     (write-line (strcat "\"" FullPath "\"") Opened)
     (foreach Routine Routines
      (write-line Routine Opened)
     )
     (write-line "_.close" Opened)
    )
    (write-line "setvar" Opened)
    (write-line "filedia" Opened)
    (write-line (itoa oldFile) Opened)
    (write-line "setvar" Opened)
    (write-line "cmddia" Opened)
    (write-line (itoa oldcmd) Opened)
    (write-line "\(alert \"Done!!\"\)" Opened)
    (close Opened)
    (command "_.script" ScrFile)
   )
  )
 )
)
(princ)
)
(defun Directory-Dia ( Message / sh folder folderobject result)
;; By Tony Tanzillo
;; Modified by Tim Willey
;; 16 Will let you type in the path
;; 64 Will let you create a new folder

  (vl-load-com)
  (setq sh
     (vla-getInterfaceObject
        (vlax-get-acad-object)
        "Shell.Application"
     )
  )


  (setq folder
     (vlax-invoke-method
         sh
         'BrowseForFolder
         (vla-get-HWND (vlax-get-Acad-Object))
         Message
         0 ; This is the bit number to change.
      )
  )
  (vlax-release-object sh)


  (if folder
     (progn
        (setq folderobject
           (vlax-get-property folder 'Self)
        )
        (setq result
           (vlax-get-property FolderObject 'Path)
        )
        (vlax-release-object folder)
        (vlax-release-object FolderObject)
        (if (/= (substr result (strlen result)) "\\")
          (setq result (strcat result "\\"))
          result
        )
     )
  )
)
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

ronjonp

  • Needs a day job
  • Posts: 7531
Re: Script search for dwgs ...
« Reply #13 on: February 14, 2007, 03:11:01 PM »
Here is what I use to create script files:

Code: [Select]
(defun c:batch (/ fname dir dirlist file cntr)
  (setq fname (getfiled "Select A Drawing File"
(getvar 'dwgprefix)
"dwg"
8
      )
  )
  (if fname
    (progn
      (setq dir     (vl-filename-directory fname)
    dirlist (vl-directory-files dir "*.dwg")
    file    (open (strcat dir "\\cleanup.scr") "w")
    cntr    0
      )
      (repeat (length dirlist)
(setq fname (vl-filename-base (nth cntr dirlist)))
(write-line
  (strcase
    (strcat "_.open \"" dir "\\" fname "\"")
    T
  )
  file
)
(write-line "do somethin" file)
(write-line "_.qsave _.close" file)
(setq cntr (1+ cntr))
      )
      (close file)
    )
  )
  (alert (strcat "Script file located in: " dir))
  (princ)
)
« Last Edit: February 14, 2007, 04:15:27 PM by ronjonp »

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

ronjonp

  • Needs a day job
  • Posts: 7531
Re: Script search for dwgs ...
« Reply #14 on: February 14, 2007, 04:26:33 PM »
This might get you started...

Code: [Select]
(defun c:x (/ job dir dirlist file cntr)
  (setq job (getstring "\n Enter job number: ")
dir (strcat "X:\\Drawings 20" (substr job 1 2) "\\" job)
dirlist (vl-directory-files
  dir
  (strcat (substr job 1 5) "*s*.dwg")
)
dirlist (vl-remove-if
  (function (lambda (x) (wcmatch (strcase x) "*OLD*"))
  )
  dirlist
)
file (open (strcat dir "\\batch.scr") "w")
cntr 0
  )
  (if dirlist
    (progn
      (repeat (length dirlist)
(setq fname (vl-filename-base (nth cntr dirlist)))
(write-line
  (strcase
    (strcat "_.open \"" dir "\\" fname "\"")
    T
  )
  file
)
(write-line "do something" file) ;<- command to run in drawing
(write-line "_.qsave _.close" file)
(setq cntr (1+ cntr))
      )
      (close file)
    )
  )
  (alert (strcat "Script located in" dir))
)

Ron

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC