Author Topic: Anonymous Block with Attributes  (Read 2192 times)

0 Members and 1 Guest are viewing this topic.

Amsterdammed

  • Guest
Anonymous Block with Attributes
« on: May 21, 2005, 06:07:10 AM »
For an application we work with i need to create Anonymious Blocks with Attributes with the entmake function. It wotrks without the Attribs, but doesn't create the U* name fore the (2.  "name") part of the entity.

What's to think about creating a Block like this??

David Bethel

  • Swamp Rat
  • Posts: 656
Anonymous Block with Attributes
« Reply #1 on: May 21, 2005, 08:31:52 AM »
You cannot do it directly via entmake.  Group 70 will not accept a value of 3
(at least not in R12 thru 2000 )

I do it by creating a standard BLOCK with attributes and then convert the INSERT into an anonymous block.

Code: [Select]
(defun anon (b / tdef en ed bn bd in)
  (and (= (type b) 'ENAME)
       (setq bd (entget b)
             in (cdr (assoc 2 bd))))
  (if (or (not bd)
          (not in)
          (/= "INSERT" (cdr (assoc 0 bd)))
          (= "*" (substr in 1 1))
          (= (logand (cdr (assoc 70 (tblsearch "BLOCK" in)))  4)  4)
          (= (logand (cdr (assoc 70 (tblsearch "BLOCK" in))) 16) 16)
          (= (logand (cdr (assoc 70 (tblsearch "BLOCK" in))) 32) 32))
       (progn
         (princ "*** Not A Changeable Block *** ")
         (setq bd nil in nil b nil)
         (exit)))
  (setq tdef (tblsearch "BLOCK" in)
          en (cdr (assoc -2 tdef))
          ed (entget en))
  (entmake (list (cons 0 "BLOCK")
                 (cons 2 "*U")
                 (cons 70 1)
                 (cons 10 (cdr (assoc 10 tdef)))))
  (entmake ed)
  (while (setq en (entnext en))
         (setq ed (entget en))
         (entmake ed))
  (setq bn (entmake (list (cons 0 "ENDBLK"))))
  (setq bd (subst (cons 2 bn) (assoc 2 bd) bd))
  (entmod bd)
  (entupd b))


-David
R12 Dos - A2K

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Anonymous Block with Attributes
« Reply #2 on: May 21, 2005, 09:11:01 AM »
David,
I found this one some time back but never tried it.
I haven't had a need for anonymous blocks.

Code: [Select]
;;AB.LSP    creates an anonymous block from user
;;          chosen entities

;;Written by Brian Debelius, NAI Technologies Inc., Systems Division
;;Date  1995/11/14
;;      1995/04/04  simplified code

(defun c:AB ()

    ;prompt user to select objects
    (setq sset (ssget))

    ;prompt user for insertion point
    (setq pt (getpoint "\nPick insertion point"))

    ;write block header
    (entmake
        (list   '(0 . "BLOCK")
                '(2 . "*anon")
                '(70 . 1)
                (cons '10 pt)
        )
    )

    ;add entities in selection set to block
    ;repeat for every entity in the selection set
    (setq a 0)
    (repeat (sslength sset)
        (progn

            (entmake (entget (setq ent (ssname sset a))))

            ;if polyline or block reference with attributes,
            ;walk down sub-entities until seqend is found

            (if (assoc 66 (entget ent))
                (progn

                    ;add sub-entities until seqend is found
                    (setq subent (entnext ent))
                    (while (/= (cdr (assoc 0 (entget subent))) "SEQEND")
                        (entmake (entget subent))
                        (setq subent (entnext subent))
                    )

                    ;add seqend sub-entity
                    (entmake (entget subent))
                )
            )

            ;delete original entity
            (entdel ent)
        )

    (setq a (1+ a))
    )

    ;write block end sub-entity
    (setq name (entmake '( (0 . "endblk"))) )

    ;insert block reference at insertion point
    (entmake
        (list   '(0 . "INSERT")
                (cons '2 name)
                (cons '10 pt)
        )
    )

(setq sset nil)
(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.

Amsterdammed

  • Guest
Thanks a lot, it works.
« Reply #3 on: May 25, 2005, 02:05:03 AM »
Quote from: David D Bethel
You cannot do it directly via entmake.  Group 70 will not accept a value of 3
(at least not in R12 thru 2000 )

I do it by creating a standard BLOCK with attributes and then convert the INSERT into an anonymous block.

Code: [Select]
(defun anon (b / tdef en ed bn bd in)
  (and (= (type b) 'ENAME)
       (setq bd (entget b)
             in (cdr (assoc 2 bd))))
  (if (or (not bd)
          (not in)
          (/= "INSERT" (cdr (assoc 0 bd)))
          (= "*" (substr in 1 1))
          (= (logand (cdr (assoc 70 (tblsearch "BLOCK" in)))  4)  4)
          (= (logand (cdr (assoc 70 (tblsearch "BLOCK" in))) 16) 16)
          (= (logand (cdr (assoc 70 (tblsearch "BLOCK" in))) 32) 32))
       (progn
         (princ "*** Not A Changeable Block *** ")
         (setq bd nil in nil b nil)
         (exit)))
  (setq tdef (tblsearch "BLOCK" in)
          en (cdr (assoc -2 tdef))
          ed (entget en))
  (entmake (list (cons 0 "BLOCK")
                 (cons 2 "*U")
                 (cons 70 1)
                 (cons 10 (cdr (assoc 10 tdef)))))
  (entmake ed)
  (while (setq en (entnext en))
         (setq ed (entget en))
         (entmake ed))
  (setq bn (entmake (list (cons 0 "ENDBLK"))))
  (setq bd (subst (cons 2 bn) (assoc 2 bd) bd))
  (entmod bd)
  (entupd b))


 :D