Attdef returning ??

Discussion in 'AutoCAD' started by mgorecki, Nov 29, 2004.

  1. mgorecki

    mgorecki Guest

    I have a block with an "attdef". The tag is "ref #" and when I use the "ddatte" command the value for the tag is "C1". But when I run my LiSP routine it returns the vale of "??" instead of "C1".
    Here is part of the code, can someone tell me why it's returning "??" instead of "C1"?

    (setq block_ent (entget block_entity)) ;gets the DXF codes for the block entity
    (setq insert_point (cdr (assoc 10 block_ent))) ;returns the insertion point of the block
    (setq block_rotation (cdr (assoc 50 block_ent)))
    (setq block_name (cdr (assoc 2 block_ent))) ;returns the name of the block of the selected entity
    (setq subent (cdr (assoc -2 (tblsearch "BLOCK" block_name)))) ;returns entity name for subent
    (setq subent_data (entget (cdr (assoc -2 (tblsearch "BLOCK" block_name))))) ;returns DXF info for subentity
    (setq entity_type (cdr (assoc 0 (entget subent))))
    (while (/= subent nil)
    (if (or (= entity_type "ATTRIB")(= entity_type "ATTDEF"))
    (progn
    (setq text_loc_X (cadr (assoc 11 subent_data)))
    (setq text_loc_Y (caddr (assoc 11 subent_data)))
    (setq relative_text_loc (list (+ (car insert_point) text_loc_X)(+ (cadr insert_point) text_loc_Y)))
    (setq text_loc_angle (+ (angle insert_point relative_text_loc) block_rotation))
    (setq text_loc_distance (distance insert_point relative_text_loc))
    (setq new_text_loc (polar insert_point text_loc_angle text_loc_distance))
    (setq text_height (cdr (assoc 40 subent_data)))
    (setq text_value (cdr (assoc 1 subent_data)))
    :
    :
    :
    Thanks.
    Mark
     
    mgorecki, Nov 29, 2004
    #1
  2. mgorecki

    ECCAD Guest

    I think you are confusing the 'block' definition - with the 'insert' of that block - using ddatte examines a 'insert' (block), and with attributes, gives you a dialog with the 'value' of that attribute. Whereas, examining the 'block' table definition, gives you the 'default' value of the attrib / attdef..which is probably "??" as a 'default' value. ??

    Bob
     
    ECCAD, Nov 29, 2004
    #2
  3. mgorecki

    mgorecki Guest

    Is there a way to extract the "C1" value from the blocks' attdef?
     
    mgorecki, Nov 29, 2004
    #3
  4. mgorecki

    ECCAD Guest

    No. You have to 'get' the 'insert'ed one, and grab the (cdr (assoc 1subent_data). If you have 'many' - you can grab them all in a selection set, foreach x ss, obtain the values.
    Or, just (setq ent (entsel "\nPick the Block:"))
    Then, drill down to the 'tag' or attribute level.

    Bob
     
    ECCAD, Nov 29, 2004
    #4
  5. mgorecki

    mgorecki Guest

    Thank you very much. I'll give it a try.

    Mark
     
    mgorecki, Nov 29, 2004
    #5
  6. mgorecki

    mgorecki Guest

    I just can't seem to get it to retrieve the text value of the tag. What do you mean by the insert'ed one? I've tried a number of ways and I'm getting nowhere fast.
     
    mgorecki, Nov 30, 2004
    #6
  7. mgorecki

    ECCAD Guest

    ;; Get Attribute value.
    (defun C:GA ()
    (setq ent (car (entsel "\nSelect a Block:")))
    (setq elist (entget ent))
    (setq attr (entget (entnext (cdr (assoc -1 elist))))); get attribute
    (setq val (cdr (assoc 1 attr)))
    (prompt "\n ")
    (princ val)
    (princ)
    ); end defun
     
    ECCAD, Nov 30, 2004
    #7
  8. mgorecki

    Dann Guest

    What version of AutoCAD are you using?
    You should look into Visual LiSP if you are at or above Acad 2000.
     
    Dann, Nov 30, 2004
    #8
  9. mgorecki

    mgorecki Guest

    That did the trick! Thank you very much!
     
    mgorecki, Nov 30, 2004
    #9
  10. mgorecki

    ECCAD Guest

    You are welcome. Any time.

    Bob
     
    ECCAD, Nov 30, 2004
    #10
  11. mgorecki

    mgorecki Guest

    I've been using Visual LiSP for a while now, it is so much easier than using an ASCII text editor!!
     
    mgorecki, Dec 2, 2004
    #11
  12. mgorecki

    Dann Guest

    Then it is easy to get any information from you attributes using the
    following example:

    <code:
    (defun objsel ($prompt / ent)
    (vl-load-com)
    (setq ent (car (entsel $prompt)))
    (if (/= ent nil)
    (setq obj (vlax-ename->vla-object ent))
    (princ "No Object Selected")
    )
    )

    (defun C:blockinfo ()
    (objsel "\nSelect Block: ") ;objsel defined above, used to get an object
    (setq atts (vlax-safearray->list
    (vlax-variant-value (vla-getattributes obj))
    )
    ) ;stores all blocks attributes in a list

    (setq att1 (nth 0 atts)) ;this is the first attribute in the list. If you
    right click
    ;on att1 and hit "inspect" it will show you all the properties that
    ;you can access with vla-get- for example if you want the text of it
    see next line.
    (setq $text (vla-get-TextString att1))
    )
    :code>

    You can change the text using.. (vla-put-TextString att1 "new string")
     
    Dann, Dec 2, 2004
    #12
  13. mgorecki

    mgorecki Guest

    Thanks Dann,
    I'm not too familiar with the "vl" type commands, but this will certainly get me going in that direction. Thanks for the help!
    Mark
     
    mgorecki, Dec 6, 2004
    #13
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.