extract dim text...

Discussion in 'AutoCAD' started by Aaron Weissner, Jul 8, 2004.

  1. i tried to do this (see below)... but all i keep getting is the same
    information as (entget (car (entsel))) or a blank list... how do i extract
    the text from a dimension without exploding the dim...

    (defun GET:ATT (EN / EL RES)
    (setq EN (entnext EN)
    EL (entget EN))
    (while (= (cdr (assoc 0 EL)) "ATTRIB")
    (setq RES
    (cons
    (cons
    (cdr (assoc 2 EL))
    (cdr (assoc 1 EL))) RES)
    EN (entnext EN)
    EL (entget EN)))
    (reverse RES)
    )
    (setq ssl (get:att (car (entsel))))
     
    Aaron Weissner, Jul 8, 2004
    #1
  2. Aaron Weissner

    Doug Barr Guest

    What's wrong with
    (cdr (assoc 42 (entget (car (entsel)))))
    ?
     
    Doug Barr, Jul 8, 2004
    #2
  3. to be honest i work in arch. units and did not know that 42 was the
    dimension value... thats great, much easier... thanks...
     
    Aaron Weissner, Jul 8, 2004
    #3
  4. Well, I see some others have beat me to it a little, but since I go this
    far, I'll send it -- this might alert you to some more possibilities.

    You don't need to treat it like an attribute. You can get it directly from
    the dimension entity. Get the association list:
    (setq diment (entget (car (entsel "Select Dimension Entity: "))))

    If it uses the actual measurement (or even if it doesn't), dxf/assoc code 42
    contains the measurement (in decimal drawing units). If you want it that
    way to use numerically, it's pretty easy:
    (setq dimcontent (assoc 42 diment))

    If you want it as a text string, (rtos) [for "real-to-string"] will convert
    a real number to a text string, with modifiers for the type of units you
    want it to give you:
    (setq dimcontent (rtos (assoc 42 diment) <mode> <precision>))

    If there's override text, it's in dxf/assoc 1, which often would already be
    a text string:
    (setq dimcontent (assoc 1 diment))

    If there's no override text, assoc 1 is still there, with a content of "".
    If you want to use the override text if there is any, but use the actual
    measurement as a text string if there isn't, you'd need to check for
    override:
    (if (= (cdr (assoc 1 diment)) "")
    (setq dimcontent (assoc 1 diment))
    (setq dimcontent (rtos (assoc 42 diment) <mode> <precision>))

    But if the override text is, for example, the actual measurement plus a
    plus-or-minus sign, it should look like "<>%%P" even though the dimension
    displays on-screen with measurement characters and a real plus-or-minus
    sign, so you'd have trouble extracting that in a meaningful way. That's
    probably possible but could be complicated, since the <> representing the
    actual measurement could come anywhere in an override text string, and you'd
    have other possible special character codes to figure for. Too much for me
    to think about right now.

    Kent Cooper, AIA


    ...
     
    Kent Cooper, AIA, Jul 8, 2004
    #4
  5. Whoops -- forgot a bunch of "cdr's" before the assoc calls here; corrected
    below.

     
    Kent Cooper, AIA, Jul 8, 2004
    #5
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.