Author Topic: Using a text format to run autolisp routines over multiple drawings  (Read 9225 times)

0 Members and 1 Guest are viewing this topic.

lispman21

  • Guest
I am trying to figure out how to take over 2,000 dxf's and run the same lisp routines on all of these dxf's.  I want to  be able to identify the directory these dxf's are in open each one run the lisp routines save routines as dxf's in the same directory they were opened from, and close. Then repeat automatically for every dxf in the directory.  I will let you know i only have little knowledge in Autolisp and no knowledge in VBA.  So i am going to need some guidance.


Also I think doing this kind of batch run will save me weeks worth of work and that is my basis for looking into doing this.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Using a text format to run autolisp routines over multiple drawings
« Reply #1 on: July 25, 2006, 03:52:37 PM »
You may want to look at running a script over all the files which will call a lisp.  If you know what you want to do, and can do it with only calling ActiveX type codes, then you can look into ObjectDBX, which is faster than a script, because it doesn't have to open all the drawings in the editor.

Do you have the lisp file already coded?  How much help are you looking for?
Tim

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

Please think about donating if this post helped you.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Using a text format to run autolisp routines over multiple drawings
« Reply #2 on: July 25, 2006, 03:59:42 PM »
Indeed! And in my experience dbxin/out via ODBX really rips. Sorry, I wish could contribute to this thread but alas, no time! Perhaps tonight as my wife is working a late shift.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Using a text format to run autolisp routines over multiple drawings
« Reply #3 on: July 26, 2006, 12:22:47 AM »
I am trying to figure out how to take over 2,000 dxf's and run the same lisp routines on all of these dxf's.  I want to  be able to identify the directory these dxf's are in open each one run the lisp routines save routines as dxf's in the same directory they were opened from, and close. Then repeat automatically for every dxf in the directory.  I will let you know i only have little knowledge in Autolisp and no knowledge in VBA.  So i am going to need some guidance.

Also I think doing this kind of batch run will save me weeks worth of work and that is my basis for looking into doing this.

Ok. IMO the first thing we need to do before we run off and start pounding code is identify exactly what we want to do -- what's the recipe so to speak. So let's clarify what you've provided so far (words in braces { word } are mine) --

1. I am trying to figure out how to take over {iterate} 2,000 dxf's and run the same lisp routines on all of these dxf's ...

I'm not sure what you mean by "take over" so I have to make an assumptive reach: You have a directory tree that hosts approximately 2000 dxf files. You want to recursively scan said directory tree and locate all dxf files, possibly using wildcarding to limit what the search discovers.

Sounds like you could use DOLIB (dos_find) to fullfill the initial scan (I'll detail it later, let's keep the recipe lite for the moment).

Please identify anything that is missing or in err.

2) I want to be able to identify the directory these dxf's are in ...

For each dxf file you need to be able to identify the full path to the dxf file. If we go the DOSLIB route it will be a no brain-er.

Please identify anything that is missing or in err.

3) ... open each one {dxf file} run the lisp routines ...

Seems straightforward but several avenues can be persued here. Do you want to open / import the dxf file in the AutoCAD editor, open the dxf file directly via ObjectDBX (a good bet, execution wise, speed), or open the dxf as a sequential file, operating directly upon it?

Please identify anything that is missing or in err.

4) ... save routines as dxf's in the same directory they were opened from ...

Depending on what transpires in item 3, save the modified dxf file over top of itself. At this point I'd suggest that if that is the case you ensure a backup of all these files is made prior to this exercise, or that a backup mechanism be part of the "program" (I'd recommend the former, at least intially).

Hmmm, nother question -- do mean save dxf files to dxf files, or dxf files to dwg files?

Please identify anything that is missing or in err.

5) ... repeat automatically for every dxf in the directory.

Gotcha.


