LEODAVINCI Posted November 1, 2013 Posted November 1, 2013 Hi, I have AutoCad Electrical 2013 and am trying to run a Lisp script on a set of drawings in a project and am running into issues. I got the script from this site (http://myacade.blogspot.in/2012/04/auto-trim-wires-from-plc-io-utility.html) and it works great for what it does. I generate my IO the TRIM HERE block gets inserted on the extra lines and everything is great. I then run the TRIMIT command from commandline and it deletes the TRIMHERE block and executes AETRIM at each insertion point. Perfect. Now I want to have a script that will open each of the new drawings, run the TRIMIT command, wait for it to finish, save and close. I have tried: _.open "DWGNAME" trimit _.qsave _.close When i run that script it opens the drawing, executes TRIMIT, saves and closes, but it doesnt wait for TRIMIT to completely finish before saving and closing. Trimit deletes all of the TRIMHERE blocks but doesnt execute the actual AETRIM command before the script continues. Any version of that script I have tried does the same thing. I also tried the ScriptWriter tool from Lee Mac (wonderful tools there btw). I tried the DELAY command in the code like the section below but all it does is delay the same results. _.open "DWGNAME" trimit DELAY 1000 _.qsave _.close I also tried a lot more stuff that I have found searching on the web but nothing seems to work. I tried putting the save and close commands at the end of the trimacadewires and get the same result, I tried embedding the commands into the lisp routine at logical points and just get syntax error. Unfortunately I dont know enough about lisp to be able to figure it out and without knowing what is happening my search results have not been very useful. Any suggestions on how I can get this LISP to execute completely and then save and close the drawing? Quote
Lee Mac Posted November 1, 2013 Posted November 1, 2013 It could be the use of sendcommand in the LISP program which is causing the Script to think that the LISP program has already completed. As a shot in the dark, try using: _.open "DWGNAME" (c:trimit) _.qsave _.close Quote
LEODAVINCI Posted November 1, 2013 Author Posted November 1, 2013 Lee, Thanks, but that didnt work either. Same results. Doesn't wait before save/close. EG Quote
Lee Mac Posted November 1, 2013 Posted November 1, 2013 I don't have AutoCAD Electrical to test, but try changing the TRIMIT program to: (defun c:trimit ( / e i s ) (if (setq s (ssget "_X" '((0 . "INSERT") (2 . "TRIMHERE")))) (progn (command "_.AETRIM") (repeat (setq i (sslength s)) (setq e (ssname s (setq i (1- i)))) (command "_non" (cdr (assoc 10 (entget e)))) (entdel e) ) (command "") ) ) (princ) ) However, first try the above program manually on an open drawing to ensure that the program functions correctly before using it in conjunction with the AutoCAD Script. Quote
jdiala Posted November 1, 2013 Posted November 1, 2013 What about incorporating the save and close command to you trimit. _.open "DWGNAME" (c:trimitandclose) (defun c:[color="red"]trimitandclose[/color] () (vl-load-com) (setq adoc (vla-get-activedocument (vlax-get-acad-object))) (if (setq ssBlks (ssget "_X" '((0 . "INSERT") (2 . "TRIMHERE")))) (progn (setq cnt (sslength ssBlks)) (repeat cnt (setq entname (ssname ssBlks (setq cnt (1- cnt)))) (setq ent (entget entname)) (setq inspt (cdr (assoc 10 ent))) (setq xy (strcat (rtos (car inspt)) "," (rtos (cadr inspt)) ) ) (setq cmd1 "AETRIM ") (if (= 0 cnt) (progn (setq cmd2 (strcat xy "\r" "\r")) ) (progn (setq cmd2 (strcat xy "\r")) ) ) (if (= (1- (sslength ssBlks)) cnt) (progn (vla-sendcommand adoc cmd1) ) ) (vla-sendcommand adoc cmd2) (entdel entname) ) ) (princ "\n Error - No entities selected.") ) [color="red"](command "_.qsave" "_.close")[/color] ) Quote
LEODAVINCI Posted November 1, 2013 Author Posted November 1, 2013 Lee, Your program deleted the TRIMHERE blocks, but then I got "Unknown command "NON". Press F1 for help" for each instance of the block and it did not trim the wires. Also, it gives me "Unknown command AETRIM. Press F1 for help" at the beginning. Here is the execution history in case it helps: Command: trimitlm _.AETRIM Unknown command "AETRIM". Press F1 for help. Command: _non Unknown command "NON". Press F1 for help. Command: Command: TRIMITLM Unknown command "TRIMITLM". Press F1 for help. Command: jdiala, Your program at least compiled and executed, which was further than I got when trying to insert the commands into the lsp, but unfortunately it still gave the same results of deleting the block, not running the AETRIM command and then saving and closing. Any other suggestions would be great. Thanks, EG 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.