tmelancon Posted June 27, 2017 Posted June 27, 2017 I wrote a little routine from scratch and it works perfectly fine. I just thought I would share it and possibly see if someone would have wrote it differently or more efficiently, and how? I am 100% completely self taught and am continuously learning on a daily basis (I still have a ways to go). I take a lot of good pointers from the forums but never actually formally learn, so if you wish to oblige, could you possible explain yourself a little. I am always willing to learn new things. Basically we draw pages and pages of piping and vessels daily. When we are finished we have to then create page labels (i.e. DWG 1 OF 5, DWG 2 OF 5, etc..) Sometimes we have in the upwards of 25 pages so you can see how copying, pasting, editing, and modifying can be monotonous. I am aware of Lee Macs - NumInc utility. The reason why we dont use that is because we have it preset to a certain prefix and suffix because we are always renumbering datapoints. I guess I could have just made a copy and created a separate command. However, I wrote a small basic routine and my crew loves it. It is straight forward and to the point. (DEFUN C:DWG() (SETQ COUNT (GETSTRING "\nHow many drawings do you have? ")) (SETQ COUNTUP 1) (setq oldlayr (getvar "clayer")) (setq t_size 0.08) (REPEAT (ATOI COUNT) (SETQ DWGOF (STRCAT "DWG " (TRIM (ITOA COUNTUP)) " OF " (TRIM COUNT))) (setq point (getpoint "\nPick Text Placement: ")) (command "layer" "s" "text" "") (command "._text" "L" point t_size "0" DWGOF) (COMMAND "MOVE" "L" "" "0,0" "0,.05") (SETQ COUNTUP (1+ COUNTUP)) ) (SETVAR "CLAYER" OLDLAYR) (PRINC)) Quote
Grrr Posted June 27, 2017 Posted June 27, 2017 if someone would have wrote it differently or more efficiently, and how? This may be worth investigating (a quick glance correction) : (defun C:DWG ([color=red] / count countup oldlayr t_size dwgof point[/color] ) ; [b] <<- ALWAYS LOCALISE YOUR VARIABLES UNLESS YOU KNOW WHAT YOU'RE DOING! [/b] [color=red](and[/color] [color=red](progn (initget (+ 2 4))[/color] (setq count ([color=red]getint[/color] "\nHow many drawings do you have? <exit> ")) [color=red])[/color] [color=red](if (not trim) (prompt "The \"trim\" subfunction is not defined.") T)[/color] (setq countup 1) (setq oldlayr (getvar "clayer")) (setq t_size 0.08) [color=red](progn[/color] (repeat [color=red]count[/color] (setq dwgof (strcat "DWG " (trim (itoa countup)) " OF " (trim [color=red](itoa[/color] count[color=red])[/color]))) [color=red](cond [/color] ( (setq point (getpoint "\nPick Text Placement <next>: ")) (command "[color=red]._-[/color]layer" "s" "text" "") (command "[color=red]._-[/color]text" "L" point t_size "0" DWGOF) (command "[color=red]._-[/color]MOVE" "L" "" "0,0" "0,.05") (setq countup (1+ countup)) ) [color=red]); cond [/color] ) (setvar "clayer" oldlayr) [color=red]); progn[/color] [color=red]); and[/color] (princ) ) Feel free to ask, I guess the other guys will help you if I don't have time to answer. Quote
tmelancon Posted June 27, 2017 Author Posted June 27, 2017 Grrr, thank you so much for your post. Im glad you noticed the localization of variables missing. I immediately recognized that after i posted here and made the update. I will definitely update the rest tomorrow morning and go from there. Thanks very very much for your time and knowledge. Quote
BIGAL Posted June 28, 2017 Posted June 28, 2017 Are you using layouts ? If so then you could auto label very easy, I would use a block as you can do more easily attribute updates. 1st step is how many layouts so this is x of total done by counting the layouts a simple function (ps -1 for model) then go to each layout and we use say D01 d02 layout1 layout2 etc you can read that layout number and put that into the block. layout12 = 12 of 25. If its all in model again count up the block and then update, I would insert the block go away and count, as well as finding highest number so block has up to date info as its added, as mentioned previously Lee's great auto number routine comes into play. Please confirm which scenario. Have some code that would be easy to adapt. Quote
ronjonp Posted June 28, 2017 Posted June 28, 2017 If this is for sheet numbers ( paperspace ), I'd use a field with %% in an attributed block. Forgive me if I'm way off Quote
Lee Mac Posted June 28, 2017 Posted June 28, 2017 If this is for sheet numbers ( paperspace ), I'd use a field with %% in an attributed block. Forgive me if I'm way off Or perhaps something along these lines. Quote
ronjonp Posted June 28, 2017 Posted June 28, 2017 Or perhaps something along these lines. The whole enchilada Quote
tmelancon Posted June 28, 2017 Author Posted June 28, 2017 Yes. Wow. Of course. I'm full now. Thanks for dinner Lee. Quote
tmelancon Posted June 28, 2017 Author Posted June 28, 2017 BIGALL, sorry I am just responding. I type up a response earlier but apparently it didn't submit. We are using layouts (Drawing1, Drawing2, etc..). The "DWG 1 OF ?" is plain text in model space right above our titleblocks. Thanks to everyone for the input! Forever grateful! Quote
ronjonp Posted June 28, 2017 Posted June 28, 2017 Here's a quick one to place text "SHEET X OF X" on each paperspace tab @ 0,0,0 .. enjoy (defun c:foo (/ _maketext r o n s ll) ;; Creates text "SHEET X OF X" on each paper space tab at 0,0,0 ;; RJP - 06.28.2017 (defun _maketext (space point string height width rotation layer) (if point (entmakex (list '(0 . "TEXT") '(100 . "AcDbEntity") (cons 8 layer) (cons 410 space) '(100 . "AcDbText") (cons 10 (trans point 1 0)) (cons 40 height) (cons 1 string) (cons 50 rotation) (cons 41 width) '(72 . 1) (cons 11 (trans point 1 0)) '(73 . 2) ) ) ) ) (and (setq r (cdr (assoc -1 (dictsearch (namedobjdict) "acad_layout")))) (setq o (itoa (length (setq ll (layoutlist))))) (foreach l ll (setq n (itoa (cdr (assoc 71 (dictsearch r l))))) (if (setq s (ssget "x" (list '(0 . "text") '(8 . "Sheet_Numbers") (cons 410 l)))) (entmod (subst (cons 1 (strcat "SHEET " n " OF " o)) (assoc 1 (entget (ssname s 0))) (entget (ssname s 0)) ) ) (_maketext l '(0 0 0) (strcat "SHEET " n " OF " o) 0.125 1 0.0 "Sheet_Numbers") ) ) ) (princ) ) Quote
tmelancon Posted June 29, 2017 Author Posted June 29, 2017 Lee, I am going to try and modify your code just a little bit (while keeping all of your original author notes and copyrights) so that It prompts the user to actually place the text, rather than select. The majority of the time we are drawing from scratch and having to enter these "DWG 1 OF 10" manually. That is why i designed my code to work the way it does; allowing the user to specify where they want to place the "DWG 1 OF 10", then proceeding to process the code to enter it. If you beat me to it, I would be happy to give it a try! Thanks for everything! God bless everyone! Keep up the great work! Quote
ronjonp Posted June 29, 2017 Posted June 29, 2017 Lee, I am going to try and modify your code just a little bit (while keeping all of your original author notes and copyrights) so that It prompts the user to actually place the text, rather than select. The majority of the time we are drawing from scratch and having to enter these "DWG 1 OF 10" manually. That is why i designed my code to work the way it does; allowing the user to specify where they want to place the "DWG 1 OF 10", then proceeding to process the code to enter it. If you beat me to it, I would be happy to give it a try! Thanks for everything! God bless everyone! Keep up the great work! If you feed my code above a point it will do all your tabs at once Quote
tmelancon Posted June 29, 2017 Author Posted June 29, 2017 Ron Sweet code, but my basic code does what I need. However, your code could eliminate the user having to even enter "Number of Sheets". But have a look at my code, its a little different that yours. You have yours putting the string at 0,0 in each layout. My code is always in model space and prompts the user to specify number of sheets then prompts user to place text (this is not automated because sometimes our titleblocks are on the left, and other times they are on the right). (DEFUN C:DWG(/ *error* count countup oldlayr t_size point dwgof) (setvar "cmdecho" 0) (defun *error* (msg) (if oldlayr (setvar "clayer" oldlayr) ) ) (SETQ COUNT (GETSTRING "\nHow many drawings do you have? ")) (SETQ COUNTUP 1) (setq oldlayr (getvar "clayer")) (setq t_size 0.08) (REPEAT (ATOI COUNT) (SETQ DWGOF (STRCAT "DWG " (TRIM (ITOA COUNTUP)) " OF " (TRIM COUNT))) (setq point (getpoint "\nPick Text Placement: ")) (command "layer" "s" "text" "") (command "._text" "L" point t_size "0" DWGOF) (COMMAND "MOVE" "L" "" "0,0" "0,.05") (SETQ COUNTUP (1+ COUNTUP)) ) (SETVAR "CLAYER" OLDLAYR) (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.