Author Topic: How to insert a block where the number of attributes are varied.  (Read 1553 times)

0 Members and 1 Guest are viewing this topic.

rayakmal

  • Newt
  • Posts: 49
I'm trying to write a custom sheet manager routine. I would like to be able to pick any title block I want (Number of attributes in that block will be varied) and the routine will insert that block in paper space, all the same attributes except maybe for page numbering purpose.
Here's a snippet of the code I wrote. The problem is I can't insert a block  properly with the correct attributes.
Seems like I can't use foreach inside "insert" command. Any help and enlightenment would be much appreciated.
Thanks.

PS. I don't want to use "copybase" command because I think it's so slow if the drawing is big (> 200 Mb).

Code: [Select]
(defun c:SMR ( / ent enm blknm blkobj atts att_lst tagatt_lst n )
  (if (setq ent (entsel "\n. Select a Title Block: "))
    (progn
      (setq enm (car ent))
      (if (equal (dxf-code 0 enm) "INSERT")
        (progn
          (setq blknm (dxf-code 2 enm))
          (setq blkobj  (vlax-ename->vla-object enm))
          (setq atts (vlax-invoke blkobj 'getattributes))
          (setq att_lst    '())
          (setq tagatt_lst '())
          (foreach attobj    atts
             (setq tagis (vla-get-tagstring attobj))
             (setq attis (vla-get-textstring attobj))
             (setq att_lst    (append    att_lst (list attis)))
             (setq tagatt_lst (append tagatt_lst (list (list tagis attis))))
          );end foreach
          (setq ipt (list 0.0 0.0))
          ;; PSEUDO CODE:
          ;; CHANGE TO LAYOUT
          ;; INSERT THE TITLE BLOCK WITH ATTRIBUTES
          ;;
          ;; THIS CODE DOESN'T WORK
          (command "insert" blknm ipt "" "" ""
                     (foreach n att_lst
                        n
                     )
          )
       );end progn
     );end if
   );end progn
   (princ "\n. Entity is not a block!")
 );end if
 (princ)
)


MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: How to insert a block where the number of attributes are varied.
« Reply #1 on: May 27, 2018, 12:35:42 AM »
Enmake the insert entity (head) making sure to include (66 . 1). Then entmake each attrib. Finish by entmaking an endseq entity. I posted an example to the autodesk forums in the late 90s +/- for such an example (I used the technique for tagging various EHT, RTD compnents etc: one block def, varying attribs per instance. The technique still works all these years later). Sorry no code, on my iphone and recovering from hospitalization last week. My wife will kill me if she sees me pounding code, no matter how trivial.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

Dlanor

  • Bull Frog
  • Posts: 263
Re: How to insert a block where the number of attributes are varied.
« Reply #2 on: May 27, 2018, 03:48:23 AM »
My wife will kill me if she sees me pounding code, no matter how trivial.

I know exactly how that feels  :knuppel2:  :tickedoff:

Have a swift recovery.

BIGAL

  • Swamp Rat
  • Posts: 1411
  • 40 + years of using Autocad
Re: How to insert a block where the number of attributes are varied.
« Reply #3 on: May 27, 2018, 06:13:50 AM »
here is an example entmake a block with attribute

Code: [Select]
(entmake (list (cons 0 "BLOCK")
    (cons 2 Blkname)
    (cons 70 2)
    (cons 10 (list 0 0 0))
    (CONS 8 "0")
  ))

(entmake (list (cons 0 "CIRCLE")
(cons 8 "0")
(cons 10 (list 0 0 0))
(cons 40 3.25) ; rad
(cons 210 (list 0 0 1))
(cons 62 256)
(cons 39 0)
(cons 6 "BYLAYER")
   )
  )

  (entmake (list (cons 0 "ATTDEF")
       (cons 8 "0")
       (cons 10 (list 0 0 0))
       (cons 1 "1") ; default value
       (cons 2 blkname) ; nblock name
       (cons 3 "Ptnum") ; tag name
       (cons 6 "BYLAYER")
       (cons 7 "STANDARD") ;text style
       (cons 8 "0") ; layer
       (cons 11 (list 0.0 0.0 0.0)) ; text insert pt
       (cons 39 0)
       (cons 40 3.5) ; text height
       (cons 41 1) ; X scale
       (cons 50 0) ; Text rotation
       (cons 51 0) ; Oblique angle
       (cons 62 256) ; by layer color
       (cons 70 0)
       (cons 71 0) ;Text gen flag
       (cons 72 1) ; Text Justify hor 1 center
       (cons 73 0) ; field length
       (cons 74 2) ; Text Justify ver 2 center
       (cons 210 (list 0 0 1))
  ))

  (entmake (list (cons 0 "ENDBLK")))
  (princ)
A man who never made a mistake never made anything

HasanCAD

  • Swamp Rat
  • Posts: 1422
Re: How to insert a block where the number of attributes are varied.
« Reply #4 on: May 27, 2018, 08:13:14 AM »
My wife will kill me if she sees me pounding code, no matter how trivial.
I was thinking that the wife has rights to kill the husband only in my area,
Now I'm sure that she has the killing tools and permission all over the world.
God bless you

rayakmal

  • Newt
  • Posts: 49
Re: How to insert a block where the number of attributes are varied.
« Reply #5 on: May 27, 2018, 09:10:21 AM »
Thank you all for the responses.
Entmake is not an option for me, because Entmaking a Title Block is way beyond my ability.
I meant, I only use Entmake for a simple block making.
Maybe I better use a CopyBase command and then change the attributes of new inserted blocks.

Have a swift recovery MP.

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1453
  • Marco
Re: How to insert a block where the number of attributes are varied.
« Reply #6 on: May 27, 2018, 10:00:36 AM »
Enmake the insert entity (head) making sure to include (66 . 1). Then entmake each attrib. Finish by entmaking an endseq entity. I posted an example to the autodesk forums in the late 90s +/- for such an example (I used the technique for tagging various EHT, RTD compnents etc: one block def, varying attribs per instance. The technique still works all these years later). Sorry no code, on my iphone and recovering from hospitalization last week. My wife will kill me if she sees me pounding code, no matter how trivial.
Spero che tu stia bene ora. (I hope you're fine now.)  :)