Code Red > AutoLISP (Vanilla / Visual)
Anonymous Block with Attributes
(1/1)
Amsterdammed:
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:
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: ---(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))
--- End code ---
-David
CAB:
David,
I found this one some time back but never tried it.
I haven't had a need for anonymous blocks.
--- Code: ---;;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)
)
--- End code ---
Amsterdammed:
--- 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: ---(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))
--- End code ---
:D
--- End quote ---
Navigation
[0] Message Index
Go to full version