Author Topic: prefixing layout tabs with page number attribute value  (Read 4267 times)

0 Members and 1 Guest are viewing this topic.

ELOQUINTET

  • Guest
prefixing layout tabs with page number attribute value
« on: December 10, 2007, 02:41:58 PM »
Hey guys,

I'm not sure if anyone has developed this routine. I have seen many things that are close but not exactly. Sometimes users put descriptions as layout tabs names so i'd like to prefix this with the page number so it's easy to organize sets when publishing. Has anyone done this yet?
« Last Edit: December 10, 2007, 02:58:45 PM by Eloquintet »

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

ELOQUINTET

  • Guest
Re: prefixing layout tabs with page number attribute value
« Reply #2 on: December 10, 2007, 05:31:48 PM »
cab i haven't forgotten your rename layouts routine but that's not what i'm looking for. I want to prefix the existing tab names with whatever the value of my sheet number attribute in my titleblock is. Let me explain my situation (deep breath). I completed a set of drawings which consists of 20 layout tabs spanning over about 10 files. I want to be able to prefix the tab numbers with the sheet number so I can tell my assistant where the drawings are and they can load them up to publish then sort them based on the prefix. Does this make anymore sense now?

ronjonp

  • Needs a day job
  • Posts: 7531
Re: prefixing layout tabs with page number attribute value
« Reply #3 on: December 10, 2007, 05:53:37 PM »
Code: [Select]
(defun c:tabpre (/ pre x)
  (setq pre (getstring "\n Enter prefix for tab names: "))
  (vlax-map-collection
    (vla-get-layouts
      (vla-get-activedocument (vlax-get-acad-object))
    )
    '(lambda (x)
       (vl-catch-all-error-p
(vl-catch-all-apply
   'vla-put-name
   (list x (strcat pre (vla-get-name x)))
)
       )
     )
  )
  (princ)
)
« Last Edit: December 11, 2007, 09:53:14 AM by ronjonp »

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: prefixing layout tabs with page number attribute value
« Reply #4 on: December 10, 2007, 06:04:24 PM »
Shoot, Ron is too fast. :)

Just clowning around Dan.

So you want to add a prefix to the tab name.
Like this:
Code: [Select]
;;  CAB - 07/10/07
;; This routine will rename all layout tabs with a prefix added
(defun c:prefix-all-layouts (/ Tab_name doc x cnt)
  (vl-load-com)
  (setq Tab_prefix "Pr-")
  (vlax-for x (vla-get-layouts
                (vla-get-activedocument (vlax-get-acad-object)))
    (if (not (= (vla-get-name x) "Model"))
      (vla-put-name x (strcat Tab_prefix (vla-get-name x)))
    )
  )
  (princ)
)

All you need is a routine to get the attribute value from the title block & replace
(setq Tab_prefix "Pr-") with that routine.
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

ELOQUINTET

  • Guest
Re: prefixing layout tabs with page number attribute value
« Reply #5 on: December 11, 2007, 12:17:36 AM »
well adding the prefix is not the problem as your rename layouts routine already has an option to add a prefix or suffix. The part I really need to integrate is the extraction of the attribute values per layout. I will look at these more tomorrow. thanks

FengK

  • Guest
Re: prefixing layout tabs with page number attribute value
« Reply #6 on: December 11, 2007, 02:04:43 AM »
Dan,

Do your title blocks always have the same name or have a common name pattern? Also, I suppose the title block has more than one attributes. For the attribute which has the sheet number, what's the TagString? Always the same? Common name pattern?

ELOQUINTET

  • Guest
Re: prefixing layout tabs with page number attribute value
« Reply #7 on: December 11, 2007, 09:26:45 AM »
we actually have 2 blocks we use for our titleblocks but both of them have the same attribute tag string for the sheet which is sheet numb.

FengK

  • Guest
Re: prefixing layout tabs with page number attribute value
« Reply #8 on: December 11, 2007, 12:44:03 PM »
Dan,

Not a complete solution, but maybe helpful:

(defun _Get_AttTagVal   (oBlk)
  (if (= (vla-get-hasattributes oBlk) :vlax-true)
    (mapcar (function (lambda (oAtt)
         (list oAtt
               (vla-get-tagstring oAtt)
               (vla-get-textstring oAtt)
         )
            )
       )
       (vlax-safearray->list (vlax-variant-value
                (vla-getattributes oBlk)
              )
       )
    )
  )
)

