ravi08ravi Posted November 2, 2021 Posted November 2, 2021 hi all i have given a task to make 500 layouts . i gave each layout tab a number " say 1 to 500 " and the same layout tab number is written in the center of the rectangle in mspace , which is to align in that tab, "say eg 450 tab should show rec with '450' text location " . can some one make a scr/lisp so that ,if i just go to that layout tab and type the tab number then 1)it should automatically go in mspace find the text 2)align the rectangle around that text to the layout . i reached the half way, but got stuck when align /zoom/select command asks to select the corner point of rectangle . bcs that is only possible with mouse . or iff some one can make some thing that can select corner without mouse, only then scr/lisp can be Completed. Quote
dan20047 Posted November 3, 2021 Posted November 3, 2021 (edited) Are you trying to align each tab view with the respective rectangle in mspace? I would use excel or google sheets to create a script file using incremented coordinates with the zoom command. Here is an example history from command line: : CTAB New current value for CTAB <"Layout1">: 1 : MS : z Zoom: In/Out/All/Center/Dynamic/Extents/Left/Previous/Right/Scale/Window/<Scale (nX/nXP)>: l Lower left corner: 0,0 Enter zoom factor (nX/nXP), or view height <838'-6 171/256">: 1/1xp : ps : CTAB New current value for CTAB <"1">: 2 this turns into a script line something like this, assuming horizontal spacing of 50 and 1:1 scale factor. (I didn't test, you should do you own manual commands and record what you type. ctab 1 ms z l 0,0 1/1xp ps ctab 2 ms z l 50,0 1/1xp ps ctab 3 ms z l 100,0 1/1xp ps I copy past the spreadsheet into a text file, use find & replace to convert tabs to spaces and run the script. Test just a couple lines are first until you get the bugs worked out. Here is a link to an example spreadsheet, modify the master row values https://docs.google.com/spreadsheets/d/11c6L8t4QEAHq0Amzuwi7nk2mn2ctSfKl0OdKwn_821Q/edit?usp=sharing Edited November 3, 2021 by dan20047 Quote
ravi08ravi Posted November 3, 2021 Author Posted November 3, 2021 2 hours ago, dan20047 said: Are you trying to align each tab view with the respective rectangle in mspace? I would use excel or google sheets to create a script file using incremented coordinates with the zoom command. Here is an example history from command line: : CTAB New current value for CTAB <"Layout1">: 1 : MS : z Zoom: In/Out/All/Center/Dynamic/Extents/Left/Previous/Right/Scale/Window/<Scale (nX/nXP)>: l Lower left corner: 0,0 Enter zoom factor (nX/nXP), or view height <838'-6 171/256">: 1/1xp : ps : CTAB New current value for CTAB <"1">: 2 this turns into a script line something like this, assuming horizontal spacing of 50 and 1:1 scale factor. (I didn't test, you should do you own manual commands and record what you type. ctab 1 ms z l 0,0 1/1xp ps ctab 2 ms z l 50,0 1/1xp ps ctab 3 ms z l 100,0 1/1xp ps I copy past the spreadsheet into a text file, use find & replace to convert tabs to spaces and run the script. Test just a couple lines are first until you get the bugs worked out. Here is a link to an example spreadsheet, modify the master row values https://docs.google.com/spreadsheets/d/11c6L8t4QEAHq0Amzuwi7nk2mn2ctSfKl0OdKwn_821Q/edit?usp=sharing Thanks for replying Dan.. but do we have something that snaps corner without mouse 🖱.? Quote
dan20047 Posted November 3, 2021 Posted November 3, 2021 my solution is different than what you ask, as I don't have an easy answer to your exact request, and instead tried to guess at your bigger picture goal with tools I've used before. Given your task I would create a script to make all the viewports and align the view based on a system of coordinates for the rectangles in model space Options for aligning viewports: Zoom left zoom > L (for left) > type coordinates > enter scale factor example 1/48xp the left option is undocumented since release 14 (try it!) Save view based on coordinates, then restore it in the viewport -view > window > type view name say "1" or "2" > enter coordinates in paperspace viewport -view > restore > "1" your exact request requires the following pseudo code: ask for number find text containing that number process text, find nearest rectangle surrounding it (this is the hard part) get coordinates of rectangle set view to coordinates Quote
dan20047 Posted November 3, 2021 Posted November 3, 2021 you'll also get more responses by posting in https://www.cadtutor.net/forum/forum/15-autolisp-visual-lisp-amp-dcl/ Quote
ravi08ravi Posted November 3, 2021 Author Posted November 3, 2021 I found another way to solve this, i used zoom2text lisp . it will find the text string in dwg and zoom to it then zoom command , but now a new issue . con someone help so that i dont have to type the tab number twice.....if i just type Ctab number once and zoom2txt takes ctab valve automatically. CTABzoomtotxt.lsp New current value for CTAB <"454">: 455 : MS : ZOOM2TXT Enter text string to zoom to: 455 Search for embedded strings? <Y or N>: n : _zoom Zoom [zoom In/zoom Out/All/Center/Dynamic/Extents/Left/Previous/Right/Scale (nx/nxp)/Window/OBject] <Scale (nX/nXP)>:w First corner: Opposite corner: Edit Text, text Properties or Neither? <T P N>: Cancel ; error : Function cancelled : z Zoom [zoom In/zoom Out/All/Center/Dynamic/Extents/Left/Previous/Right/Scale (nx/nxp)/Window/OBject] <Scale (nX/nXP)>:c Center of view <689003.287,561002.817,0.000> Enter zoom factor (nX/nXP), or view height <2.000>: 48 : -VPORTS Viewports: Set first corner or [ON/OFf/Lock/Fit/create 2 viewports/create 3 viewports/create 4 viewports/Object/Polygonal]:l Viewport locking [ON/OFf] <ON>: Select viewports [selection options (?)]:? Select entities [select ALL entities/Add/add to set (+)/Remove/subtract from set (-)/Previous selection/Last entity in drawing/inside Window/Crossing window/Outside window/Window Polygon/Crossing Polygon/Outside Polygon/Window Circle/Crossing Circle/Outside Circle/Box/POint/Fence/AUto/Multiple/Single/select by PROperties.../selection methoDs.../Undo/Group]: b First corner of selection box: 0,0 Opposite Corner: 402,248 Entities in set: 2 Select viewports [selection options (?)]: : PS : z Zoom [zoom In/zoom Out/All/Center/Dynamic/Extents/Left/Previous/Right/Scale (nx/nxp)/Window/OBject] <Scale (nX/nXP)>:e : Quote
dan20047 Posted November 3, 2021 Posted November 3, 2021 try adding these two lines noted below (if (= embed "Y") (setq txt (strcat "*" txt "*")) ) ;; new code (setvar "ctab" txt) (command "mspace") ;; end new code (setq zoompt1 (getvar "extmin")) (setq zoompt2 (getvar "extmax")) ps, please don't highlight the code, I use darkmode and can't read it easily Quote
BIGAL Posted November 4, 2021 Posted November 4, 2021 Why not just ssget text, make a new layout with that name, do mview, mspace, zoom c textinspt scale, pspace, lock viewport. Do next, ie dont make layouts 1st. This has advantage that when "layout new" can copy a master layout that has a title block. I take it that the text has been created in sequence so the ssget will get 1-500 in order. (defun c:wow ( / ss x val ins txt obj) (setq ss (ssget "x" '((0 . "TEXT")(410 . "Model")))) (setq x -1) (repeat (sslength ss) (setq txt (entget (ssname ss (setq x (1+ x))))) (setq val (cdr (assoc 1 txt))) (setq ins (cdr (assoc 10 txt))) (command "layout" "C" "D01" val) (setvar 'ctab val) ; If no mview here then do now (command "mspace" "zoom" "C" ins 100) (command "zoom" "4xp") (command "pspace") (setq vp (ssget "x" (list (cons 0 "VIEWPORT")(cons 410 val)))) (setq obj (vlax-ename->vla-object (ssname vp 0))) (vla-put-DisplayLocked obj 1) ) (princ) ) Quote
ravi08ravi Posted November 5, 2021 Author Posted November 5, 2021 On 04/11/2021 at 00:23, BIGAL said: Why not just ssget text, make a new layout with that name, do mview, mspace, zoom c textinspt scale, pspace, lock viewport. Do next, ie dont make layouts 1st. This has advantage that when "layout new" can copy a master layout that has a title block. I take it that the text has been created in sequence so the ssget will get 1-500 in order. (defun c:wow ( / ss x val ins txt obj) (setq ss (ssget "x" '((0 . "TEXT")(410 . "Model")))) (setq x -1) (repeat (sslength ss) (setq txt (entget (ssname ss (setq x (1+ x))))) (setq val (cdr (assoc 1 txt))) (setq ins (cdr (assoc 10 txt))) (command "layout" "C" "D01" val) (setvar 'ctab val) ; If no mview here then do now (command "mspace" "zoom" "C" ins 100) (command "zoom" "4xp") (command "pspace") (setq vp (ssget "x" (list (cons 0 "VIEWPORT")(cons 410 val)))) (setq obj (vlax-ename->vla-object (ssname vp 0))) (vla-put-DisplayLocked obj 1) ) (princ) ) sorry frnds i dont know making lisp yet , i am new.... i just know how to load lisp and make script. for me this "wow" lisp is not working. i copied the wow lisp and made a lsp file ,loaded it ,but not loading successfully. Quote
dan20047 Posted November 5, 2021 Posted November 5, 2021 FYI scripts are different than lisps and are easier to start learning. They basically replay your typing. More info: https://www.cad-notes.com/learn-how-to-write-command-scripts-for-autocad-and-automate-your-plotting/ If you are having problem with a lisp or script running, share the command line history so that we can see what is going wrong. Quote
BIGAL Posted November 6, 2021 Posted November 6, 2021 I copied the wow lisp and made a lsp file ,loaded it ,but not loading successfully. If you look at the code it expects at least 1 layout to exist and that layout has your title block and a mview set up. (command "layout" "C" "D01" val) so replace "D01" with the name of your layout. eg "Layout1" 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.