Engineer_Yasser Posted Friday at 01:55 PM Posted Friday at 01:55 PM (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 Friday at 08:58 PM by Engineer_Yasser Quote
GLAVCVS Posted Friday at 04:53 PM Posted Friday at 04:53 PM 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 Friday at 05:04 PM Author Posted Friday at 05:04 PM On 4/4/2025 at 4:53 PM, 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'. Expand @GLAVCVS Thanks for replying .. could you explain by example code please i need to zoom extents in the created drawing Quote
GLAVCVS Posted Friday at 07:01 PM Posted Friday at 07:01 PM 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 Friday at 07:14 PM Author Posted Friday at 07:14 PM (edited) On 4/4/2025 at 7:01 PM, 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. Expand @GLAVCVS The point creation done OK but Zoom Extents never happened Edited Friday at 07:36 PM by Engineer_Yasser Quote
GLAVCVS Posted Friday at 08:21 PM Posted Friday at 08:21 PM 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 Friday at 08:29 PM Author Posted Friday at 08:29 PM On 4/4/2025 at 8:21 PM, 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'. Expand @GLAVCVS Do you have any example code to test your idea ? Quote
BIGAL Posted Friday at 10:52 PM Posted Friday at 10:52 PM 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 Friday at 10:58 PM Author Posted Friday at 10:58 PM (edited) On 4/4/2025 at 10:52 PM, 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") Expand @BIGAL I have a lisp code and i want to make zoom extents to the created drawing .. can you ? Edited Friday at 11:56 PM by Engineer_Yasser Quote
GLAVCVS Posted Friday at 11:52 PM Posted Friday at 11:52 PM 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 Saturday at 10:09 AM Posted Saturday at 10:09 AM (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 Saturday at 06:36 PM by Steven P 1 Quote
pkenewell Posted Tuesday at 01:12 PM Posted Tuesday at 01:12 PM (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 Tuesday at 01:13 PM by pkenewell 1 Quote
SLW210 Posted Tuesday at 02:28 PM Posted Tuesday at 02:28 PM 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 Tuesday at 03:00 PM Posted Tuesday at 03:00 PM 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 23 hours ago Posted 23 hours ago On 4/8/2025 at 1:12 PM, 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. Expand @pkenewell Does this really work? Have you tried it? Quote
Steven P Posted 22 hours ago Posted 22 hours ago 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 21 hours ago Posted 21 hours ago (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 21 hours ago by GLAVCVS Quote
GLAVCVS Posted 21 hours ago Posted 21 hours ago 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 19 hours ago Posted 19 hours ago 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 18 hours ago Posted 18 hours ago 19 hours 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. Expand 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.