Bill Tillman Posted May 2, 2012 Posted May 2, 2012 This has to do once again with my totally automated process. And this seems to be an intermittent problem. The code has been running great for several days and there is more than one version of it running fine. But now it's crashing at a certain point each time. I can stop and restart AutoCAD and it will run fine, once, but then it will crash at the same place on subsequent runs. I have also transferred this to my home machine and running it remotely on that machine ACAD 2012 it seems to be alright. It's just so cumbersome running it remote that I really need to be running this locally on this ACAD 2009 machine. This part of the code was added recently to handle a request from the users. While in the Excel spreadsheet where this whole process starts, I use VBA code to select and copy to the clipboard a range of cells, A1 thru K93 on one of the sheets. When the LISP program starts the first thing I want to do is to copy this (a bill of materials) to a isolated place in model space. No matter how many times I tried this the darn thing kept inserting the OLE object in the wrong place. The only way I found to do it was to draw a long horizontal line out close to where I want the OLE object to end up, do a zoom "All" then pasteclip the OLE object in place. The finished code snippet is like this: (vla-put-DisplayOLEScale (vla-get-System (vla-get-Preferences (vlax-get-acad-object))) :vlax-false) (command "._LINE" '(0.0 0.0) '(-180.0 0.0) "") (setq l1 (entlast)) (command "._ZOOM" "A") (command "._PASTECLIP" '(-170.0 0.0)) (vla-put-DisplayOLEScale (vla-get-System (vla-get-Preferences (vlax-get-acad-object))) :vlax-true) (command "._ERASE" l1 "") (setq l1 nil) As you can see once I draw this horizontal line I then erase it after the OLE is in place and all works well. Except up until today the thing started going south on me. I have narrowed it down to the ERASE command in this snippet. If I comment this line out all works well. And recall that on the first run this works and has been working all day yesterday. I also use the erase command in about a 1/2 dozen other places in this code and those work fine. It's only this one which is acting up and again, it's very strange how it will work and then not work. I was running this all morning, time and time again and it was buzzing along. Then suddenly I hit this snag. The ACAD text box shows this error message: *Invalid selection* Expects a point or Window/Last/Crossing/BOX/ALL/Fence/WPolygon/CPolygon/Group/Add/Remove/Multiple/P revious/Undo/AUto/SIngle/SUbobject/Object Error: Function cancelled Error Resetting Enviroment Quote
Lt Dan's legs Posted May 2, 2012 Posted May 2, 2012 try this instead.. (vlax-invoke (vlax-get-acad-object) 'zoomwindow '(0. 0. 0.) '(-180. 0. 0.)) or (vla-zoomwindow (vlax-get-acad-object) (vlax-3d-point '(0. 0. 0.)) (vlax-3d-point '(-180. 0. 0.))) Check your yahoo email. I sent you some good info in that zip file Quote
Bill Tillman Posted May 2, 2012 Author Posted May 2, 2012 Thanks Lee, the entdel command appears to be the 800 lbs gorilla which resolved this. I'm still working on the vlax/vla stuff...it's difficult to get the time for it and I've been knocked out of the box with allergies lately. I keep praying for rain as it washes the pollen out of the air for at least a while. Quote
Lee Mac Posted May 2, 2012 Posted May 2, 2012 Bill, A few comments on your code: Instead of repeatedly calling (vlax-get-acad-object), then trudging through the object hierarchy every time to get the System Preferences Object, I would suggest storing this object using a local variable, then calling the variable to reference the object. As with System Variables, users will not take kindly to their CAD environment being altered after running a custom program. It is always good practice to reset all aspects of the environment to the previous settings in place before the program was executed. In this respect, I would suggest that you first store the existing setting of the DisplayOLEScale property before changing it. Finally, you seem to be going a very long way about setting the insertion point for your OLE Object, involving drawing long lines, zooming in and out, etc etc. Why not simply set the InsertionPoint property of the OLE VLA-Object, e.g.: (defun c:test ( / ent ols sys ) (setq sys (vla-get-system (vla-get-preferences (vlax-get-acad-object))) ols (vla-get-displayolescale sys) ent (entlast) ) (vla-put-displayolescale sys :vlax-false) (command "_.pasteclip" "_non" '(-170.0 0.0)) (if (and (not (equal ent (setq ent (entlast)))) (eq "OLE2FRAME" (cdr (assoc 0 (entget ent)))) ) (vla-put-insertionpoint (vlax-ename->vla-object ent) (vlax-3D-point '(-170.0 0.0))) ) (vla-put-displayolescale sys ols) (princ) ) 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.