Jump to content
homasa

Help: Auto Number Layouts By its sequence and prefix it if < 10

Recommended Posts

homasa

Hello Again

 

I found this script that i wanna change because it does not work well when layouts are not "Layout 1", "Layout 2" , etc

even for example if i already have the layouts numbered but have to create another one or simply re-arrange them

 

(alert "Use at command line to execute program:\n\n numlay")
(defun c:numlay (/ i) (vl-load-com)
 (setq i 0)
 (foreach x (layoutlist)
   (vla-put-name
     (vla-item	(vla-get-layouts
	  (vla-get-activedocument (vlax-get-acad-object))
	)
	x
     )
              (strcat (itoa (setq i (1+ i))))
     )
 )
 (princ)
)

 

I wanna it to :

1) Auto-number Layout using the sequence in which they really are

2) That autonumbering prefix an 0 before the number if it is

 

this last topic i tryied using this code without sucess ....

(cond
       	((and (> i 0) (< i 10))
        	(strcat "0" (itoa i))
       )

 

thx in advanced

Share this post


Link to post
Share on other sites
homasa

at least anyone can tell me what am i doing wrong here:

 

(alert "Use at command line to execute program:\n\n cat")
(defun c:cat (/ i) (vl-load-com)
 (setq i 0)
 (foreach x (layoutlist)
   (vla-put-name
     (vla-item	(vla-get-layouts
	  (vla-get-activedocument (vlax-get-acad-object))
	)
	x
     )

(strcat (itoa (setq i (1+ i))))

(if (< (atoi i) 10)
(setq i (strcat "0" i))
)
   )
 )
 (princ)
)

Edited by homasa
; error: bad argument type: stringp 1

Share this post


Link to post
Share on other sites
BIGAL

I think I have exactly what you want, credits to Lee mac & AlanJT

 

It changes a number of attributes on the title block one being the layout name as a sheet number including those less than 10

 

; change the 410 to layout name
;;-------------------=={ Parse Numbers }==--------------------;;
;;                                                            ;;
;;  Parses a list of numerical values from a supplied string. ;;
;;------------------------------------------------------------;;
;;  Author: Lee Mac, Copyright © 2011 - [url="http://www.lee-mac.com"]www.lee-mac.com[/url]       ;;
;;------------------------------------------------------------;;
;;  Arguments:                                                ;;
;;  s - String to process                                     ;;
;;------------------------------------------------------------;;
;;  Returns:  List of numerical values found in string.       ;;
;;------------------------------------------------------------;;
(defun LM:ParseNumbers ( s )
 (
   (lambda ( l )
     (read
       (strcat "("
         (vl-list->string
           (mapcar
             (function
               (lambda ( a b c )
                 (if
                   (or
                     (< 47 b 58)
                     (and (= 45 b) (< 47 c 58) (not (< 47 a 58)))
                     (and (= 46 b) (< 47 a 58) (< 47 c 58))
                   )
                   b 32
                 )
               )
             )
             (cons nil l) l (append (cdr l) (list nil))
           )
         )
         ")"
       )
     )
   )
   (vl-string->list s)
 )
)
;(defun ah:sheetupdate1 (ss1 lay plotabs tabname dwgname)
(defun ah:sheetupdate1 ()
(setq doc (vla-get-activedocument (vlax-get-acad-object)))
(vlax-for lay (vla-get-Layouts doc)
 (setq plotabs (cons (vla-get-name lay) plotabs))
)
(setq title "Please enter dwg number")
(setq width "   edit_width = 12;")
(setq limit "     edit_limit = 9;")
(ah:getval title width limit)
(setq dwgname item)
(setq title "Please enter version for all sheets <Cr> no change")
(setq width "   edit_width = 8;")
(setq limit "     edit_limit = 5;")
(ah:getval title width limit)  
(setq newstr4 item)
(princ "0")
(setq len (length plotabs))
(setq x 0)
(setq bname "DA1DRTXT") ; block name is bname
(repeat len
 (setq tabname (nth x plotabs))
 (if (/= tabname "Model")
   (progn
     (setvar "ctab" tabname)
     (setq ss1 (ssget "x"  (list (cons 0 "INSERT") (cons 2 bname)(cons 410 tabname))))
     (setq dwgnum (Lm:parsenumbers tabname))
     (setq sheetnum (car dwgnum))
     (setq oldtag1 "SHT_NO") ; attribute1 tag name
     (setq newstr1 (rtos sheetnum 2 0))
     (setq oldtag2 "DRG_NO") ;attribute2 tag name
     (setq oldtag3 "PROJ_NO") ;attribute3 tag name
     (setq newstr3 dwgname)
     (setq oldtag4 "REV_NO") ;attribute4 tag name
; if less than 10
(if (< (car dwgnum) 10.0) 
     (setq newstr2 (strcat dwgname "-D0"  (rtos sheetnum 2 0)))
     (setq newstr2 (strcat dwgname "-D"  (rtos sheetnum 2 0)))
)
     (foreach att (vlax-invoke (vlax-ename->vla-object (ssname SS1 0 )) 'getattributes)
       (if (= oldtag1 (strcase (vla-get-tagstring att)))
       (vla-put-textstring att newstr1) 
       ) ; end if
       (if (= oldtag2 (strcase (vla-get-tagstring att)))
       (vla-put-textstring att newstr2) 
       ) ; end if
       (if (= oldtag3 (strcase (vla-get-tagstring att)))
       (vla-put-textstring att newstr3) 
       ) ; end if
       (if (and (/= version nil) (= oldtag4 (strcase (vla-get-tagstring att))) )
       (vla-put-textstring att newstr4) 
       ) ; end if 
      ) ; end foreach
   ) ; end progn
) ; end if
(setq x (+ x 1))
) ; end repeat
(setq ss1 nil)  
) ; end defun ah

(ah:sheetupdate1)
(princ)

Getval.lsp load it first before lisp above

;; Input  Dialog box with variable title
;; By Ah June 2012
;; code (ah:getval title)
;; Credits to AlanJT for original idea
(defun AH:Getval (title width limit / fo)
(setq fname "C://acadtemp//getval.dcl")
(setq fo (open fname "w"))
(write-line "ddgetval : dialog {" fo)
(write-line " : row {" fo)
(write-line ": edit_box {" fo)
(write-line (strcat "    key = "  (chr 34) "sizze" (chr 34) ";") fo)
(write-line  (strcat " label = "  (chr 34) title (chr 34) ";"  )   fo)
; these can be replaced with shorter value etc
;(write-line "     edit_width = 18;" fo) 
;(write-line "     edit_limit = 15;" fo)
(write-line width fo) 
(write-line limit fo)
(write-line "   is_enabled = true;" fo)        
(write-line "    }" fo)
(write-line "  }" fo)
(write-line "ok_cancel;}" fo)
(close fo)
(setq dcl_id (load_dialog  "c:\\acadtemp\\getval"))
(if (not (new_dialog "ddgetval" dcl_id))
(exit))
(action_tile "sizze" "(setq item  $value)(done_dialog)")
(mode_tile "sizze" 3)
(start_dialog)
; returns the value of item
)

Share this post


Link to post
Share on other sites
homasa

Hey Bigal thx for the answer

 

well i try to run it in the order like you said and it gives me an ; error: bad argument type: streamp nil

 

Just a note: i do not have a title block so i only need to number / re-number layouts in the order they are when i run the lisp.

my lisp above do it but i do not know why it doesn't respect order unless they are labeled "Layout 1", "Layout 2", etc...

 

regards :)

Share this post


Link to post
Share on other sites
irneb

You mean something like this?

(defun vlax-collection->list (col / lst)
 (vlax-for item col (setq lst (cons item lst)))
 (reverse lst))

(defun c:LayoutRenum  (/ layouts n name digits)
 (vl-load-com)
 (setq n       0
       digits  2
       layouts (vl-remove-if
                 '(lambda (lay) (= (vla-get-ModelType lay) :vlax-true))
                 (vlax-collection->list (vla-get-Layouts (vla-get-ActiveDocument (vlax-get-acad-object))))))
 (foreach lay layouts (vla-put-Name lay (vla-get-Handle lay)))
 (foreach lay  (vl-sort layouts '(lambda (a b) (apply '< (mapcar 'vla-get-Taborder (list a b)))))
   (setq name (itoa (setq n (1+ n))))
   (repeat (- digits (strlen name)) (setq name (strcat "0" name)))
   (vla-put-Name lay name))
 (princ))

 

Edit: You need to sort the list because both vla-get-Layouts and layoutlist gets in creation order. If you rearranged the tabs after you created them, the taborder property is the only one which allows you to get to their "displayed order".

Share this post


Link to post
Share on other sites
homasa

Hello irneb

 

thx for your answer, and yes that's exactly what i was looking for.

TTTHHHHHXXXXXX so MMMMMUUUUCCCHHH both.

 

By the way irneb can you please explain me why the other one didnt respected layout order ??? (i am starting at lisp)

 

best regards to both

 

You mean something like this?
(defun vlax-collection->list (col / lst)
 (vlax-for item col (setq lst (cons item lst)))
 (reverse lst))

(defun c:LayoutRenum  (/ layouts n name digits)
 (vl-load-com)
 (setq n       0
       digits  2
       layouts (vl-remove-if
                 '(lambda (lay) (= (vla-get-ModelType lay) :vlax-true))
                 (vlax-collection->list (vla-get-Layouts (vla-get-ActiveDocument (vlax-get-acad-object))))))
 (foreach lay layouts (vla-put-Name lay (vla-get-Handle lay)))
 (foreach lay  (vl-sort layouts '(lambda (a b) (apply '< (mapcar 'vla-get-Taborder (list a b)))))
   (setq name (itoa (setq n (1+ n))))
   (repeat (- digits (strlen name)) (setq name (strcat "0" name)))
   (vla-put-Name lay name))
 (princ))

 

Edit: You need to sort the list because both vla-get-Layouts and layoutlist gets in creation order. If you rearranged the tabs after you created them, the taborder property is the only one which allows you to get to their "displayed order".

Share this post


Link to post
Share on other sites
homasa

oh oh didn't saw

"Edit: You need to sort the list because both vla-get-Layouts and layoutlist gets in creation order. If you rearranged the tabs after you created them, the taborder property is the only one which allows you to get to their "displayed order"."

 

well thats the answer ;)

 

Thx again very much for your help

 

king regards

Share this post


Link to post
Share on other sites
irneb

And actually seeing as you always number from 1, you need not do the sorting idea either. Just use the TabOrder number as the new name:

(defun c:LayoutRenum (/ layouts digits name)
 (vl-load-com)
 (setq digits 2
       layouts (vl-remove-if '(lambda (lay) (= (vla-get-ModelType lay) :vlax-true))
                 (vlax-collection->list (vla-get-Layouts (vla-get-ActiveDocument (vlax-get-acad-object))))))
 (vlax-for lay layouts (vla-put-Name lay (vla-get-Handle lay)))
 (vlax-for lay layouts
   (setq name (itoa (vla-get-TabOrder lay)))
   (repeat (- digits (strlen name)) (setq name (strcat "0" name)))
   (vla-put-Name lay name)))

Notice also that I first name the tab to its Handle string, and then to its new number. This is to try an prevent a situation where a duplicate name happens - which would cause the routine to error and not rename correctly.

Share this post


Link to post
Share on other sites
homasa

always learning :)

Share this post


Link to post
Share on other sites
Lee Mac
(defun c:LayoutRenum (/ layouts digits name)
 (vl-load-com)
 (setq digits 2
       layouts (vl-remove-if '(lambda (lay) (= (vla-get-ModelType lay) :vlax-true))
                 (vlax-collection->list (vla-get-Layouts (vla-get-ActiveDocument (vlax-get-acad-object))))))
 (vlax-for lay layouts (vla-put-Name lay (vla-get-Handle lay)))
 (vlax-for lay layouts
   (setq name (itoa (vla-get-TabOrder lay)))
   (repeat (- digits (strlen name)) (setq name (strcat "0" name)))
   (vla-put-Name lay name)))

 

That looks like it will error as 'layouts' is a list, not a collection (I'm sure you knew this already). But I think the 'vlax-collection->list' and 'vl-remove-if' expressions are unnecessary loops:

 

(defun c:layoutrenum ( / l n )
   (vlax-for x (vla-get-layouts (vla-get-activedocument (vlax-get-acad-object)))
       (if (= :vlax-false (vla-get-modeltype x))
           (progn
               (vla-put-name x (vla-get-handle x))
               (setq l (cons x l))
           )
       )
   )
   (foreach x l
       (setq n (itoa (vla-get-taborder x)))
       (repeat (- 2 (strlen n)) (setq n (strcat "0" n)))
       (vla-put-name x n)
   )
   (princ)
)
(vl-load-com) (princ)

 

Notice also that I first name the tab to its Handle string, and then to its new number. This is to try an prevent a situation where a duplicate name happens - which would cause the routine to error and not rename correctly.

 

Good idea Irné :thumbsup:

Share this post


Link to post
Share on other sites
irneb

You're absolutely correct! That second one of mine is neither here nor there! The first portion (vl-remove...) is definitely not to be in that function! Yours does exactly what I was thinking of! :thumbsup:

Share this post


Link to post
Share on other sites
BIGAL

Thanks irneb & Lee we often have lots of layouts and when you shuffle them they get out of layout name order I will look at using the code to auto number etc as different people call their layouts different names and would like consistent name as well as order. Like you say always learning.

Share this post


Link to post
Share on other sites
Lee Mac

Thanks BigAl, glad you could make use of it :)

Share this post


Link to post
Share on other sites
Designer

Is there a way to leave the text of the layout after the numbering?

Share this post


Link to post
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...