Dang, the sleeping pill is kicking (and Im nodding), and I must decline to work on this any more tonight (as if you couldn't tell). You wouldn't imagine how hard I gotta stare at the screen to see it in one place and legibly; woo. Forgive me, I should have just tossed it in the bin.

Anyway, I hope my swamp friends pick this up torrow where I've left and pass the battan back an forth 'til a proper solution design emerges, though the O/P has a few things to clarify before coding thing happens. Night all.

MP.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

lispman21

  • Guest
Re: Using a text format to run autolisp routines over multiple drawings
« Reply #4 on: July 26, 2006, 08:10:15 AM »
Ok, starting with question 1 and going in order.


1.  As what i meant about "take over" this probably should have read like "I am trying to run a couple lisp routines on dxf's that are located in their own directory."  So you assumed correctly to wha twas meant here.

2.  Again these statements are correct and i will have to check the hyperlinks you gave for background info on DOSLIB.

3.  I am going to want to open these dxf's via ObjectDBX, just because of the execution speed and it doesn't have to open the drawing editor.

4.  Backups of these file are placed in two different locations and yes I am wanting to save the dxf file back into the directory as a dxf file.  Which means the converted file will overwrite the existing file.

5.  And as in question 5 it is pretty straight forward.  Repeat on all dxf files.

Thanks for your detailed look at my question.  Hopefully my answers will give you more insight to waht i am trying to achieve.
« Last Edit: July 26, 2006, 08:11:49 AM by lispman21 »

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Using a text format to run autolisp routines over multiple drawings
« Reply #5 on: July 26, 2006, 11:10:41 AM »
Now the question of what routines do you want to run one each file?  This will let us know if we can go the ObjectDBX route, and if you have said routines written, or if you need help writting them.
Tim

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

Please think about donating if this post helped you.

uncoolperson

  • Guest
Re: Using a text format to run autolisp routines over multiple drawings
« Reply #6 on: July 26, 2006, 11:16:10 AM »
http://www.theswamp.org/index.php?topic=10211.msg134658#msg134658


would something like that help you out?

3.  I am going to want to open these dxf's via ObjectDBX, just because of the execution speed and it doesn't have to open the drawing editor.

scratch that, this opens the drawing editor...
« Last Edit: July 26, 2006, 11:18:33 AM by uncoolperson »

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Using a text format to run autolisp routines over multiple drawings
« Reply #7 on: July 26, 2006, 11:25:20 AM »
Just incase it isn't clear; You will have to have the editor open, but with ObjectDBX it doesn't have to open each drawing in the editor.
Tim

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

Please think about donating if this post helped you.

lispman21

  • Guest
Re: Using a text format to run autolisp routines over multiple drawings
« Reply #8 on: July 26, 2006, 12:14:40 PM »
ok that sounds better that it doesnt have to open every drawing in the editor so therefore this is the faster way.  I believe this is the way i want to go.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Using a text format to run autolisp routines over multiple drawings
« Reply #9 on: July 26, 2006, 12:18:59 PM »
What is you code going to do?  This is an important part of the process Michael has started.
Tim

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

Please think about donating if this post helped you.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Using a text format to run autolisp routines over multiple drawings
« Reply #10 on: July 26, 2006, 12:33:06 PM »
So you want to convert all the lines in the drawings, to plines?
Tim

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

Please think about donating if this post helped you.

lispman21

  • Guest
Re: Using a text format to run autolisp routines over multiple drawings
« Reply #11 on: July 26, 2006, 01:22:29 PM »
i already have lisp routines written to convert every single entity in the drawings to plines.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Using a text format to run autolisp routines over multiple drawings
« Reply #12 on: July 26, 2006, 01:25:28 PM »
With the code you have shown on the AUGI site, then a script is the best way to go.  Did you get all you needed there?
Tim

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

Please think about donating if this post helped you.

Krushert

  • Seagull
  • Posts: 13679
  • FREE BEER Tomorrow!!
Re: Using a text format to run autolisp routines over multiple drawings
« Reply #13 on: July 26, 2006, 01:57:13 PM »
Just a curious thought or question.

If lispman was to run this script/code on 2000 def files, how long would it take to run?  Minutes or hours?
I know it depends on the machine, but roughly how long?
I + XI = X is true ...  ... if you change your perspective.

I no longer CAD or Model, I just hang out here picking up the empties beer cans

lispman21

  • Guest
Re: Using a text format to run autolisp routines over multiple drawings
« Reply #14 on: July 26, 2006, 02:06:29 PM »
ok another forum i have visited has given me a lot of help and this is as far as we have got to.

Here is the code
Code: [Select]

(defun c:GenScr (/ dwgPath dwgList dwgName numDwgs count scrFile)
;;; Path should be like "c:\\projects\plots\\" or "c:/projects/plots/"
;;; Substitute your path here.
(setq dxfPath "C:\\Documents and Settings\\laoom\\Desktop\\dxf's that need converting\\" ; sets the path
dwgList (vl-directory-files dxfPath "*.dxf") ; get the list of all the dxf's
)
(if dwgList ; if dwg files exists there
(progn
(setq numDwgs (length dwgList) ; number of drawings
count 0 ; initiate counter
scrFile (open (strcat dxfPath "Runme.scr") "w") ; open a script file in the same folder
)
(repeat numDwgs ; for all the drawings
(setq dwgName (strcat "\"" dxfpath (nth count dwgList) "\""))  
(write-line ".Open" scrFile) ; write to script file
(write-line dwgName scrFile)
 
;;;If you need to load a lisp routine in each dwg
(write-line "(load \"Setting layer '0' current with continuous Ltype.LSP\")" scrFile) ; load any required lisp routine
  (write-line "(load \"Arcs to plines.lsp\")" scrFile) ; load any required lisp routine
  (write-line "(load \"Circles to PLines.LSP\")" scrFile) ; load any required lisp routine
  (write-line "(load \"Converting Lines to Polylines.LSP\")" scrFile) ; load any required lisp routine
  (write-line "(load \"Explode all.LSP\")" scrFile) ; load any required lisp routine
  (write-line "(load \"Light-weight PLines to 2D PLines.LSP\")" scrFile) ; load any required lisp routine
;;;
;;; Enter your commands here.
(write-line "(con)" scrFile)
(write-line "(ex)" scrFile)
  (write-line "(convert)" scrFile)
  (write-line "(arctopl)" scrFile)
  (write-line "(c2p)" scrFile)
  (write-line "(2d)" scrFile)
  (write-line "(con)" scrFile)

;;;
;;; Preset the dxf file format before you proceed.
;;; May require minor modification depending on you
;;; AutoCAD version Notice the two spaces after dxfout
;;; in the following line acts like <enter>.This will
;;; accept the default file name and default format
(write-line ".Dxfout  " scrFile)
;;; Better to save the drawing for uninterrupted scripting
(write-line ".Qsave" scrFile)
  (write-line ".close" scrFile)
(setq count (1+ count)) ; next dwg
)
(close scrFile) ; close when done
;;; Make sure that the current dwg won't prompt for
;;; save changes!
(command ".script" (strcat dxfpath "Runme.scr")) ; run the script
) ; progn
) ; if
(princ)
) ; defun



For some reason or another this program will open 1 drawing run all the lisp routines and then it just stops.  It doesn't save it or close or opent he next drawing.  It could be how my lisp programs are written.  They are attached for review.