bartonrj25 Posted November 25, 2013 Posted November 25, 2013 I was curious to know if anyone knows of a LISP routine that can create multiple paper space layout tabs and can name them incrementally. Your help is greatly appreciated. Quote
rkmcswain Posted November 25, 2013 Posted November 25, 2013 Here is a start. (no error checking included) (setq i 1) (repeat 10 (vl-cmdf "._layout" "_N" (strcat "MyLayout-" (itoa i))) (setq i (1+ i)) ) Quote
Chilidawg Posted November 25, 2013 Posted November 25, 2013 I would think that it would be more useful to create the layouts from a pre-createded template tab. That way you can set up your borders, labels and do the plot/page setup once instead of 10 times. Quote
bartonrj25 Posted November 25, 2013 Author Posted November 25, 2013 @ Chilidawg That is correct. That is exactly what I am looking for. I have a code that comes close but it creates a new layout instead of copying a template tab that I want repeated and named incrementally. Quote
rkmcswain Posted November 25, 2013 Posted November 25, 2013 Ok, how about this? (setq i 1) (repeat 10 (vl-cmdf "._layout" "_C" "Layout1" (strcat "MyLayout-" (itoa i))) (setq i (1+ i)) ) Quote
Chilidawg Posted November 25, 2013 Posted November 25, 2013 A low tech option is to set up your first tab the way you want it, name it "Name (1)" then simply select that tab right click, and copy it to the end. you will get two tabs, "Name (1)," and "Name (2)." Now here is the trick. Select BOTH tabs, right click, select move or copy, and copy them to the end. You will now have FOUR tabs sequentially numbered. Select all four tabs, repeat, and you will now have EIGHT tabs sequentially numbered. Do this untill you have created how many tabs you want. If you can live with the number in (##), then you are good to go. Sometimes the old fashioned way is faster than trying to create a Lisp. Quote
bartonrj25 Posted November 25, 2013 Author Posted November 25, 2013 I have been doing it that way previously but I have a data field inserted into my template that loads my sheet numbers into my title block per each layout and it would just look a little odd with the () format. I appreciate your help though. Quote
SLW210 Posted November 26, 2013 Posted November 26, 2013 I moved your thread to the AutoLISP, Visual LISP & DCL forum. Quote
cwake Posted December 2, 2013 Posted December 2, 2013 This lacks the coding elegance that I'm trying to achieve lately, but I'm a little pushed for time. (defun c:duplayout ( / increment_string CustSort CustSort_Comparable CustSort_SplitStr oce louts flag ctab layout# layoutname newlayoutname ) (vl-load-com) ;;****************************************************************** ;; Local Functions ;;****************************************************************** (defun increment_string (string inc / num tmp1 len check sign) (if (/= string "");Don't process an empty string (progn (setq num "" tmp1 1 ) (while (and (> (setq len (strlen string)) 0) tmp1) (setq check (substr string len));The last character of the string (if (wcmatch check "[0-9]");Is it a number? (setq num (strcat check num);If yes put it aside string (substr string 1 (1- len));and take it off the original string ) (setq tmp1 nil);If no end the loop );if );while ;check for negative signage in front of the string (if (and (> (strlen string) 0) (= (substr string 1 1) "-")) (progn (setq sign -1) (if (> (strlen string) 1);more than just a negative sign (setq string (vl-string-left-trim " " (substr string 2 (1- (strlen string)))));remove the negative sign and any spaces (setq string "") ) );progn (setq sign 1) ) (setq tmp1 (+ (* (atoi num) sign) inc) sign (if (< tmp1 0) "-" "") tmp1 (itoa (abs tmp1)) ) ;Then pad with zeros if the original was padded (if (< (strlen tmp1) (strlen num)) (repeat (- (strlen num) (strlen tmp1)) (setq tmp1 (strcat "0" tmp1)));Buffer with zeros ) (strcat sign string tmp1) );progn "1" );if ) ;;****************************************************************** ;;Customised string sorting function Main Part (defun CustSort ( x ) (vl-sort x (function (lambda ( x1 x2 / n1 n2 comp ) (setq x1 (CustSort_SplitStr x1);creates a broken down list of alpha & numeric values from the string x2 (CustSort_SplitStr x2);creates a broken down list of alpha & numeric values from the string ) (while (and (setq comp (CustSort_Comparable (setq n1 (car x1)) (setq n2 (car x2)))) (= n1 n2) (/= n1 nil) ) (setq x1 (cdr x1) x2 (cdr x2)) );while (if comp (< n1 n2) (numberp n1)) );lambda );function );vl-sort ) ;********************************************************************* ;;Customised string sorting function Sub Part 1 - Tests whether the values are both strings or both numbers (defun CustSort_Comparable ( e1 e2 ) (or (and (numberp e1) (numberp e2)) (= 'STR (type e1) (type e2)) (not e1) (not e2) ) ) ;********************************************************************* ;;Customised string sorting function Sub Part 2 - Splits a string into a list of separated string and number parts (defun CustSort_SplitStr ( str / lst test rslt num tmp ) (setq lst (vl-string->list str) test (chr (car lst)) ) (if (< 47 (car lst) 58) (setq num T)) (while (setq lst (cdr lst)) (if num (cond ((= 46 (car lst)) (if (and (cadr lst) (setq tmp (strcat "0." (chr (cadr lst)))) (numberp (read tmp))) (setq rslt (cons (read test) rslt) test tmp lst (cdr lst)) (setq rslt (cons (read test) rslt) test "." num nil)) );1st condition ((< 47 (car lst) 58) (setq test (strcat test (chr (car lst)))) );2nd condition (T (setq rslt (cons (read test) rslt) test (chr (car lst)) num nil ) );3rd condition );cond (if (< 47 (car lst) 58) (setq rslt (cons test rslt) test (chr (car lst)) num T) (setq test (strcat test (chr (car lst)))));if );if );while (if num (setq rslt (cons (read test) rslt)) (setq rslt (cons test rslt))) (reverse rslt) ) ;;****************************************************************** ;; Main Program Code ;;****************************************************************** (setq oce (getvar "cmdecho")) (setvar "cmdecho" 0) (setq louts (layoutlist) ctab (if (= "Model" (getvar "ctab")) (car louts) (getvar "ctab")) flag nil ) (while (not flag) (setq layoutname (getstring T (strcat "\nLayout to duplicate <" ctab ">: "))) (if (= layoutname "") (setq layoutname ctab)) (if (= layoutname "Model") (alert "Cannot duplicate Modelspace") (if (member (strcase layoutname) (mapcar 'strcase louts)) (setq flag T)) );if );while (initget 6) (setq layout# (getint "\nHow many copies ? <2>: ")) (if (null layout#) (setq layout# 2)) (setq newlayoutname layoutname louts (mapcar 'strcase louts) ) (repeat layout# (while (member (strcase (setq newlayoutname (increment_string newlayoutname 1))) louts)) (vl-cmdf ".layout" "copy" layoutname newlayoutname) (setq louts (cons (strcase newlayoutname) louts)) );repeat (setq louts (CustSort louts)) (vlax-for tab (vla-get-layouts (vla-get-activedocument (vlax-get-acad-object))) (if (not (= (strcase (vla-get-name tab)) "MODEL")) (vla-put-taborder tab (1+ (vl-position (strcase (vla-get-name tab)) louts))) ) ) (setvar "cmdecho" oce) (princ) );defun 1 Quote
Lee Mac Posted December 2, 2013 Posted December 2, 2013 @cwake, forgive me if I am mistaken, but didn't gile write those 'CustSort_' functions? http://www.theswamp.org/index.php?topic=30262.msg359719#msg359719 It is courteous to acknowledge when you have used code written by other authors, otherwise the code is assumed to be your own. Lee Quote
cwake Posted December 2, 2013 Posted December 2, 2013 (edited) It is courteous to acknowledge when you have used code written by other authors, otherwise the code is assumed to be your own. Lee Hi Lee. I acknowledge that, but in this case, the honest truth is I don't know. I'm not surprised that you have a much better memory of forum activity than I... but I don't recognise that particular post. Nevertheless, I do believe that the sorting code was either copied from or inspired by something I found a few years ago when I wasn't happy with the results of the generic string sort functions, so certainly someone should be acknowledged, it's true. The function now resides in my function library in it's current form, and I cut and paste it as needed. But unfortunately I haven't kept a record of it's history. If I'm to be more active on the forums as you suggested to refine my coding, I'll certainly try to be more diligent in keeping records of material when not my own. But until now I've been more outcome driven then process driven, thus I haven't kept too many records with my library. All I can do is again express my gratitude to you and others like you who have generously shared their knowledge on the forums. It has more than once helped me solve problems that textbooks and help files have not. Edited December 2, 2013 by cwake Quote
Lee Mac Posted December 2, 2013 Posted December 2, 2013 Thank you for your understanding cwake, I do appreciate the honesty in your response and also your gratitude for the contributions of the forum community. Please know that it was not my intention to reprimand you on this issue, but rather offer some friendly advice when posting code to the public domain. Now, back on topic Quote
bartonrj25 Posted December 3, 2013 Author Posted December 3, 2013 Thanks cwake. This worked out perfectly. Quote
Bloodhurt Posted August 10, 2015 Posted August 10, 2015 Hello, I've been using this lips for a while and it's working perfectly. Already found how to change the "jump" of the name's number, but right now I was searching how to make this lisp change the FIRST character of the string, not the last as it is now. i.e: layout name: 4-2, new layout name: 5-2 (not 4-3 as it is now). thanks for help! Quote
Bloodhurt Posted August 11, 2015 Posted August 11, 2015 Hello, I was thinking about that lisp and I think the good idea would be to add the more 2 question/options (together with: which layout dup. and how many copies): 1. What should be the string ? 2. Which character to change? Please help me with solving those problems ASAP (i don't want to manualy change name of over 100 layouts! ) Thanks! Quote
MP7 Posted July 7, 2020 Posted July 7, 2020 Hey guys, I've tried and this is an awesome routine, but is there one that would move every created layout for a given distance in the model? For example the first duplicated layout is moved from the original for 2000 units(a prompt for distance would be nice), the second duped layout for 4000 from the original or in other words 2000 from the last one and so on... Sorry for bumping but I think it's related :) Quote
maratovich Posted July 7, 2020 Posted July 7, 2020 4 hours ago, MP7 said: Hey guys, I've tried and this is an awesome routine, but is there one that would move every created layout for a given distance in the model? For example the first duplicated layout is moved from the original for 2000 units(a prompt for distance would be nice), the second duped layout for 4000 from the original or in other words 2000 from the last one and so on... Sorry for bumping but I think it's related Do you have rectangles in the model and want to get viewports for these rectangles? So ? Quote
MP7 Posted July 7, 2020 Posted July 7, 2020 Yes! I mean it's not a big deal you enter each viewport and zoom to that rectangle but still, if you have a huge number of them.... Quote
maratovich Posted July 7, 2020 Posted July 7, 2020 2 minutes ago, MP7 said: Yes! I mean it's not a big deal you enter each viewport and zoom to that rectangle but still, if you have a huge number of them.... Use this : AutoViewport 1 Quote
MP7 Posted July 7, 2020 Posted July 7, 2020 WOW, holy crap thx a lot I'll take a look into it, price is great as well 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.