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

0 Members and 1 Guest are viewing this topic.

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.