extract attribute value

Discussion in 'AutoCAD' started by spencer1971, Jun 14, 2004.

  1. spencer1971

    spencer1971 Guest

    I am tyring to extract a value of an attribute called rev from a block called pmh1 using lisp and setting it to a variable.

    I have tried searching the board but am getting nowhere fast.

    Could someone point me in the right direction regarding the commands I should be looking at or better still post a bit of code that I could adapt.

    Many thanks

    Spencer
     
    spencer1971, Jun 14, 2004
    #1
  2. spencer1971

    bob.at Guest

  3. spencer1971

    spencer1971 Guest

    So would this be right for extracting the value of attribute REV from block PM-A1V ?

    I am struggling to work this out.


    (setq ss (ssget "X" ((0 . "PM-A1V") (2. "REV"))))
     
    spencer1971, Jun 14, 2004
    #3
  4. spencer1971

    bob.at Guest

    Specer,

    unfortunatly it is not as easy as you want it. A block with attributes consist of a main entity (the insert) and one subentity for each attribut. So you first must select the Block with:
    (setq ss (ssget "X" ((0. "INSERT") (2. "PM-A1V"))))
    then you must step through the subentities wiht a while loop and testing, if the attribut tag (2-groupe of subent) is thisone you want.

    From the thrid link above, you can use the code from Wayne without testing it):


    ;;;;Returns Attribute value
    ;;;; Example: (GetAtt "tag1" "new block")
    ;;;; or: (GetAtt "REV" "PM-A1V")
    (defun GetAtt (TAG BLOCK / sset cnt ent1 ent2 entinfo name)
    (if (setq sset (ssget "x" (list (cons 2 block))))
    (progn
    (setq cnt 0)
    (setq ent1 (ssname sset cnt))
    (setq ent2 (entnext ent1))
    (setq entinfo (entget ent2))
    (while (and ent2
    (= "ATTRIB" (cdr (assoc 0 entinfo))))
    (if (= tag (cdr (assoc 2 entinfo)))
    (progn
    (setq name (cdr (assoc 1 entinfo)))
    (setq ent2 nil)
    )
    (progn
    (setq ent2 (entnext ent2))
    (setq entinfo (entget ent2))
    )
    )
    )
    )
    )
    name
    )
     
    bob.at, Jun 14, 2004
    #4
  5. (setq SS (ssget "X" (list (cons 0 "INSERT") (cons 2 "REV"))))
    (if SS
    (progn
    (setq KK 0 KS (sslength SS))
    (while (< KK KS)
    (setq EG (entget (ssname SS KK)))
    (setq A1 (entget (entnext (cdr (assoc -1 EG)))))
    (while (and (/= (cdr (assoc 0 A1)) "SEQEND") (/= (strcase (cdr (assoc
    2 A1))) "PMH1"))
    (setq A1 (entget (entnext (cdr (assoc -1 A1)))))
    )
    (if (= (strcase (cdr (assoc 2 A1))) "PMH1")
    (progn
    (setq T1 (cdr (assoc 1 A1)))
    (princ (strcat "\nPMH1=" T1))
    )
    )
    (setq KK (1+ KK))
    )
    )
    )
     
    Alan Henderson @ A'cad Solutions, Jun 14, 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.