PDA

View Full Version : Extract attribute to layout



junaidi_roza
2010-01-25, 03:57 AM
Hi guys, I need help to extract attribute in model space into layout in paper space. Coz, hundreds of layout I have to make. If anyone have autolisp to do that? hope those layout will appear same with sequence click.

irneb
2010-01-25, 07:26 AM
Welcome to AUGI & congrats on your 1st post. Try this:
;;; Command to create a layout for each block selected
(vl-load-com) ;Ensure VLisp extensions loaded
(defun c:Blk2Lay (/ tmpFName tmpLName blkName sttName ss n en an ad lst layLst zScale)
(setq tmpFName (getfiled "Select the Template File: " "" "dwt" 12)
tmpLName (getstring t "Enter the Layout Tab Name: ")
blkName (getstring "Enter the Block name: ")
attName (strcase (getstring "Enter attribute tag name: "))
zScale (getstring "Enter Zoom Scale Factor (e.g. 1/50xp = 1:50): ")
;; Get a selection set of all blkName named blocks in Model Space
ss (ssget "X" (list '(0 . "INSERT") (cons 2 blkName) '(410 . "Model")))
) ;_ end of setq

;; Create a sorted list of blocks
(setq n (sslength ss)) ;Initialize counter
(while (>= (setq n (1- n)) 0) ;Step through all in selection set
(setq en (ssname ss n) ;Get nth entity in selection set
an (entnext en) ;Get next entity after block
) ;_ end of setq
(while (and an ;While next entity available
(setq ad (entget an)) ;And has data
(= (cdr (assoc 0 ad)) "ATTRIB") ;And is attribute
(/= (strcase (cdr (assoc 2 ad))) attName) ;And not yet found Name
) ;_ end of and
(setq an (entnext an)) ;Get next entity
) ;_ end of while
(if (and an ;If entity found
(= (cdr (assoc 0 ad)) "ATTRIB") ;And is attribute
(= (strcase (cdr (assoc 2 ad))) attName) ;And found Name
) ;_ end of and
(setq lst (cons (cons (cdr (assoc 1 ad)) en) lst)) ;Add Attrib Value & BlockRef ename to list
) ;_ end of if
) ;_ end of while
;; Sort the list
(setq lst (vl-sort lst (function (lambda (e1 e2) (< (car e1) (car e2))))))

;; Step through all blocks
(foreach en lst
(setq layLst (layoutlist)) ;Get list of layouts
(command ".-LAYOUT" "_Template" tmpFName tmpLName) ;Create a new layout from template
(foreach an (layoutlist) ;Step through new layout list
(if (not (member an layLst)) ;Check if new
(setvar "CTAB" an) ;Change to current
)
)
(command ".-LAYOUT" "_Rename" (getvar "CTAB") (car en)) ;Rename tab to Attribute value
(command "_MSPACE") ;Ensure inside VPort's Model Space
(command "_ZOOM" "_Extents") ;Zoom extents
(command "_.ZOOM" "_Object" (cdr en) "") ;Zoom to Block
(command "_.ZOOM" zScale) ;Zoom to scale
(command "_PSPACE") ;Change to Paper Space
)

(princ)
) ;_ end of defunJust a warning. With the 641 blocks, you get 642 layout tabs. This takes a while and uses a hell of a lot of RAM!

I'd advise you to later split this file into a XRef source an layout set. Try to keep to <20 layouts per DWG.

junaidi_roza
2010-01-26, 03:40 AM
Hi, Irneb.
Thanks for your quick response. But it seems doesn't work properly. There is no dialog that ask to klik the blok (attribute).
Thanks for your lisp, it's help me to understanding the autolisp. Iam newbie about lisp or programming. :)

irneb
2010-01-26, 06:03 AM
You can go and create a dialog if you like, this would be a bit more code though.The LSP simply asks for the block & attribute name in the command-line area. You have to type it in. Also after asking for the template file you need to type in the Layout name inside the template file. Unfortunately I don't know how to bring up the standard dialog when importing layouts, and trying to read the template before importing (so the Layout names can be displayed in a list to select) would require some ObjectDBX as well.

If you like, you could try to modify it to add DCL for the dialog. Search this forum for some examples. It would be a great way to learn lisp.