Author Topic: Using a text format to run autolisp routines over multiple drawings  (Read 9226 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.

lispman21

  • Guest
Re: Using a text format to run autolisp routines over multiple drawings
« Reply #15 on: July 26, 2006, 02:14:48 PM »
I think I have narrowed the problem down to it being something wrong with the code i have written for converting Lines to plines.  Not sure what is wrong with it cause it works but it just won't let the script continue for some reason or another.  If any one could look at it and the script that was posted before and make all suggestions you want.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Using a text format to run autolisp routines over multiple drawings
« Reply #16 on: July 26, 2006, 02:16:03 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?
With what he wants to do, most likely hours.

ok another forum i have visited has given me a lot of help and this is as far as we have got to.

<snip>

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.
Can youu post what the script file looks like?  Maybe just open it on your computer, and post it into code prompts in a reply, as script files can be dangerous.  Then maybe we can see what is happening.
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 #17 on: July 26, 2006, 02:20:09 PM »
The Lisp file for writing the script is on the previous page.  I do know that the program will run with ever code i have written except for the converting lines to plines code.  These are all on the first page.  Please take a look at the code.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Using a text format to run autolisp routines over multiple drawings
« Reply #18 on: July 26, 2006, 02:33:44 PM »
I can't use my Acad right now, it's busy, so this is guessing.  You should make sure you get a selection set, us an if statement to test that.  What error message does it show when you run the command?

I would write it like
Code: [Select]
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;                                                                         ;;
;;    AutoLisp Program                                                     ;;
;;    PROGRAM: ConvertingLines to Polylines.lsp                            ;;
;;    DATE: 4-19-06                                                        ;;
;;    File Location: C:\Program Files\Trane Company\Data Maintenance\SM    ;;
;;    BY: Jeremy Preston                                                   ;;
;;                                                                         ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


(defun CONVERT (/ OLDVAR1 LCOLOR COUNT LINENO SS1 ENT EDATA PT1 PT2)
   (command ".undo" "Mark")
     (setq old_plinetype (getvar "PLINETYPE"))
   (setvar "PLINETYPE" 0)
   (setq OLDVAR1 (getvar "CMDECHO")) (setvar "CMDECHO" 0)
   (setvar "PLINEWID" (getreal "Enter Width for Plines: "))   
;   (setq SS1 nil)    ; no need for this
(if  ; added
   (setq SS1 (ssget "X" ' ((0 . "LINE"))))   
(progn  ; added
   (setq LINENO (sslength SS1)) 
   (setq COUNT 0)
   (setq PLINFO (ssadd))         
   (repeat LINENO
      (progn     
         (setq ENT (ssname SS1 COUNT))   
         (setq EDATA (entget ENT))   
         (setq PT1 ( cdr (assoc 10 EDATA)))
         (setq PT2 ( cdr (assoc 11 EDATA)))
         ;(setq LCOLOR (cdr (assoc 62 EDATA)))   
         (setq LLAYER (cdr (assoc 8 EDATA)))
         ;(if LCOLOR (princ) (setq LCOLOR "BYLAYER"))
         (command "Color" LCOLOR )
         (command "Layer" "s" LLAYER "")
         (command "Pline" PT1 PT2 "")       
         (ssadd (entlast) PLINFO)       
         (prompt (strcat "Processing line no. " (itoa COUNT) "\r"))
         (setq COUNT (1+ COUNT))       
      )
   )
   (COMMAND "ERASE" SS1 "")     
) ; added end (progn     
) ; added end (if
   (setvar "CMDECHO" OLDVAR1)         
   (prompt (strcat "\n" "Erasing original lines..." "\n"))
   (princ) ; end program
   (setvar "PLINETYPE" old_plinetype)
); end convert.lsp
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 #19 on: July 26, 2006, 03:31:51 PM »
Whoa, TMI: Bookmarked for tonight.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Using a text format to run autolisp routines over multiple drawings
« Reply #20 on: July 26, 2006, 03:35:16 PM »
Whoa, TMI: Bookmarked for tonight.
Not really.  Nothing has gotten answered really.  OP got help from the AUGI site, but the problem with with the OP's lisp to convert lines to plines.  I posted a modified version, but haven't heard back yet.

Now you are all caught up.   :wink:
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 #21 on: July 26, 2006, 03:52:38 PM »
I hate these drawings because whoever did them sucked.  Now i am having problems converting lines to plines because some of them are not parallel to the ucs.  Any way to get around this.

lispman21

  • Guest
Re: Using a text format to run autolisp routines over multiple drawings
« Reply #22 on: July 26, 2006, 04:03:29 PM »
Even when the revised code encounters a drawing where lines have to be changed to plines it changes them but doesn't save and close and repeat on other drawings it just stops.



T.Willey

  • Needs a day job
  • Posts: 5251
Re: Using a text format to run autolisp routines over multiple drawings
« Reply #23 on: July 26, 2006, 04:06:38 PM »
Even when the revised code encounters a drawing where lines have to be changed to plines it changes them but doesn't save and close and repeat on other drawings it just stops.



This is why I asked that you post what the contents of the script file look like.  Here is a portion of what one of mine looks like.

Quote
_.open
"H:\eMatrix\PICS\TDD-3\12-2708-0851-7_001.dwg"
updnum
_.qsave
_.close
_.open
"H:\eMatrix\PICS\TDD-3\12-2708-0851-7_002.dwg"
updnum
_.qsave
_.close
This one opens the drawing, runs the lisp command "updnum", saves, closes, and opens the next one.
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 #24 on: July 27, 2006, 07:23:29 AM »
here is the script you asked for.  it is attached

lispman21

  • Guest
Re: Using a text format to run autolisp routines over multiple drawings
« Reply #25 on: July 27, 2006, 08:25:32 AM »
ok here is an update.  It seems to me that I have everything working perfectly right now.  But one issue I have is with converting ellipses to plines.  It works great on actual ellipses but not elliptical arcs.  The program takes the arc and draws it in its full elliptical state and does not trim or break it back to look like the arc it is supposed to look like.  If anyone can help on this it would be much appreciated.

Code: [Select]
(defun e2p( /
old new   ;existent and new polyline
sav    ;store system variables
cen    ;center of ellipse
dep    ;axis end point deplacement (relative to cen)
p1 p2 ;first axis enpoints
p3 ;sec. axis endpoint
 ellObjs   ; added
 numObjs   ; added   
 count ; added   
   )

(setq ellObjs (ssget "x" '((0 . "ELLIPSE"))))
(if ellObjs
  (progn
  (setq numOjbs (sslength ellObjs)
 count 0
 )
  (while (> numOjbs count)
(setq old (cdr (assoc -1 (entget (ssname ellObjs count)))))


   (setq sav (mapcar 'getvar '("PELLIPSE" "OSMODE" "UCSICON"))
cen (cdr (assoc 10 (entget old)))
dep (cdr (assoc 11 (entget old))))
   (mapcar 'setvar '("PELLIPSE" "OSMODE" "UCSICON") '(1 0 0))
   (command "UCS" "e" old)
   (setq p1 (trans (list (+ (car cen) (car dep))
   (+ (cadr cen) (cadr dep))
   (+ (caddr cen) (caddr dep)))
0 1)
p2 (trans (list (- (car cen) (car dep))
   (- (cadr cen) (cadr dep))
   (- (caddr cen) (caddr dep)))
0 1)
p3 (trans (polar cen
(+ (/ PI 2.0) (angle p1 p2))
(* 0.5 (cdr (assoc 40 (entget old))) (distance p1 p2)))
0 1)
)
   (command "ellipse" p1 p2 p3)
   (command "_.chprop" old "" "la" "0" "")   
   (setq new (entget (entlast))
new (subst (cons 8 (cdr (assoc 8 (entget old)))) (assoc 8 new) new))
   (entmod new)
   (entdel old)
   (command "ucs" "p")
   (mapcar 'setvar '("PELLIPSE" "OSMODE" "UCSICON") sav)

(setq count (1+ count))
); while
  ); progn
  ); if
(princ)
   );; end of program
/[code]
[/code]

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Using a text format to run autolisp routines over multiple drawings
« Reply #26 on: July 27, 2006, 11:15:59 AM »
ok here is an update.  It seems to me that I have everything working perfectly right now.  But one issue I have is with converting ellipses to plines.  It works great on actual ellipses but not elliptical arcs.  The program takes the arc and draws it in its full elliptical state and does not trim or break it back to look like the arc it is supposed to look like.  If anyone can help on this it would be much appreciated.

<snip>
If this is the only thing left, you might want to start a new thread, so that others will notice. I don't work much with ellipses, so I can't really be much help there.
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 #27 on: July 27, 2006, 12:31:47 PM »
Ok good point. New thread is getting started.

Dinosaur

  • Guest
Re: Using a text format to run autolisp routines over multiple drawings
« Reply #28 on: July 27, 2006, 01:52:28 PM »
Luis has been working on a routine recently that could possibly turn into what you are looking for.  Have a look at THIS thread to see it in action.