dbroada Posted January 4, 2013 Author Posted January 4, 2013 I would also recommend that you save the above function definition to a separate LISP file in your support path, and then load the LISP file from your Script (using the load function) as you may encounter problems defining some functions containing comments by entering the function definition at the command-line using a Script.That is roughly where I came in. I am trying to keep everything in one script so it is totally independant of support paths. Our networks get renamed on a too frequent basis and it can take hours just repathing each machine. I will store the final iteration of your routine somewhere safe but issue the script built version. If it causes problems I can rewrite my VB6 code to create the lisp file in the current folder (in fact I may try that anyway). Oh why does project work get in the way...... Quote
dbroada Posted January 9, 2013 Author Posted January 9, 2013 OK, progress report. I now have your (Lee) LISP file being created in a sub folder of the current project by my VB6 program and the script now loads the LISP early on. sdi 1 (load "P:\\Design_Office\\ZZZ - Loop Test\\db$Convert.LSP") zoom e new y acadiso (DxfImportAll "P:\\Design_Office\\ZZZ - Loop Test\\Output\\TEST-00-LD-0001-001.dwg_0.dxf") zoom e new y and this is where the fun begins. On my machine this works well. On the two other machines I have tried it works well the second time it is run. The first time through I get a "no definition DXFImportAll" (or similar). My guess is that it is a timing problem and that the LISP file is still loading while the script is racing away. Do you think that is the problem? If you do agree, can you recommend how to delay the script? I don't really want to NoOp in a loop but will if I have to. Quote
Lee Mac Posted January 9, 2013 Posted January 9, 2013 I doubt that the issue is being caused by a delay in loading the LISP file since this should be very quick indeed for such a small amount of code. Are you certain that the AutoLISP file is being created correctly by your VB6 code (accounting for escape character sequences), and that the file is successfully loaded? (I would always recommend supplying the second [onfailure] argument to the AutoLISP load function, otherwise this function will throw an error if there is a problem). Quote
dbroada Posted January 9, 2013 Author Posted January 9, 2013 not answering your question, even if AutoCAD is shut down and restarted the script runs perfectly. It appears to only fail on the very first attemp of loading the LISP file. I'm running out of machines to try this on and I am tempted to add a "if the script doesn't run, run it again" line to the work instruction. I can only assume I am constructing the LISP file correctly in VB as it runs subsequently and I only make it once (some milliseconds) before the script is generated. are you suggesting I change the (load "P:\\Design_Office\\ZZZ - Loop Test\\db$Convert.LSP") line above? In what way (he says looking around for his old AutoCAD reference books but hoping Lee will give him a code snippet)? my lisp file (defun DXFImportAll ( myfile / base dir i myscale mytempfile overwite p1 thisdrawing ) (setq ThisDrawing (vla-get-activedocument (vlax-get-acad-object)) P1 (vlax-3D-point 0 0) myScale 1.0 base (vl-filename-base myfile) base (substr base 1 (1- (strlen base))) dir (vl-string-translate "/" "[url="file://\\"(vl-filename-directory"]\\"(vl-filename-directory[/url] myfile)) i 0) (repeat 3 (if (setq myTempFile (findfile (strcat dir "[url="file://\\"base"]\\"base[/url] (itoa i)".dxf"))) (vla-import ThisDrawing myTempFile P1 myScale) ) (setq i (1+ i)) ) (vla-ZoomExtents (vlax-get-acad-object)) (setq overwrite t filename (strcat dir "[url="file://\\"(substr"]\\"(substr[/url] base 1 (1- (strlen base)))) ) (if (or overwrite (not (findfile filename))) (vla-saveas ThisDrawing filename ac2010_dwg) ) (princ) ) Quote
Lee Mac Posted January 9, 2013 Posted January 9, 2013 I can only assume I am constructing the LISP file correctly in VB as it runs subsequently and I only make it once (some milliseconds) before the script is generated. Ah good point, in my haste I had overlooked the fact that the program was running successfully in subsequent runs. are you suggesting I change the (load "P:\\Design_Office\\ZZZ - Loop Test\\db$Convert.LSP") line above? In what way (he says looking around for his old AutoCAD reference books but hoping Lee will give him a code snippet)? Yes, I would recommend that you include the second argument for the load function, e.g.: (load "P:\\Design_Office\\ZZZ - Loop Test\\db$Convert.LSP" "Load Failed.") Or, for a more prominent result: (eval (load "P:\\Design_Office\\ZZZ - Loop Test\\db$Convert.LSP" '(alert "Load Failed."))) The above will display an alert window if the program has failed to load. Quote
dbroada Posted January 9, 2013 Author Posted January 9, 2013 Thanks, line of code about to be added. The problem I now have is that the only machine left to try it on is the bosses! Quote
Lee Mac Posted January 9, 2013 Posted January 9, 2013 The problem I now have is that the only machine left to try it on is the bosses! Fingers crossed nothing goes wrong! Quote
dbroada Posted January 9, 2013 Author Posted January 9, 2013 Fingers crossed nothing goes wrong! I have just added "LISP programming provided by Lee Mac (http://lee-mac.com/)." to the comments section of the compiled routine so I can blame you if necessary. Quote
dbroada Posted January 9, 2013 Author Posted January 9, 2013 and another final question I don't think this is possible but I'll ask just in case you know how to do the impossible with a script, it is possible to "abort script" sfter the "load failed" message? At the moment the script continues starting new drawings and doing nothing with them. Not too bad with my sample set of 30 but the final runs will be mach larger. As scripts work serially would I be best starting a script that loads the LISP file and only if the load works have the lisp file call my final script? Quote
Lee Mac Posted January 9, 2013 Posted January 9, 2013 I have just added "LISP programming provided by Lee Mac (http://lee-mac.com/)." to the comments section of the compiled routine so I can blame you if necessary. Haha! I don't think this is possible but I'll ask just in case you know how to do the impossible with a script, it is possible to "abort script" sfter the "load failed" message? To be honest, I've never tried to abort a Script, however, the following documentation states that a Script may be aborted by pressing Esc: http://docs.autodesk.com/ACD/2013/ENU/index.html?url=files/GUID-95BB6824-0700-4019-9672-E6B502659E9E.htm,topicNumber=d30e500218 So you may be able to use the SendKeys method of the WSH object to issue the Esc key should the Script need to be aborted - but as I say, I've never tried this. Here is a wrapper for the SendKeys method: ;; Send Keys - Lee Mac ;; A wrapper function for the SendKeys method of the WSH (defun LM:SendKeys ( keys / wsh ) (setq wsh (vlax-create-object "wscript.shell")) (vl-catch-all-apply 'vlax-invoke (list wsh 'sendkeys keys)) (vlax-release-object wsh) (princ) ) (vl-load-com) To send Esc: (LM:SendKeys "{ESC}") Quote
dbroada Posted January 9, 2013 Author Posted January 9, 2013 OK, thanks. I'll have a look at that some time but for now the boss has got the work instruction and the routine that runs on if there is an error. I already have a few "improvements" to make so I will wait and see what he finds first. 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.