Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

AUTO NUMBER LISP BASED ON LAYOUT TAB POSITION

18 REPLIES 18
SOLVED
Reply
Message 1 of 19
Anonymous
10495 Views, 18 Replies

AUTO NUMBER LISP BASED ON LAYOUT TAB POSITION

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

 

Tags (2)
18 REPLIES 18
Message 2 of 19
Patchy
in reply to: Anonymous

First part do this:

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

 

Your 2nd question,

 

Ask the Customization Group

 

Message 3 of 19
Anonymous
in reply to: Patchy

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?
Message 4 of 19
Ranjit_Singh2
in reply to: Anonymous

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.

Message 5 of 19
Anonymous
in reply to: Ranjit_Singh2

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

Message 6 of 19
Ranjit_Singh2
in reply to: Anonymous

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
in reply to: Ranjit_Singh2

You are amazing. Thank you!
Message 8 of 19
Anonymous
in reply to: Anonymous

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!

 

Message 9 of 19
Anonymous
in reply to: Ranjit_Singh2


@Ranjit_Singh2 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

Message 10 of 19
wfraser3
in reply to: Anonymous

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
in reply to: wfraser3

Thank you so much for your time to answer.

 

Best regads

Message 12 of 19
vladimir_michl
in reply to: Anonymous

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
in reply to: vladimir_michl

Thank you so much!

Message 14 of 19
CarlosAJL
in reply to: wfraser3

Hola! 

no puedo ejecutarlo 😞

; error, "no funCtion definition: PRINCIPE"

 

¿Que hice mal?

Message 15 of 19
asilva_mad
in reply to: wfraser3

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!

Message 16 of 19

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?

Message 17 of 19
wfraser3
in reply to: rcasteel2CH8H

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

Message 18 of 19
wfraser3
in reply to: asilva_mad

I'd have to see your drawing 🙂 

Message 19 of 19
pete.j.schiller
in reply to: wfraser3

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

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

State of Sustainability Webinar


AutoCAD Inside the Factory