Bhanson Posted February 23, 2011 Posted February 23, 2011 For some reason my script does not want to run properly when I use a lisp routine that accesses information in an entity and then modifies it...? Any Ideas? If you need examples of the code I would be happy to provide it. But here is a synopsis of the Script... Open a file; Edit the file using a lisp routine (which modifies entities in an existing drawing); Then save that file as a .DXF and a .DWG then close the file and open another one; Rinse and Repeat... The script simply cancels after it finishes the LISP Routine and does not move on to save the files, and it does not close the open drawing. Your help is greatly appreciated Thanks. Quote
BIGAL Posted February 24, 2011 Posted February 24, 2011 You need to post it to see what is wrong Quote
Bhanson Posted February 24, 2011 Author Posted February 24, 2011 LISP: (defun C:TU1 ( ) (setq osvalue (getvar "osmode")) (command "osmode" 0) (command "zoom" "e") (command ".explode" (ssget "_C" '(0.0 10.0) '(1.0 10.1)) ""); Explode Cutline from Pline (command "zoom" "e") (setq selection (ssget "_C" '(15.0 15.0) '(150.0 15.1)) ); Define Selection (setq ent_name (ssname selection 0)); Determine DXF Code name of selection (setq ent_REARline (entget ent_name)); Retreive entity's definition data (print ent_REARline); print that data ; Determine Cover Length (command "zoom" "e") (setq REARline_xyz (cdr (assoc 10 ent_REARline))); select an endpoint of the rearline (print "REARline_XYZ 10: ")(print REARline_xyz)(princ "\n") (setq REARx (car REARline_xyz)); Determine x value of rear vertical line (print "REAR X value: ")(print REARx) ; Convret cut line back to polyline (command "zoom" "e") (command ".pedit" "M" (ssget "x" '((8 . "CUT"))) "" "Y" "Join" "" ""); re-defign cut line as pline (setq CvrLen REARx); set rear line x value as the cover length (princ "Length ")(princ CvrLen)(print) ; Change Cover Length ; In front of Rear Bow (command "zoom" "e") (setq sel_a (list (- CvrLen 25.0) 0.0) ); set selection (setq sel_b (list 150.0 150.0) ); set selection (setq stretchLen -0.09375); determine stretch ammount (setq SX (rtos stretchLen) SY (rtos 0.0)); set stretch points (command ".stretch" (ssget "_C" sel_a sel_b) "" "0,0" (strcat SX "," SY)); stretch command ; Behind Front Bow (command "zoom" "e") (setq sel_a (list 25.0 0.0) ); set selection (setq sel_b (list 150.0 150.0) ); set selection (setq stretchLen -0.09375); determine stretch ammount (setq SX (rtos stretchLen) SY (rtos 0.0)); set stretch points (command ".stretch" (ssget "_C" sel_a sel_b) "" "0,0" (strcat SX "," SY)); stretch command (command "zoom" "e") (command "osmode" osvalue) (princ) ); End of TU1 Script: _FILEDIA 0 _OPEN "C:\Users\Bhanson\Desktop\LISP & SCRIPT\2711.dwg" TU1 DXFCOVER "C:\Users\Bhanson\Desktop\LISP & SCRIPT\TEST COVERS\ 2711 " _SAVEAS 2007 "C:\Users\Bhanson\Desktop\LISP & SCRIPT\TEST COVERS\ 2711 " _CLOSE _OPEN "C:\Users\Bhanson\Desktop\LISP & SCRIPT\2811.dwg" TU1 DXFCOVER "C:\Users\Bhanson\Desktop\LISP & SCRIPT\TEST COVERS\ 2811 " _SAVEAS 2007 "C:\Users\Bhanson\Desktop\LISP & SCRIPT\TEST COVERS\ 2811 " _CLOSE _FILEDIA 1 There it is... The LISP code works just fine when I run it through the command line but when I run the script it simply does not work (see above post). Quote
David Bethel Posted February 24, 2011 Posted February 24, 2011 You need to either (load) the lisp file either through the command line or an automatic ( appload ) type of application. -David Quote
Bhanson Posted February 24, 2011 Author Posted February 24, 2011 (edited) You need to either (load) the lisp file either through the command line or an automatic ( appload ) type of application. -David Could you please explain further. The Lisp is not the problem.. at least I don't think it is. The Lisp is automatically loaded when the file is opened using and acaddoc file. I'm confused? Edited February 24, 2011 by Bhanson Quote
BlackBox Posted February 24, 2011 Posted February 24, 2011 Having only glanced at your code, I didn't see anything that would prevent your using ObjectDBX (ODBX) - it is significantly more efficient. Quote
David Bethel Posted February 24, 2011 Posted February 24, 2011 Could you please explain further. The Lisp is not the problem.. at leas I don't think it is. The Lisp is automatically loaded when the file is opened using and acaddoc file. I'm confused? In that case, try using (c:tu1) in the script. -David Quote
Bhanson Posted February 24, 2011 Author Posted February 24, 2011 Having only glanced at your code, I didn't see anything that would prevent your using ObjectDBX (ODBX) - it is significantly more efficient. I am not familiar with ObjectDBX is there a site I can use as a resource to learn about it or somewhere to take tutorials that you would reccomend? Thanks Quote
BlackBox Posted February 24, 2011 Posted February 24, 2011 I am not familiar with ObjectDBX is there a site I can use as a resource to learn about it or somewhere to take tutorials that you would reccomend? I first learned about ODBX completing this Autodesk University course, and then posted this thread. Thanks to Robert Bell for his AU course, and code in the above linked thread! Quote
alanjt Posted February 24, 2011 Posted February 24, 2011 Right off the bat, since he calls PEdit, I'd say that ODBX is out. You can't use command calls in ODBX and I doubt he wants to write his own PEdit. Quote
BlackBox Posted February 24, 2011 Posted February 24, 2011 Having only glanced at your code... Right off the bat, since he calls PEdit... Yeah - 23 lines deep, lol I'd say that ODBX is out. You can't use command calls in ODBX and I doubt he wants to write his own PEdit. Alan is correct about the limitations of ODBX (see the document I referenced above for more info), had I spied that line, I would not have suggested ODBX. Better luck next time! Quote
alanjt Posted February 24, 2011 Posted February 24, 2011 Yeah - 23 lines deep, lol LoL, I just rolled the mouse wheel and glassed for the word command. Quote
Lee Mac Posted February 24, 2011 Posted February 24, 2011 If you decide to got the ObjectDBX route, this may be of help: http://lee-mac.com/odbxbase.html But, yeah, as these guys have said - you'll have to VL'ise your code Quote
Bhanson Posted February 25, 2011 Author Posted February 25, 2011 Ok I have taken a few of your suggestions but I am doing everything in my power to keep from having to re-write all of my code and learn ODBX although I'm sure it's not that bad. On the other hand I did try a few of your suggestions and came up short. I did however find that when I do not run the LISP (TU1) in my Script the script works flawlessly as it should (minus the lisp which is the whole point so I guess it's not flawless so to speak). When I run the script without the Lisp function (TU1) it properly opens the file, saves that file as a .DXF and a .DWG, Closes and then moves on to the next file and it all starts over. I have written many Lisp and Script programs that are mated together in an almost identical fashion with different Lisp routines. I never had this problem until I started to use ent* methods such as (entmod) and (entget). Any ideas? Below I have attached a similar LISP that is used by an almost identical Script where (Txptupd) is substituted for (TU1) and I am encountering the same problem. (defun C:TxptUpd () (setq osvalue (getvar "osmode")) (command "osmode" 0) (command "zoom" "e") ; Explode cut line (command ".explode" (ssget "_C" '(0.0 10.0) '(1.0 10.1)) "") ; Select Passenger Side Length Line (setq selection (ssget "_C" '(5.0 20.0) '(5.1 150.0)) ) (setq ent_name (ssname selection 0)) (setq ent_PAline (entget ent_name)) (print ent_PAline) ; Select Driver Side Length Line (setq selection (ssget "_C" '(5.0 0.0) '(5.1 20.0)) ) (setq ent_name (ssname selection 0)) (setq ent_DRline (entget ent_name)) (print ent_DRline) ; Set PA side Length Line end points (setq PAline_p1 (cdr (assoc 10 ent_PAline))) (setq PAline_p2 (cdr (assoc 11 ent_PAline))) (print "PAline_p1: ")(print PAline_p1)(princ "\n") (print "PAline_p2: ")(print PAline_p2)(princ "\n") ; Set DR side Length Line end points (setq DRline_p1 (cdr (assoc 10 ent_DRline))) (setq DRline_p2 (cdr (assoc 11 ent_DRline))) (print "DRline_p1: ")(print DRline_p1)(princ "\n") (print "DRline_p2: ")(print DRline_p2)(princ "\n") ; Determine pA, pB, pC, pD (setq PA1x (car PAline_p1)) (setq PA2x (car PAline_p2)) (setq DR1x (car DRline_p1)) (setq DR2x (car DRline_p2)) (princ "\n") (princ "Point 1x top line: ")(princ PA1x)(princ "\n") (princ "Point 2x top line: ")(princ PA2x)(princ "\n") (princ "Point 1x bottom line: ")(princ DR1x)(princ "\n") (princ "Point 2x bottom line: ")(princ DR2x)(princ "\n") ; Cover Point Layout ; (ptA----ptB) ;Front | | Rear ;Front | | Rear ; (ptC----ptD) ; Determine which PAline point is closer to the front of the cover (if (< PA1x PA2x) (progn (setq ptA (cdr (assoc 10 ent_PAline))) (setq ptB (cdr (assoc 11 ent_PAline))) ); TRUE (progn (setq ptA (cdr (assoc 11 ent_PAline))) (setq ptB (cdr (assoc 10 ent_PAline))) ); FALSE ) ; Determine which DRline point is closer to the front of the cover (if (< DR1x DR2x) (progn (setq ptC (cdr (assoc 10 ent_DRline))) (setq ptD (cdr (assoc 11 ent_DRline))) ); TRUE (progn (setq ptC (cdr (assoc 11 ent_DRline))) (setq ptD (cdr (assoc 10 ent_DRline))) ); FALSE ) (princ " A: ")(princ ptA)(princ " B: ")(princ ptB)(print) (princ " C: ")(princ ptC)(princ " D: ")(princ ptD) ; Determine Point Layout X and Y (setq ptAx (car ptA))(setq ptAy (cadr ptA)) (setq ptBx (car ptB))(setq ptBy (cadr ptB)) (setq ptCx (car ptC))(setq ptCy (cadr ptC)) (setq ptDx (car ptD))(setq ptDy (cadr ptD)) (print "A:")(princ ptAx)(princ ",")(princ ptAy) (print "B:")(princ ptBx)(princ ",")(princ ptBy) (print "C:")(princ ptCx)(princ ",")(princ ptCy) (print "D:")(princ ptDx)(princ ",")(princ ptDy) ; Determine Cover Dimensions (setq Cover_Len (+ ptBx 1.7685)) (setq Cover_taper (- ptAy ptBy)) (if (> Cover_taper 0.0); Determine if there is a taper. (setq taper_direction "Cover Tapers from Cab to Tail") (setq taper_direction "Cover Tapers from Tail to Cab") ) (if (and (< Cover_taper 0.01) (> Cover_taper -0.01)); determine if there is no taper (setq taper_direction "Cover DOES NOT Taper") ) (print) (princ "Cover Length: ")(princ Cover_Len) (print) (princ "Cover Taper: ")(princ Cover_Taper) (print)(princ taper_direction) ;**************Begin While Loop**************** (setq count 1) (while (<= count 4.0) (print)(princ "Count is: ")(princ count)(print) (cond ((= count 1); point A (setq calca -)(setq calcb +)(setq calcc -) (setq ptNx ptAx)(setq ptNy ptAy) (setq scale_ammt 0.97) ); end of first condition ((= count 2); point B (setq calca +)(setq calcb -)(setq calcc -) (setq ptNx ptBx)(setq ptNy ptBy) (setq scale_ammt 0.935) ); end of second condition ((= count 3); point C (setq calca -)(setq calcb +)(setq calcc +) (setq ptNx ptCx)(setq ptNy ptCy) (setq scale_ammt 0.97) ); end of third condition ((= count 4); point D (setq calca +)(setq calcb -)(setq calcc +) (setq ptNx ptDx)(setq ptNy ptDy) (setq scale_ammt 0.935) ); end of fourth condition ) ; Set Selection points for Top Right (setq sel_1 (list (calca ptNx 1.2) (calcc ptNy 0.9)) ) (setq sel_2 (list (calca ptNx 1.4) (calcc ptNy 1.25)) ) (setq sel_3 (list (calca ptNx 1.4) (calcc ptNy 1.3)) ) (setq sel_4 (list (calca ptNx 1.41) (calcc ptNy 1.65)) ) (setq sel_5 (list (calca ptNx 1.0) (calcc ptNy 2.5)) ) (setq sel_6 (list (calca ptNx 1.25) (calcc ptNy 3.0)) ) (setq sel_9 (list (calcb ptNx 0.2) (calcc ptNy 2.0)) ) (setq sel_10 (list (calca ptNx 1.00) (calcc ptNy 2.25)) ) (setq sel_11 (list (calca ptNx 0.5) (calcc ptNy 2.5)) ) (setq sel_12 (list (calca ptNx 1.25) (calcc ptNy 3.0)) ) (setq sel_14 (list (calcb ptNx 0.6) (calcc ptNy 0.) ) (setq sel_15 (list (calcb ptNx 0.3) (calcc ptNy 0.9)) ) ; Edit Drawing lines on cover to New Style ;***************************************** ; Edit Drawing lines (command "zoom" "e") (command ".explode" (ssget "_C" sel_1 sel_2)); Explode Dart in corner (command ".offset" 0.375 (ssget "_C" sel_1 sel_2) sel_12 ""); Offset Dart (command "zoom" "e") (setq selection (ssget "_C" sel_3 sel_4)); Modify Newline Entities (setq ent_name (ssname selection 0)) (setq ent_temp (entget ent_name)) (setq ptM (cdr (assoc 10 ent_temp))) (setq ptN (cdr (assoc 11 ent_temp))) ; Find Center of Newline (setq center (list (+ (/(-(car ptM) (car ptN))2.0) (car ptN)); Find Center X Value (+(/(-(cadr ptM) (cadr ptN))2.0)(cadr ptN)) ) ); Find Center Y Value (command "scale" (ssget "_C" sel_3 sel_4) "" center scale_ammt ""); Scale Down Newline Entities (command "explode" (ssget "_C" sel_11 sel_12) ); Explode L shape pline close to center (command "zoom" "e") (command ".extend" (ssget "_C" sel_9 sel_10) "" (ssget "_C" sel_3 sel_4) ""); EXtend Newline to Left side of L ;(command ".trim" (ssget "_C" sel_3 sel_4) "" (ssget "_C" sel_9 sel_10) "") (Command ".explode" (ssget "_C" sel_14 sel_15)) (command "erase" (ssget "_C" sel_5 sel_6) ""); Erase Bottom of L (this one ^) (setq selection (ssget "_C" sel_14 sel_15)) (setq ent_name (ssname selection 0)) (setq ent_temp (entget ent_name)) (setq ptM (cdr (assoc 10 ent_temp))) (setq ptN (cdr (assoc 11 ent_temp))) (setq **** (list (car ptN)(calcc (cadr ptN) 0.7)(caddr ptN) ) ) (setq ent_temp (subst (cons 11 ****)(assoc 11 ent_temp) ent_temp)) (entmod ent_temp) (setq count (+ count 1)) ); END WHILE LOOP ;***************************************** ; End Edit Drawing Lines (command "zoom" "e") ; Convert cut line back to polyline (command ".pedit" "M" (ssget "x" '((8 . "CUT"))) "" "Y" "Join" "" "") (setq ptA nil ptB nil ptC nil ptD nil p1x nil p2x nil) (princ "\n") (command "osmode" osvalue) (command "regen") (command "zoom" "e") (princ "DONE") (princ); Close Cleanly ); END OF TruXportUpdate (princ); Load Cleanly P.S. Anyone is free to use any of the code I have posted anywhere on this site unless otherwise noted. I am not asking for any credit because I truly don't care but a simple thank you for the post would be greatly appreciated. It's nice to know someone benefits from your work. Happy Coding! Thanks Everyone for your help!! I hope this helps us come up with the problem Quote
BlackBox Posted February 25, 2011 Posted February 25, 2011 Thanks Everyone for your help!! I hope this helps us come up with the problem Hey Freud, watch your step or you'll slip. I do enjoy (and suffer from!) a good parapraxis every now and then. Quote
Bhanson Posted February 25, 2011 Author Posted February 25, 2011 In my defense I wrote that post after a few beers while beating my head on my keyboard trying to find the solution. :wink: There has to be someone out there who has some clue about why the program simply stops after it finishes the Lisp while running the script, but that most definitely is not me. Quote
David Bethel Posted February 26, 2011 Posted February 26, 2011 Maybe there is a confusion of terms. I don't see a (command "_.SCRIPT" ...) in your code, but if it does some where in 1 of the peripherals, Autolisp always gives over complete command to the script and will not continue. It has been that way as long as I can remember. Otherwise I'm guessing that you are not completing a command some where. -David Quote
Bhanson Posted February 28, 2011 Author Posted February 28, 2011 David- I guess I am having trouble understanding what you mean when you say that there may be a command that hasn't been completed please explain... The reason It doesn't say _.SCRIPT in my code is that it is run by a program from http://www.scriptsheets.com/ It is a program that writes scripts using a program in Microsoft Excel an then runs from a button in my autocad toolbar if that helps clarify, But are you saying that there might be something wrong with how the code transitions from the Lisp function and back to the other functions in the script? I am fairly new to using ent* commands such as _entmod Is there some syntax that I may have missed that is required when I use these type of commands. is there something that has to do with the status of the _filedia whether it is set at 1 or 0 when performing these operations? I know that if I want to run a command to save I need the _filedia set to a different number but could that be causing the problem? I am just shooting in the dark her hoping that it will trigger some idea for someone. Quote
BIGAL Posted February 28, 2011 Posted February 28, 2011 Whats dxfcover ? I think thats your problem Also just a personal thing I would not use & in file names Quote
Bhanson Posted February 28, 2011 Author Posted February 28, 2011 Whats dxfcover ? I think thats your problem Also just a personal thing I would not use & in file names dxfcover is a short lisp function that I wrote to create a dxf file in a particular way in order for it to be used for a cnc fabric cutter. and Why wouldn't you use the & symbol is it simply a personal preference or is there some backing to it. Just wondering. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.