AUTO NUMBER LISP BASED ON LAYOUT TAB POSITION

AUTO NUMBER LISP BASED ON LAYOUT TAB POSITION

Anonymous
Not applicable
12,313 Views
18 Replies
Message 1 of 19

AUTO NUMBER LISP BASED ON LAYOUT TAB POSITION

Anonymous
Not applicable

Hi,

 

I would like to have a page number based on the layout tab order. I am currently using the CTAB field for labeling my page titles, but i would also like something to help number my sheets "page X of XX" is there a way of doing this with a lisp file? 

 

I would like it so if I changed the order of my tabs the numbers would automatically update.

 

Thanks

 

0 Likes
Accepted solutions (1)
12,314 Views
18 Replies
Replies (18)
Message 2 of 19

Patchy
Mentor
Mentor

First part do this:

http://forums.augi.com/showthread.php?141491-Auto-Numbering-Layout-Tabs

 

Your 2nd question,

 

Ask the Customization Group

 

0 Likes
Message 3 of 19

Anonymous
Not applicable
That is not really what I am looking for. I would like to keep my tab names the same as what my sheet titles are using the 'ctab' field. What I want to do is have a field that would be based off the order in which the tabs are positioned to automatically number my sheets. (ex. the sheet on the first layout would be sheet 1, layout 2 would be sheet 2. If the layouts are repositioned the field would update automaticlly). I there a way to create a field that would do this? Is there a way to create a new style of field period?
0 Likes
Message 4 of 19

Ranjit_Singh
Advisor
Advisor

I don't think there are fields to check the order of the layout tab. But I am not sure. I would certainly like to know if there is such a field. Using LISP though, once you get the layouts collection object the taborder property tells you the order of the tab. You would need some kind of reactor to check when the tabs were moved and call a lisp to update the relevant entities to reflect taboder property.

 

Are the text/mtext entities to be updated in a title block of some sort? Post a sample dwg.

0 Likes
Message 5 of 19

Anonymous
Not applicable

See attached sample. Just using a simple title block that was given to me.

 

I don't know what you mean by "once you get the layouts collection object the taborder property tells you the order of the tab"

 

Thanks

0 Likes
Message 6 of 19

Ranjit_Singh
Advisor
Advisor
Accepted solution

Try the below routine.

 

Spoiler
(defun c:somefunc  (/ adoc layouts layoutname ss1 ent entdata)
 (setq layouts (vla-get-layouts (setq adoc (vla-get-activedocument (vlax-get-acad-object)))))
 (if (setq ss1 (ssget "_x" '((0 . "INSERT") (2 . "_11x17"))))
  (mapcar
   '(lambda (x)
     (setq ent     (cadr x)
           entdata (entget ent))
     (while (/= (cdr (assoc 0 entdata)) "SEQEND")
      (cond ((= "SHT#" (cdr (assoc 2 entdata)))
             (vlax-for y  layouts
              (cond ((=
                     (vla-get-name (vla-objectidtoobject adoc (vla-get-ownerID (vlax-ename->vla-object (cdr (assoc 330 entdata))))))
                     (vla-get-name (vla-get-block y)))
                    (entmod (subst (cons 1 (itoa (vla-get-taborder y))) (assoc 1 entdata) entdata)))
                    (T ())))
              ))
            (setq entdata (entget (setq ent (entnext ent))))))
     (ssnamex ss1))
  "No titleblocks found!")
 (princ))

 

 

 

Message 7 of 19

Anonymous
Not applicable
You are amazing. Thank you!
0 Likes
Message 8 of 19

Anonymous
Not applicable

I've seen you get it but, which attribute do you use put the number in your pages before using lisp?

I don't know if you understand me. I am sorry about my poor english.

 

Thank you so much in advance!

I looking forward you reply!


@Anonymous wrote:
You are amazing. Thank you!

@Anonymous wrote:
You are amazing. Thank you!

 

0 Likes
Message 9 of 19

Anonymous
Not applicable

@Ranjit_Singh wrote:

Try the below routine.

 

(defun c:somefunc  (/ adoc layouts layoutname ss1 ent entdata)
 (setq layouts (vla-get-layouts (setq adoc (vla-get-activedocument (vlax-get-acad-object)))))
 (if (setq ss1 (ssget "_x" '((0 . "INSERT") (2 . "_11x17"))))
  (mapcar
   '(lambda (x)
     (setq ent     (cadr x)
           entdata (entget ent))
     (while (/= (cdr (assoc 0 entdata)) "SEQEND")
      (cond ((= "SHT#" (cdr (assoc 2 entdata)))
             (vlax-for y  layouts
              (cond ((=
                     (vla-get-name (vla-objectidtoobject adoc (vla-get-ownerID (vlax-ename->vla-object (cdr (assoc 330 entdata))))))
                     (vla-get-name (vla-get-block y)))
                    (entmod (subst (cons 1 (itoa (vla-get-taborder y))) (assoc 1 entdata) entdata)))
                    (T ())))
              ))
            (setq entdata (entget (setq ent (entnext ent))))))
     (ssnamex ss1))
  "No titleblocks found!")
 (princ))

 

 

 


Hello Ranjit,

 

I've been looking for this for some weeks. I've tried your lisp but doesn't work at all. Which attribute do you use to number the pages? Because I understand you write page number 1/5, 2/5, ...5/5 and after all, you use autocad lisp, are you?

 

Thank you so much in advance.

I'm looking forward to hearing from you.

 

Regards,

Ana

0 Likes
Message 10 of 19

wfraser3
Explorer
Explorer

The code specifies the block name ("_11x17") and the attribute name ("SHT#") of the sample title block provided. Change these to your block name and attribute name and the code will work.

Message 11 of 19

Anonymous
Not applicable

Thank you so much for your time to answer.

 

Best regads

0 Likes
Message 12 of 19

vladimir_michl
Advisor
Advisor

See also the PageOf utility (reactor):

https://www.cadforum.cz/cadforum_en/total-number-of-layouts-as-a-field-tip11171

 

Vladimir Michl, www.cadstudio.cz

 

Message 13 of 19

Anonymous
Not applicable

Thank you so much!

0 Likes
Message 14 of 19

CarlosAJL
Community Visitor
Community Visitor

Hola! 

no puedo ejecutarlo 😞

; error, "no funCtion definition: PRINCIPE"

 

¿Que hice mal?

0 Likes
Message 15 of 19

asilva_mad
Participant
Participant

Hi wfraser3;

 

I changed the name of the title block but left the attribute tag the same because I used "SHT#" in the name, but the numbers don't change. I'm using AutoCAD 2023 but I don't know if that has something to do with it.

 

May you help me with this problem?

Thanks!

0 Likes
Message 16 of 19

rcasteel2CH8H
Community Visitor
Community Visitor

Could you add to this source code to make it display total pages in set. For instance if a file has 10 pages make it to where it would say 1 of 10, 2 of 10..... 10/10?

0 Likes
Message 17 of 19

wfraser3
Explorer
Explorer

I make a custom property shown in the picture (drawing utilities -> drawing properties -> custom -> add) and then 'insert field' of the custom property in text (in the mtext, right click and find insert field, find the name of the custom property and click insert). You'll have to manually update it from the drawing utilities, but it'll update it for all of the pages if it's in your title block. 

 

Screenshot (1).png

0 Likes
Message 18 of 19

wfraser3
Explorer
Explorer

I'd have to see your drawing 🙂 

0 Likes
Message 19 of 19

pete.j.schiller
Contributor
Contributor

I am using the PageOf tool (see Message #12) to update the fields and total number of pages. Quite handy.

0 Likes