• This forum is the machine-generated translation of www.cad3d.it/forum1 - the Italian design community. Several terms are not translated correctly.

multiple selection of blocks based on the attribute value

  • Thread starter Thread starter Giuseppe Beatrice
  • Start date Start date

Giuseppe Beatrice

Guest
Hello, I have a problem to expose regarding the realization of a portion of lisp code for use with autocad 2007.
I would like to select, with the instruction ssget of autolisp, between a series of blocks with attributes, only those whose attribute has a certain value, in order to be able to vary it with appropriate instructions, always in lisp.
is it possible to do so, with ssget or, possibly, with different instructions I don't know?
Thank you for your cooperation.
 
Thank you, gp.
the file you recommended actually helped me a lot to search for blocks with a given attribute.
However I still have a problem, since the search I ran does not allow me to perform the final task, which is to change the value of a second block attribute to a new value.
in other words, using a fragment of the file lisp you recommended, I created a selection group in which all the blocks that have the specified value of the first attribute are contained; I cannot change, however, for each member of this selection group, the value of a second attribute to a new assigned value.
Can you help me again? Thanks again and excuse me for the trouble.
 
you must replace the bet pair corresponding to the attribute value and update the db with (entmod).
in this example if the selected block has a "topolino" attribute is replaced by "pluto"
HTML:
(setq ent (entget (car (entsel))))

(if (= (cdr (assoc 0 ent)) "insert")
(progn
(setq ogg (cdr (car ent)))
(setq ent1 (entnext ogg))
(if any)
(progn
(setq tipo (cdr (assoc 0 (entget ent1))))
(while (= tipo "attrib")
(setq valore_attributeo (cdr (assoc 1 (entget ent1))))

(if (= valore_attribute "topolino")
(progn
(setq attrib (entget ent1))
(setq new (cons 1 "pluto"))
(setq old (assoc 1 (entget ent1)))
(setq attrib (subst new old attrib))
(entmod attrib) )
)

(setq ent1 (entnext ent1))
(setq tipo (cdr (assoc 0 (entget ent1))))
)
)
)
)
)
 
Thank you, gp.
I used your code fraction to change the block, adding only the final instruction
(entmod ent)
with which you change the block on the design.
only one curiosity: because if I launch education
(entupd mod)
Does a mistake occur?
Anyway, thank you again, you're a friend!
 
with (entupd) update the block, that is the main entity.

if you mod It was:

((-1). <nome 7ed91b78="" entità:="">) (0 . "insert") (330 . <nome 7ed92cf8="" entità:="">) (5 . "b0f") (100 . "acdbentity") (67 .

you should write (entupd (cdr (car mod)))

but the attributes are not updated with the entmod alone?</nome></nome>
 
If you need to clarify ideas, I leave this note.
entmod works in a complementary way to entget: entget recovers from the database the entity (individual from the pair (-1 . <nome entità="">), then follows a possible change, and at the end entmod returns the entity (in the form of a list) to the database, updating it; entmod also regenerates a simple entity on the screen, but does not redesign on screen a complex entity, like a polyline or a block, when a sub-entity, example a vertex is modified.
on the contrary entupd updates to screen all entities, simple or complex; its argument can be both the name of the entity and that of its sub-entity, but in any case it redesigns the whole entity.
instead to update all instances of the blocks, in the case of a change, it is not enough entupd, but it is necessary to add a regen.</nome>
 
I thank all for the contribution to the discussion, and I apologize for the involuntary error, perhaps at the origin of both answers, which I have committed indicating education (ent against) as if there was a further variable modIt's not there.
what I meant is that with the first instance (ent totrib) of the code indicated by gp, the content of the sub entity is updated int1 of the block with the new attrib value, and the real entity containing that attribute is not updated on the drawing (the block, identified in the ent variable of the file): I have been able to see that, finally launching further education (entmod ent), even the blockade is actually modified on the drawing with the new value of the attribute (the question that gp asked me is correct, that instruction is in itself necessary and sufficient to solve the problem completely).
the doubt - only philosophical at this point - that remains is, on the contrary, related to the actual functioning of education entupd: because, by launching education (entupd ent), both in place and after (entmod ent), an error is generated?
 
probably, as gp. has already told you, the entupd function needs, as an argument, not the entity, but the name of the entity, therefore:
not entupd (ent)
but entupd (cdr (car (ent))).
 
in other words, using a fragment of the file lisp you recommended, I created a selection group in which all the blocks that have the specified value of the first attribute are contained;
bye,
I would just need a script like the one you made. I should in fact select a group of blocks based on the value of an attribute, then be able to copy, move, etc.
would you be so kind to post the result of your work?

Thank you very much.
Roman lords
 
caro romnexus6, the lisp I'm working on doesn't do the things you ask: in fact it extracts simply, from the container created by the "ssget" function with all the blocks of a design, those with a certain text value (in my case they represent the electric cables of power of a series of loads, each with the name of the powered load, and for them I placed equal to "nd" the value of the section, which I then calculated separately with a excel file). the values calculated for each section are therefore associated with the name of the load and written in a txt file, which is read from my lisp list, which then neatly replaces on the drawing, for each powered load, the value associated with the section to the previous text "nd". the core that has allowed me to solve this problem, as you see very specific, was the code lisp mailed by gp, which I think can be the basis also to solve your problem, since you will only have to adapt it to your needs to carry out the necessary actions to your case on the blocks, perhaps with the instruction "command". Of course, I won't have any trouble getting through my list if you still feel it necessary as soon as I'm done.
 
bye,

Maybe your script can help me.
What I would like to do in detail is:

- search for all blocks that have an attribute = string
- move them all to another layer

What do you think?

Roman Roman
 
here is a list that I hope will help you:
;; modification function of the insert layer blocks having a given attribute value
;; to digit the text to be found in the attributes of the blocks, even partially and correctly indicating uppercase and lowercase
(defun c:mod_lay (/)
(sing)
" attention: the program will replace the layer of all blocks containing the text indicated !!! "
(setq sel (ssget "_x"((0 . "insert"))));construction of selection group with all drawing blocks
(Sectq)
txt (getstring)
"indicate text to be searched in the block (write also the capitals correctly))

(setq layer (getstring "\new layer on which to move the block : <0> "))
(if (not layer) ; if you press only send
(setq layer "0")
(research sel txt) ;build group containing only the blocks with right circus attribute
(modifies sel_rist layer) ;changes narrow group blocks with the new section
) ;
[Bleep] [Bleep] [Bleep] [Bleep] [Bleep] [Bleep [Bleep] [Bleep] [Bleep] [Bleep] [Bleep] [Bleep] [Bleep] [Bleep] [Bleep] [Bleep] [Bleep] [Bleep [Bleep] [Bleep] [Bleep] [Bleep] [Bleep] [Bleep [Bleep] [Bleep] [Bleep] [Bleep] [Bleep [Bleep] [Bleep] [Bleep] [Bleep] [Bleep] [Bleep] [Bleep] [Bleep [Bleep] [Bleep [Bleep] [Bleep] [Bleep] [Bleep [Bleep] [Bleep] [Bleep [Bleep] [Bleep] [Bleep] [Bleep] [Bleep] [Bleep] [Bleep
[Bleep] [Bleep] [Bleep] [Bleep] search for track text
(defun research (sel txtcer / ent1 index ogg name num type txtrov)
(setq num (sslength sel)); the number of blocks present in the selection
(setq sel_rist (ssadd));builds blank selection to add blocks to the criterion
(setq index 0)
(repeat num ; use of code fragment suggested by gp (cad3d.it)
(setq name (ssname sel index) ; hexadecimal authority name
(setq ent (entget name)); definition of the main entity (block)
(setq ogg (cdr))
(setq ent1 (entnext ogg));sub entity (other than nil only if the block contains attributes)
(if ent)
(progn)
(setq type (cdr (assoc 0 (entget ent1))))
(while (= type "attrib")
(setq txtrov (cdr (assoc 1)))
(if (= txtrov txtcer)
(xdd name sel_rist)); add the entity corresponding to the criterion to the restricted group
(setq ent1 (entnext ent1))
(setq type (cdr (assoc 0 (entget ent1))))));
(setq index (+ index 1)) ;up the index to the next block of the group
) ; repeat end; the narrow group is completely built
) ;

[Bleep] [Bleep] [Bleep] [Bleep] [Bleep] [Bleep [Bleep] [Bleep] [Bleep] [Bleep] [Bleep] [Bleep] [Bleep] [Bleep] [Bleep] [Bleep] [Bleep] [Bleep] [Bleep] [Bleep] [Bleep] [Bleep] [Bleep] [Bleep [Bleep] [Bleep] [Bleep] [Bleep [Bleep] [Bleep] [Bleep] [Bleep] [Bleep] [Bleep] [Bleep [Bleep] [Bleep] [Bleep] [Bleep] [Bleep [Bleep] [Bleep [Bleep [Bleep] [Bleep] [Bleep [Bleep] [Bleep] [Bleep] [Bleep] [Bleep] [Bleep] [Bleep
;;change function of the only section in the type of cable of the block sought
(defun edit (sel_rist layer /)
(setq num (sslength sel_rist)) ;calculates the number of blocks present
(setq index 0)

(repeat num)
(setq name (ssname sel_rist index)); hexadecimal entity name
(setq ent (entget name))
(setq oldlayer (assoc 8 ent));_list of definition of the main entity (block)
(setq newlayer (cons 8 layer))


(setq ent (subst newlayer oldlayer ent)
(entmod ent)
(setq index (+ index 1))
) ;_update the index by moving to the next block of the group

)
 
thanks giuseppe,

I was very helpful and educational.

I also found another way to do what I said, i.e. select the blocks that have a certain attribute value.

- Select all blocks
- find
- indicate the string to search, then enter
- click on "select everything"

I hope that this procedure will also help other users.

Thanks again,
Hi.

Roman Roman
 
Sure, the solution you found is definitely valid and has the advantage of being ready to use.
On the other hand, I find that all autocad commands are just a series of lisp functions, so writing some of our invention only serves to speed up the conduct of particular procedures that we need at that time.
 
Good morning to all are fabrizio
my problem is that I can't with a lisp to "take" within a block the different (about ten) values of attribute. the difficulty lies in the fact that the coordinate I have available to select is bet on the last attribute and I have no way to change it.
Thank you in advance ... I hope to have been clear !!!
Hello everyone
 
reading the attributes of a block requires first to recognize the "external" block entity, and this you can do, for example with the command (setq noment (car (entsel "select the block))))
then with the next command light the block definition set:
(setq defent (entget noment)
in this way you will have to insert point, layer, etc...
to read attributes you have to make a series of other later steps of the same type:
(setq noment (entnext noment)
(setq defent (entget noment)
you will see that every time you run these two instruction rows you will get a list containing the attribute value associated with the dxf code 1.
the procedure ends when the value associated with the code dxf 0 is "seqend".
I hope I've been quite clear.
 
reading the attributes of a block requires first to recognize the "external" block entity, and this you can do, for example with the command (setq noment (car (entsel "select the block))))
then with the next command light the block definition set:
(setq defent (entget noment)
in this way you will have to insert point, layer, etc...
to read attributes you have to make a series of other later steps of the same type:
(setq noment (entnext noment)
(setq defent (entget noment)
you will see that every time you run these two instruction rows you will get a list containing the attribute value associated with the dxf code 1.
the procedure ends when the value associated with the code dxf 0 is "seqend".
I hope I've been quite clear.
Thank you... I try and I will know
 
bye,
Anchio, like Mr. Ladies, I would need that script for multiple selection of blocks that have the same attribute value.
I would be very grateful! !

thanks in advance!
Fances
 
bye,
Anchio, like Mr. Ladies, I would need that script for multiple selection of blocks that have the same attribute value.
I would be very grateful! !

thanks in advance!
Fances
I'm sorry, but isn't the list already on the discussion?
find it in red by scrolling the sequence of questions and answers.::mixed:
 

Forum statistics

Threads
44,997
Messages
339,767
Members
4
Latest member
ibt

Members online

No members online now.
Back
Top