(defun _Get_AttValByTag (oBlk tag / lstAtt lstVal)
  (if (and (setq lstATV (_Get_AttTagVal oBlk))
      (setq @ (vl-position   (strcase tag)
            (mapcar 'strcase (mapcar 'cadr lstATV))
         )
      )
      )
    (caddr (nth @ lstATV))
  )
)

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: prefixing layout tabs with page number attribute value
« Reply #9 on: December 11, 2007, 02:23:10 PM »
Now you can solve it like this.
Code: [Select]
(defun c:prefix-all-layouts (/ ss blkOname Tab_prefix)
  (vl-load-com)
  (if (and
        (setq ss (ssget "x" (list '(0 . "INSERT") (cons 2 "BlockName"))))
        (setq blkOname (vlax-ename->vla-object (ssname ss 0)))
        (setq Tab_prefix (_Get_AttValByTag blkOname "TagName"))
      )
    (vlax-for x (vla-get-layouts (vla-get-activedocument (vlax-get-acad-object)))
      (if (not (= (vla-get-name x) "Model"))
        (vl-catch-all-apply
          'vla-put-name
          (list x (strcat Tab_prefix "-" (vla-get-name x)))
        )
      )
    )
  )
  (princ)
)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

ELOQUINTET

  • Guest
Re: prefixing layout tabs with page number attribute value
« Reply #10 on: December 11, 2007, 03:58:03 PM »
cab i tried yours out and got an error

; error: no function definition: _GET_ATTVALBYTAG

i was also wondering about how i deal with the problem of having 2 blocks
i have one called title and in other case title3

Code: [Select]
(defun c:prefixsheet (/ ss blkOname Tab_prefix)
  (vl-load-com)
  (if (and
        (setq ss (ssget "x" (list '(0 . "INSERT") (cons 2 "title"))))
        (setq blkOname (vlax-ename->vla-object (ssname ss 0)))
        (setq Tab_prefix (_Get_AttValByTag blkOname "Sheetnum"))
      )
    (vlax-for x (vla-get-layouts (vla-get-activedocument (vlax-get-acad-object)))
      (if (not (= (vla-get-name x) "Model"))
        (vl-catch-all-apply
          'vla-put-name
          (list x (strcat Tab_prefix "-" (vla-get-name x)))
        )
      )
    )
  )
  (princ)
)

ronjonp

  • Needs a day job
  • Posts: 7531

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

ELOQUINTET

  • Guest
Re: prefixing layout tabs with page number attribute value
« Reply #12 on: December 11, 2007, 05:08:33 PM »
uhhhh so you're saying that i need to effectively combine these two into one routine. i always get pretty lost when combining stuff.

FengK

  • Guest
Re: prefixing layout tabs with page number attribute value
« Reply #13 on: December 11, 2007, 05:10:41 PM »
How about this?

Code: [Select]
(defun C:PREFIXSHEET (/ loName ss Tab_prefix loName2)
  (vl-load-com)
  (vlax-for objLo (vla-get-layouts
    (vla-get-activedocument (vlax-get-acad-object))
  )
    (if (and (not (= (setq loName (vla-get-name objLo)) "Model"))
     (setq ss (ssget "x"
     (list (cons 0 "INSERT") (cons 2 "TITLE") (cons 410 loName))
;Replace "TITLE" with your title block name
      )
     )
     (setq Tab_prefix (_Get_AttValByTag (vlax-ename->vla-object (ssname ss 0))
"SHEETNUMB"
;Replace "SHEETNUMB" with your tag string
      )
     )
     (not (vl-position (setq loName2 (strcat Tab_prefix loName))
       (layoutlist)
  )
     )
)
      (vla-put-name objLo loName2)
      (prompt
(strcat "\nSomething isn't right with layout " loName ".")
      )
    )
  )
  (prompt "\nDone.")
  (princ)
)

(defun _Get_AttTagVal (oBlk)
  (if (= (vla-get-hasattributes oBlk) :vlax-true)
    (mapcar (function (lambda (oAtt)
(list oAtt
      (vla-get-tagstring oAtt)
      (vla-get-textstring oAtt)
)
      )
    )
    (vlax-safearray->list (vlax-variant-value
    (vla-getattributes oBlk)
  )
    )
    )
  )
)

(defun _Get_AttValByTag (oBlk tag / lstAtt lstVal)
  (if (and (setq lstATV (_Get_AttTagVal oBlk))
   (setq @ (vl-position (strcase tag)
(mapcar 'strcase (mapcar 'cadr lstATV))
   )
   )
      )
    (caddr (nth @ lstATV))
  )
)

(princ)

ELOQUINTET

  • Guest
Re: prefixing layout tabs with page number attribute value
« Reply #14 on: December 12, 2007, 05:37:42 PM »
Kelie that works great but seeing it work gave me a couple of thoughts. First how can I have it search for 2 blocks names. As I said before depending on the amount of available job info when the info is extracted from access it will use one or the other. Most users don't even know we have 2 blocks as it is automated. We have one block called title and another called title3. Another thing and this is more of a convenience but how hard would it be to put a space after the prefix. Thanks man for all of your help recently. I'm sorry I haven't been more help but they are killin me here.