Insert a block based on anothers attrib insertion
Insert a block based on anothers attrib insertion
(OP)
ok where would i start lsp wise to make a lisp that given a block and either the contents of or tag name of an Attribute would insert said block at that attributes insertion point??
any ideas of where to start or how to go about getting the attributes insertion point with out exploding the block
any ideas of where to start or how to go about getting the attributes insertion point with out exploding the block
if everyone helps everybody the world will be a better place





RE: Insert a block based on anothers attrib insertion
This should be the attribute entity name, then entget the list i.e.
(entget att_name)
Now you can look at the dxf group codes 1,2,3,10 & 11
If the group codes of 1,2 & 3 match the attribute you are looking for, then use the dxf code 10 for the insertion point of the new block. If the attribute is a justified entity (other than left justify) then use the dxf code 11 for the insertion point.
So...
(defun C:InsertAtAtt( / att_list )
(setq att_name (entnext (car (entsel))))
(while (not att_list)
(setq att_list (entget att_name))
(setq tag (cdr (assoc 1 att_list))
val (cdr (assoc 2 att_list))
prm (cdr (assoc 3 att_list))
a10 (cdr (assoc 10 att_list))
a11 (cdr (assoc 11 att_list))
)
(if (and (= tag "this_value")
(= val "this_value")
(= prm "this_value")
)
(command "_.insert" "block_name" a10 "" "" "")
(setq att_list nil)
)
)
)
RE: Insert a block based on anothers attrib insertion
if everyone helps everybody the world will be a better place
RE: Insert a block based on anothers attrib insertion
RE: Insert a block based on anothers attrib insertion
if everyone helps everybody the world will be a better place
RE: Insert a block based on anothers attrib insertion
If you read the block definition from the block symbol table then filter out the entities until you find the invisible/constant attribute, then apply the coordinate of that attribute to the insertion point of that block (adding the X to X, Y to Y, and Z to Z) and rotation of the insert, then you can extrapolate the position of the constant attribute and hence insert another block at that position.
RE: Insert a block based on anothers attrib insertion
can i do a ssget and filter by object type/name???
im confusing myself maybe u can clairify all im wanting is to give the name of the block or by selecting one then have it look at the attribs and use a specific attrib tag/value/prompt use that attribs insert pnt does this make sence to you
i have been trying to get a good example of the ssget x deal so that it makes a selection set of all the blocks and allow me to filter by name of block or am i going the wrong way
???Which is the easiest, fastest, least difficult???
if everyone helps everybody the world will be a better place
RE: Insert a block based on anothers attrib insertion
The blocks are multiview blocks created in ADT... they still should be accessable through the block definition table. You can then still step through the definition to get the attribute insertion point if in fact it is invisible and constant. I would still recommend changing to invisible but non constant ... it seems easier that way.
To select all objects in the drawing based on specific criteria it is preferable to use the ssget "x" function call. The correct syntax for using ssget "x" is as follows:
Create a list of entity data (excluding xdata) that you want to filter by i.e. entity name, text value, entity type, layer, color etc....
for example:
(setq filter_list (list (cons 0 "TEXT")(cons 8 "LAYER1")))
You can specify any of the group codes if you know the value you are looking for and the DXF group code.
Now you can apply that filter to a selection set of all the entities in the drawing as follows:
(setq selection_set (ssget "x" filter_list))
You can also just quote the list in the ssget function as well:
(setq selection_set (ssget "x" '((0 . "TEXT")(8 . "LAYER1"))))
Case is insensitive for groups 0 and 8, but you must specify exactly groups 1,2,3 & 4
This will return a selection set of all entities in current space that are text entities on layer1
Keep in mind that (ssget "x" '((0 . "ATTRIB"))) will return nil regardless of the number of attributes in the drawing since the attributes are actually considered part of the complex insert to which they are attached, similar to the way a vertice is appended to a polyline entity. To access entities you must entnext the "parent" complex entity to retrieve the attached attributes excepting constant attributes of course.
I hope this sheds a bit more light on the subject
RE: Insert a block based on anothers attrib insertion
(Setq blknms (ssget "X"'(0. "AEC_MVBLOCK_REF")(0. "BLOCK REFERENCE"))
bout time i say
ok so this collects the names of the AEC_MVBLOCK_REF & BLOCK REFERENCE so u were saying that i need to use entnext to step thru and get the attrib stuff ok so do i start a new line and call out the variable or how do i do it let me give it a shot on what i should do
(Setq blknms (ssget "X"'(0. "AEC_MVBLOCK_REF")(0. "BLOCK REFERENCE"))
(setq blkatt (entget (entnext (entnext (ssget ":E" '(2 . "ATTRIB"))blknms))))
(setq att_name (entnext (car (entsel))));Variable ATT_NAME that returnes the name of entities in the list of objects selected
(while (not att_list); continues searching untill ATT_NAME Variable Is done collecting names
(setq att_list (entget att_name));Variable ATT_list
(setq tag (cdr (assoc 1 att_list));Variable TAG
val (cdr (assoc 2 att_list));Variable VAL
prm (cdr (assoc 3 att_list));Variable PRM
a10 (cdr (assoc 10 att_list));Variable A10
a11 (cdr (assoc 11 att_list));Variable A11
)
(if (and (= tag "this_value")
(= val "this_value")
(= prm "this_value")
)
(command "_.insert" "block_name" a10 "" "" "")
(setq att_list nil)
)
)
)
Does that look about right i thought that maybe i could still use the bit of code u gave me and incorperate it i think i might have quite a fe mistakes but this was just a stab at it ya know
if everyone helps everybody the world will be a better place
RE: Insert a block based on anothers attrib insertion
(setq blkname (cdr (assoc -1 (tblsearch "block" "AEC_MVBLOCK_REF")))
Then you can entnext the variable blkname until you retrieve the desired entity (presumably a constant hidden attribute)
RE: Insert a block based on anothers attrib insertion
(Defun C:InsertATATT ( / blknames blkatt blkattdef att_name att_list)
(setq blkname (cdr (assoc -1 (tblsearch "block" "AEC_MVBLOCK_REF"))))
(setq att_name (entnext (car (blkname))));Variable ATT_NAME that returnes the name of entities in the list of objects selected
(while (not att_list); continues searching untill ATT_NAME Variable Is done collecting names
(setq att_list (entget att_name));Variable ATT_list
(setq tag (cdr (assoc 1 att_list));Variable TAG
val (cdr (assoc 2 att_list));Variable VAL
prm (cdr (assoc 3 att_list));Variable PRM
a10 (cdr (assoc 10 att_list));Variable A10
a11 (cdr (assoc 11 att_list));Variable A11
)
(if (and (= tag "this_value")
(= val "this_value")
(= prm "this_value")
)
(command "_.insert" "block_name" a10 "" "" "")
(setq att_list nil)
)
)
)
does not ask for input like block name attrib tag nothing well let me know where im going wrong or what direction i nee to go hey also take a look at the other post i did on lsp defaults i didnt understand quite what he was talking about something about variables that dont destroy??? i dunno maybe you can elaborate for me
if everyone helps everybody the world will be a better place
RE: Insert a block based on anothers attrib insertion
;|
; Michael Weaver
; Alascad
; 1073 Badger Road
; Fairbanks, Alaska 99705
; Email:mikeweaver_ak@hotmail.com
; Voice and fax (907)488-3577
; (c)1996, 1997, 1998 Michael Weaver
;
; Revision History
; 3/2/92 Added c:repatt function.
; 10/8/92 Added c:ate and c:atm functions
; 5/30/98 Added c:athm function
; 8/3/98 Added c:attpresuf
;ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ
;
; (REPATT) REPlace ATTributes globally
; Environment: autocad release 10 or later
; Function: repatt
; Purpose: Repatt will search for all occurrances of a given block
; and search all attributes within those blocks for a
; given attribute value and replace each occurance with a
; new a specified value.
;
; Syntax: (repatt block old new)
; Where the arguments have the following values
; block the name of the block to search
; old the attribute value to be replaced
; new the new attribute value
;
;
; Included functions block to act on old string new string
; c:nodash prompts user - <null>
; c:repatt prompts user prompts user prompts user
; c:atem select a sample attribute, select subject blocks
; specify the new attribute value.
; c:attpresuf add a prefix and/or suffixe to multiple attributes
|;
;;;ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ
(defun repatt ( ;REPLACE ATTRIBUTES GLOBALLY
block ;name of block to scan
old ;old attribute value to search for
new ;new attribute value
/ ;end of formal argument list
ss1 ;selection set of blocks
indx1 ;index to ss1 for current block
ent ;entity name for current block
elist ;entity list for current block
ent1 ;entity name for current sub-entity
attflag ;attributes follow flag for current block
elist1 ;entity list for current sub-entity
etype1 ;entity type for current sub-entity
current ;attribute value for current attribute
) ;end of local variable list
(setq ss1 (ssget "x" (list (cons 2 block))))
(if ss1
(progn
(setq indx1 -1)
(while (< (setq indx1 (1+ indx1)) (sslength ss1))
;while blocks in selection set
(setq
ent (ssname ss1 indx1)
ent1 ent
elist (entget ent)
attflag (if (assoc 66 elist)
T
nil
) ;_ end of if
) ;_ end of setq
(if attflag
(progn ;block has attributes
(setq
ent1 (entnext ent1)
elist1 (entget ent1)
etype1 (cdr (assoc 0 elist1))
) ;_ end of setq
(while (/= etype1 "SEQEND")
(if (= etype1 "ATTRIB")
(progn
(setq current (cdr (assoc 1 elist1)))
(if (= current old)
(progn
(setq elist1 (subst (cons 1 new)
(assoc 1 elist1)
elist1
) ;_ end of subst
) ;_ end of setq
(entmod elist1)
) ;end progn
) ;end if current = old?
) ;end progn entity is attrib
) ;end if entity type?
(setq
ent1 (entnext ent1)
elist1 (entget ent1)
etype1 (cdr (assoc 0 elist1))
) ;_ end of setq
) ;end while not seqend
(entupd ent)
) ;end progn block has attributes
) ;end if attributes?
) ;end while not end of ss1
) ;end progn blocks exist
) ;end if blocks exist?
) ;end of repatt
;ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ
;RELEASE 10 OR LATER
(defun c:nodash () ;DRIVES REPATT WITH - TO <NULL>
(repatt
(cdr
(assoc
2
(entget
(car
(entsel
"\nSelect block to eliminate dash attributes: "
;select block
) ;_ end of entsel
) ;_ end of car
) ;_ end of entget
) ;_ end of assoc
) ;_ end of cdr
"-" ;old string
"" ;new string
) ;_ end of repatt
) ;_ end of defun
;ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ
;Release 10 or later
(defun c:repatt ( ;REPLACE ATTRIBS GLOBALLY, INTERACTIVE
/
)
(repatt
(cdr
(assoc
2
(entget
(car
(entsel
"\nSelect block to replace attributes: " ;select block
) ;_ end of entsel
) ;_ end of car
) ;_ end of entget
) ;_ end of assoc
) ;_ end of cdr
(progn
(setq
oldatt (if oldatt
oldatt
""
) ;_ end of if
test (getstring T (strcat "\nOld attribute value<" oldatt ">:"))
oldatt (if test
test
oldatt
) ;_ end of if
) ;_ end of setq
) ;_ end of progn
(progn
(setq
newatt (if newatt
newatt
""
) ;_ end of if
test (getstring T (strcat "\nNew attribute value<" newatt ">:"))
newatt (if test
test
newatt
) ;_ end of if
) ;_ end of setq
) ;_ end of progn
) ;end call to repatt
) ;end c:repatt
;ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ
;ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ
;replaces the value of text and attribute entities with a given value
;RELEASE 11 OR LATER
;Mike Weaver (907)344-7263 2/11/92
;ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ
(defun attrep ( ;REPLACES VALUES OF SELECTED ATTRIBS
value ;new value for entity
/ ;end of argument list
ent ;list returned by nentsel
elist ;entity list for current entity
etype ;entity type for current entity
)
(while (setq ent (nentsel "\nSelect attribute: "))
(setq
elist (entget (car ent))
etype (cdr (assoc 0 elist))
) ;_ end of setq
(cond
((= "TEXT" etype)
(princ "\nEntity selected was text. ")
(setq elist (subst (cons 1 value) (assoc 1 elist) elist))
(entmod elist)
) ;end cond TEXT
((= "ATTRIB" etype)
(princ "\nEntity selected was an attribute. ")
(setq elist (subst (cons 1 value) (assoc 1 elist) elist))
(entmod elist)
) ;end cond ATTRIB
(T
(princ "\nEntity selected not text or an attribute. ")
) ;end cond not valid
) ;end cond etype?
) ;end while
(if elist
(entupd (cdr (assoc -1 elist)))
) ;_ end of if
) ;end attrep
(defun c:null () ;DRIVES ATTREP WITH <NULL>
(attrep "")
(princ)
) ;_ end of defun
;;;ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ
;;;ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ
;;;c:adt takes selected text and/or attribute entities and combines their
;;;values adding a space and applies the result to the first entity
;;;selected.
;;;
;;;c:adtx works similarly to c:adt except all entities after the first are
;;;erased and there is no space added between the entities.
;;;
;;;adt is the engine driven by c:adt and c:adtx. It's syntax is as follows.
;;;(adt spacemode erasemode)
;;;Where the arguments have the following meanings:
;;;spacemode if non-nil a space is added between text values.
;;;erasemode if non-nil subsequent entities are erased.
;;;
;RELEASE 11 OR LATER
(defun c:adt () ;adds text values with a space, doesn't erase anything
(adt T nil)
) ;_ end of defun
(defun c:adtx () ;adds text values without a space, erases subseqent entities
(adt nil T)
) ;_ end of defun
(defun adt ( ;COMBINES TEXT/ATTRIBUTE VALUES
spacemode ;add intermediate space if non-nil
erasemode ;erase all but 1st item if non-nil
/ ;end of formal argument list
valid ;local function
ent1 ;primary entity
ent2 ;secondary entity
elist1 ;entity list for ent1
elist2 ;entity list for ent2
test ;loop control flag
*error* ;internal error handler
undo ;undo control flag
)
;;;ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
;;LCA - COMMENT: *error* defun no longer evaluates as a list.
;;LCA - COMMENT: *error* defun no longer evaluates as a list.
(defun *error* (st)
(if undo
(progn
(setvar "cmdecho" 0)
(command "undo" "e")
(setvar "cmdecho" 1)
(setq undo nil)
) ;_ end of progn
) ;_ end of if
(if ent1
(redraw (car ent1))
) ;_ end of if
(princ st)
(princ)
) ;_ end of defun
;;;ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
(defun valid (elist) ;VALIDATES ENTITY TYPES
(if (or
(= (cdr (assoc 0 elist)) "TEXT")
(= (cdr (assoc 0 elist)) "ATTRIB")
) ;end or
T ;return T
nil
) ;end if
) ;end valid
;;;ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
(setvar "cmdecho" 0)
(command "undo" "m")
(setq undo T)
(setvar "cmdecho" 1)
(setq ent1 (nentsel "\nSelect primary entity: "))
(if ent1
(progn
(redraw (car ent1) 3)
(setq
elist1 (entget (car ent1))
) ;_ end of setq
(if (valid elist1)
(progn
(setq test T)
(while test
(setq
ent2 (nentsel (strcat "\n"
(cdr (assoc 1 elist1))
"\nSelect entity to combine: "
) ;_ end of strcat
) ;_ end of nentsel
elist2 (if ent2
(entget (car ent2))
) ;_ end of if
) ;_ end of setq
(if (and elist2 (valid elist2))
(progn
&