Engineer_Yasser Posted April 4 Posted April 4 (edited) How to force running commands in the created drawing ? I created a new drawing using ( vla-add ) The code creates a point in the created drawing but ( zoom extents ) in the original drawing not the created drawing .. anyone can help in this ? (defun C:DRZ (/ acadApp acadDoc) (vl-load-com) (setq acadApp (vlax-get-acad-object)) (setq acadDoc (vla-Add (vla-get-Documents acadApp))) (vla-AddPoint (vla-get-ModelSpace acadDoc) (vlax-3d-point 10000 10000 0)) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (vla-put-ActiveDocument acadApp acadDoc) (vla-ZoomExtents acadApp) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (vla-Activate acadDoc) (vla-SendCommand (vla-get-activedocument (vlax-get-acad-object)) (strcat "Zoom" " " "e" " ")) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (princ) ) (princ) Sorry for the inconvenience @BIGAL @Lee Mac @Nikon @Steven P @rlx Edited April 4 by Engineer_Yasser Quote
GLAVCVS Posted April 4 Posted April 4 Hi @Engineer_Yasser If you have created a new drawing from code, to create new objects in it, you will need to assign the vla object name of the new drawing to 'activeDocument'. Quote
Engineer_Yasser Posted April 4 Author Posted April 4 9 minutes ago, GLAVCVS said: Hi @Engineer_Yasser If you have created a new drawing from code, to create new objects in it, you will need to assign the vla object name of the new drawing to 'activeDocument'. @GLAVCVS Thanks for replying .. could you explain by example code please i need to zoom extents in the created drawing Quote
GLAVCVS Posted April 4 Posted April 4 I just reviewed your code and it works fine for me. I've even tried creating more objects from your code and it loads them correctly in the new drawing. Quote
Engineer_Yasser Posted April 4 Author Posted April 4 (edited) 33 minutes ago, GLAVCVS said: I just reviewed your code and it works fine for me. I've even tried creating more objects from your code and it loads them correctly in the new drawing. @GLAVCVS The point creation done OK but Zoom Extents never happened Edited April 4 by Engineer_Yasser Quote
GLAVCVS Posted April 4 Posted April 4 I believe 'vla-zoomExtents' can't work in a drawing that's still being opened and whose parameters AutoCAD hasn't yet calculated. Let's say 'zoomExtents' is too fast here. The closest solution is for your code to calculate the parameters of the display window and apply them from 'vla-zoomWindow'. Quote
Engineer_Yasser Posted April 4 Author Posted April 4 6 minutes ago, GLAVCVS said: I believe 'vla-zoomExtents' can't work in a drawing that's still being opened and whose parameters AutoCAD hasn't yet calculated. Let's say 'zoomExtents' is too fast here. The closest solution is for your code to calculate the parameters of the display window and apply them from 'vla-zoomWindow'. @GLAVCVS Do you have any example code to test your idea ? Quote
BIGAL Posted April 4 Posted April 4 Have you thought about using a script, it can open a new dwg and will automatically then be in that dwg. Script code. (command "New" "Yourtemplatename") (alert "now in other dwg do your lisp code here") version 2 (command "New" "Yourtemplatename") (load "your lisp program") 1 1 Quote
Engineer_Yasser Posted April 4 Author Posted April 4 (edited) 1 hour ago, BIGAL said: Have you thought about using a script, it can open a new dwg and will automatically then be in that dwg. Script code. (command "New" "Yourtemplatename") (alert "now in other dwg do your lisp code here") version 2 (command "New" "Yourtemplatename") (load "your lisp program") @BIGAL I have a lisp code and i want to make zoom extents to the created drawing .. can you ? Edited April 4 by Engineer_Yasser Quote
GLAVCVS Posted April 4 Posted April 4 Definitely: not possible. At least with my version of AutoCAD. Any line of code after the new drawing is created will not be executed in it. If zoomExtents is so important, you should consider an indirect solution (which I've never tried, but which may be possible): write a LISP in 'acad.lsp' so that it does a 'zoomExtents' when each drawing is opened. Perhaps someone can share their experience in this regard. 1 Quote
Steven P Posted April 5 Posted April 5 (edited) Yes, LIPS is session based, that means you start a command in one drawing, it will run on one drawing and (generally) not run in another. A few ways round this. As BigAl says a script can cross drawings, open or create a new drawing, run commands in it. You could adjust the acad.lsp file, this runs on opening / creating a drawing, but your changes will run on every subsequent drawing Expanding acad.lsp file idea, you could add the below to acad.lsp file. Will work on EVERY new drawing. You could create the below as a stand alone LISP file, add it it the startup suit. Will work on EVERY new drawing You could create a temporary LISP file, search for it and if it exists run it (using acad.lsp or a file in the startup suit)... though of course you'd have to consider deleting after running. Will work on EVERY new drawing till temp file is deleted (can do that with LISP once it is loaded delete the file) Last one is a bit related, have a list of say, filename prefix and if the file name prefix is in this list do stuff... handy if say a clients drawings are all in the form "12345-dwg-001.dwg", search 123456 and if yes, do stuff. A step further on from the 'if new drawing do stuff' idea above All depends how your mind works and which you think is the best solution for you. (defun c:testthis ( / SavedDrawing ) (setq SavedDrawing (getvar "dwgtitled")) (if (= SavedDrawing 1) (progn (alert "Drawing has been saved, is not a new drawing") ) ; end progn (progn ; savedDrawing = 0 (alert "Drawing has not been saved, is a new drawing") ) ; end progn ) ; end if (princ) ) (c:testthis) ;; run on loading Edited April 5 by Steven P 1 Quote
pkenewell Posted April 8 Posted April 8 (edited) This is a way that I have found to do it: 1) Start the LISP that will open the new drawing. 2) In this LISP, set a variable to the Blackboard namespace via (vl-bb-set), alternatively, you could set a value in the registry or a temporary text file. 3) Add a portion to the startup code in "acaddoc.lsp" to check the value of the variable using (vl-bb-ref), and if set, perform the (vla-ZoomExtents). 4) clear the variable previously set with (vl-bb-set) again to set the value to nil. Edited April 8 by pkenewell 1 Quote
SLW210 Posted April 8 Posted April 8 I didn't look into what your code is doing, but if you use QNEW, focus goes to the new drawing. 1 Quote
GLAVCVS Posted April 8 Posted April 8 If achieving zoom extensions is so important and you can't do it any other way, the quickest solution might be to write a DXF and define the initial view in it. But I suppose you'd have to find a simpler solution. 1 Quote
GLAVCVS Posted April 9 Posted April 9 17 hours ago, pkenewell said: This is a way that I have found to do it: 1) Start the LISP that will open the new drawing. 2) In this LISP, set a variable to the Blackboard namespace via (vl-bb-set), alternatively, you could set a value in the registry or a temporary text file. 3) Add a portion to the startup code in "acaddoc.lsp" to check the value of the variable using (vl-bb-ref), and if set, perform the (vla-ZoomExtents). 4) clear the variable previously set with (vl-bb-set) again to set the value to nil. @pkenewell Does this really work? Have you tried it? Quote
Steven P Posted April 9 Posted April 9 Yes, it should work - he is setting a flag in the registry, a temporary file or in Blackboard (never used that), when a new file is opened acaddoc.lsp checks for this flag and does stuff, clearing the flag afterwards Quote
GLAVCVS Posted April 9 Posted April 9 (edited) It doesn't seem easy to find a solution to this. I've tried adding code to AcadDoc.lsp to create reactors. First, I tried using an 'editor-reactor' ('...-endDwgOpen'), and nothing related to the view parameters is executed. Then I tried using a 'command-reactor' to try to activate it with '(command "_pan"...)', and that doesn't work either. Nothing seems to be able to modify the initial view until after any startup code has been loaded/executed. Edited April 9 by GLAVCVS Quote
GLAVCVS Posted April 9 Posted April 9 And I think I just discovered the reason: "EXTMIN" / "EXTMAX" are not the same when the startup code is loaded as they are after the user begins interacting with the drawing. Somehow, the initial view parameters of the newly created drawing aren't determined until it's made available to the user. Quote
SLW210 Posted April 9 Posted April 9 What makes you believe the Zoom Extents isn't working? With a single Point Object in a drawing, with the point just being a small point, it never centers in the screen. If you change PDMODE to something like a line or crosshairs, zoom extents works. Quote
GLAVCVS Posted April 9 Posted April 9 37 minutes ago, SLW210 said: What makes you believe the Zoom Extents isn't working? With a single Point Object in a drawing, with the point just being a small point, it never centers in the screen. If you change PDMODE to something like a line or crosshairs, zoom extents works. I've added a couple of 'vla-addLine' with distant coordinates to ensure that objects don't accidentally appear on the default screen coordinates If this doesn't happen to you, I'll have to assume I have a problem with my version of AutoCAD. 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.