EntDraught Posted February 22, 2023 Posted February 22, 2023 Hello, I'm here with my hat in my hand hoping people won't be offended by a basic question but I've found many posts about doing this online and many of the examples use VLA and I'm not at all familiar with it and while I've programmed a lot of custom LISP routines in the past (over 15 years ago) I basically have to relearn it because of the time lapse. All I want to do is pick a single block which has two attribute tags PIPE_DIAM and PIPE_LENGTH and store the values into variables for use elsewhere. I'm not sure where to go next after getting the entity name. Quote
Steven P Posted February 22, 2023 Posted February 22, 2023 These might help:' http://www.lee-mac.com/attributefunctions.html 1 Quote
Tharwat Posted February 22, 2023 Posted February 22, 2023 Here is a AutoLISP vanilla example for you to start with and the text strings would be in a list and should be printed to command line if tag strings matched. (defun c:Test (/ sel ent get lst ) (and (princ "\nSelect attributed block to replace retrieve values : ") (or (setq sel (ssget "_+.:S" '((0 . "INSERT") (66 . 1)))) (alert "Invalid object or nothing selected! Try again.") ) (setq ent (ssname sel 0)) (while (not (eq (cdr (assoc 0 (setq get (entget (setq ent (entnext ent)))))) "SEQEND")) (and (wcmatch (strcase (cdr (assoc 2 get))) "PIPE_DIAM,PIPE_LENGTH") (setq lst (cons (cdr (assoc 1 get)) lst)) ) ) (princ lst) ) (princ) ) 2 Quote
EntDraught Posted February 22, 2023 Author Posted February 22, 2023 1 hour ago, Steven P said: These might help:' http://www.lee-mac.com/attributefunctions.html Thanks, I've come across those in my searches and some of Lee's postings and he's a very helpful guy but for some reason I only had varied success trying to use those. I know it's just me though. 1 Quote
EntDraught Posted February 22, 2023 Author Posted February 22, 2023 50 minutes ago, Tharwat said: Here is a AutoLISP vanilla example for you to start with and the text strings would be in a list and should be printed to command line if tag strings matched. (defun c:Test (/ sel ent get lst ) (and (princ "\nSelect attributed block to replace retrieve values : ") (or (setq sel (ssget "_+.:S" '((0 . "INSERT") (66 . 1)))) (alert "Invalid object or nothing selected! Try again.") ) (setq ent (ssname sel 0)) (while (not (eq (cdr (assoc 0 (setq get (entget (setq ent (entnext ent)))))) "SEQEND")) (and (wcmatch (strcase (cdr (assoc 2 get))) "PIPE_DIAM,PIPE_LENGTH") (setq lst (cons (cdr (assoc 1 get)) lst)) ) ) (princ lst) ) (princ) ) Thank you very much! That gets me where I need to be and should be able to get me started back up in my routine! I'll have some reading to do in order to make sense of some of it but I really do appreciate it! Quote
Tharwat Posted February 22, 2023 Posted February 22, 2023 Excellent, you are most welcome Feel free to ask if you stuck with any part of the codes. 1 Quote
BIGAL Posted February 22, 2023 Posted February 22, 2023 A alternative example is retrieve all the attributes and just get the textstring for an attribute based on its creation order number, note its number -1 as nth starts at 0. (setq obj (vlax-ename->vla-object (car (entsel "Pick obj")))) (setq atts (vlax-invoke obj 'Getattributes)) (setq val1 (vla-get-textstring (nth 0 atts))) (setq val2 (vla-get-textstring (nth 1 atts))) so I have a block with 20 attributes and just want att 3 & 7 (setq val1 (vla-get-textstring (nth 2 atts))) (setq val2 (vla-get-textstring (nth 6 atts))) This is a more global approach as don't need to know Tag names. Also note block appearance of attributes does not reflect the creation order. Just double click the block, will show attribute order. Quote
mhupp Posted February 23, 2023 Posted February 23, 2023 Shout out to @ronjonp for showing me getpropertyvaule (setq ent (car (entsel "Pick obj")))) (setq pdia (getpropertyvalue ent "PIPE_DIAM")) (setq plen (getpropertyvalue ent "PIPE_LENGTH")) and if you want to update another block with attributes use setpropertyvalue 1 Quote
EntDraught Posted February 23, 2023 Author Posted February 23, 2023 10 hours ago, mhupp said: Shout out to @ronjonp for showing me getpropertyvaule (setq ent (car (entsel "Pick obj")))) (setq pdia (getpropertyvalue ent "PIPE_DIAM")) (setq plen (getpropertyvalue ent "PIPE_LENGTH")) and if you want to update another block with attributes use setpropertyvalue Everyone has been very generous and I'm very thankful for that. You all are a great group of people! But @mhupp, you get the trophy! Thank you!!! 1 Quote
j2lstaples Posted February 23, 2023 Posted February 23, 2023 1 hour ago, EntDraught said: Everyone has been very generous and I'm very thankful for that. You all are a great group of people! But @mhupp, you get the trophy! Thank you!!! You can always (princ) so it shows the value in the command line so you know it stored the correct value. Quote
BIGAL Posted February 23, 2023 Posted February 23, 2023 Get & Setproperty are not supported in Bricscad V20 not sure about latest version. So for me use what I posted not everyone has Autocad. Bricscad, ZWcad, Intellicad, Drafsight to mention a few no idea which support Get & Set. 1 Quote
TheVAS Posted February 27, 2023 Posted February 27, 2023 You will also find that you can read the bodies of the ATTOUT and ATTIN commands. When I was first learning to extract attributes, I went through those documents with 3 highlighters and lots of notes. If I remember correctly, the 'assoc' command determines the format of dotted pairs which are extracted. The '#' switch receives a value of 1-4, which you select. The output of each of those 4 items determines the format of the value you extract. If I'm remembering correctly, then you might try playing around with that switch to learn more. ("The ABC's of AutoLIPS" page 206). Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.