Drilling down into a blocked attribute

Discussion in 'AutoCAD' started by Mike Hetherton, Aug 6, 2004.

  1. Hi Group, below is something mean and nasty I have created. It does the task
    required but can be more efficient, and I am stuck on that part.

    Problem, I have to select the attribute twice (once to dump the material
    name) and secondly to dump the length.

    I don't know how to access the subentitys. Therefore I have to select the
    block BOM twice and select the exact attribute also. I'm probably not making
    much sense.

    Cheers
    Mike
    OZ



    (defun C:SR (/ DIMSTR1 DIMSTR2 DIMSTRL DIMSTRN DIMATT1 DIMATT2)
    (setq DIMSTR1 (CDR (ASSOC 1 (entget (car (entsel "\nSelect text with
    material name included: \n"))))))
    ;WE NOW HAVE THE STRING "150 PFC x 5421 LONG"
    ; THE NEXT OBJECTIVE IS TO CUT OUT THE STEEL NAME AND STEEL LENGTH
    (setq DIMSTR1 (vl-string-right-trim " LONG" DIMSTR1))
    ; WE NOW HAVE THE STRING "150 PFC x 5421"
    (setq DIMSTR2 (vl-string-position (ascii "x") DIMSTR1 nil t))
    ;POSITION EQUALS 8
    (SETQ DIMSTRL (SUBSTR DIMSTR1 (+ DIMSTR2 3)))
    ;DIMSTR = "5421" WE KNOW HAVE OBTAINED THE STEEL LENGTH
    (SETQ DIMSTRN (SUBSTR DIMSTR1 1 (- DIMSTR2 1)))
    ;DIMSTRN = "150 PFC" WE KNOW HAVE OBTAINED THE STEEL NAME
    (SETQ DIMATT1 (entget (car (nentsel "\nSelect material in bom:
    \n"))));BLOCK IS CALLED BOM ATTRIBUTE IS CALLED MATERIAL
    (setq DIMATT2 (entget (car (nentsel "\nSelect length in bom: \n")))); SAME
    BLOCK BUT ATTRIBUTE IS CALLED LENGTH
    (setq DIMATT1 (subst (cons 1 DIMSTRN)(ASSOC 1 DIMATT1) DIMATT1))
    (setq DIMATT2 (subst (cons 1 DIMSTRL)(ASSOC 1 DIMATT2) DIMATT2))
    (ENTMOD DIMATT1)
    (ENTMOD DIMATT2)
    (COMMAND "REGEN")
    (PRINC)
    )
     
    Mike Hetherton, Aug 6, 2004
    #1
  2. Mike Hetherton

    coachball8 Guest

    Just a suggestion. Check out this month's issue of AUGI (you can access it online at their website). R. Robert Bell wrote an excellent article about working with attributes. I know it clarified a lot of things for me.
    http://www.augi.com/login/welcome.asp
     
    coachball8, Aug 6, 2004
    #2
  3. Mike Hetherton

    Doug Broad Guest

    Mike,
    What you have should work fine.
    If you use entsel to select the block, you can check to see
    if it has attributes. If you are working with only one block,
    that could be as simple as a selection set filter, filtering on the block
    name. The entities that follow the block are the attributes.
    One simple way to access them is to use (entnext ename). By looking
    at the attribute tag, you should be able to determine which
    information should go where. Changing the attribute would
    be much as you are already doing.

    BTW, if your comments are accurate, there is no reason
    to select something to obtain the string "150 PFC x 5421 LONG".
    Just assign it to a variable.

    Regards,
    Doug
     
    Doug Broad, Aug 6, 2004
    #3
  4. Mike Hetherton

    Jim Claypool Guest

    (defun C:SR (/ DIMSTR1 DIMSTR2 DIMSTRL DIMSTRN DIMATT1 DIMATT2)
    (setq DIMSTR1 (CDR (ASSOC 1 (entget (car (entsel "\nSelect text with
    material name included: \n"))))))
    ;WE NOW HAVE THE STRING "150 PFC x 5421 LONG"
    ;THE NEXT OBJECTIVE IS TO CUT OUT THE STEEL NAME AND STEEL LENGTH
    (setq DIMSTR1 (vl-string-right-trim " LONG" DIMSTR1))
    ;WE NOW HAVE THE STRING "150 PFC x 5421"
    (setq DIMSTR2 (vl-string-position (ascii "x") DIMSTR1 nil t))
    ;POSITION EQUALS 8
    (SETQ DIMSTRL (SUBSTR DIMSTR1 (+ DIMSTR2 3)))
    ;DIMSTR = "5421" WE KNOW HAVE OBTAINED THE STEEL LENGTH
    (SETQ DIMSTRN (SUBSTR DIMSTR1 1 (- DIMSTR2 1)))
    ;DIMSTRN = "150 PFC" WE KNOW HAVE OBTAINED THE STEEL NAME
    (setq ename (car (entsel "\nSelect BOM block to change:\n")))) ;BLOCK IS
    CALLED BOM ATTRIBUTE IS CALLED MATERIAL
    (setq attlist (GetAtts ename))
    (setq attlist (subst (cons "MATERIAL" dimstrn) (assoc "MATERIAL" attlist)
    attlist))
    (setq attlist (subst (cons "LENGTH" dimstr) (assoc "LENGTH" attlist)
    attlist))
    (setatts ename attlist)
    (entupd ename)
    (PRINC)
    )

    (defun GetAtts (Obj)
    (setq obj (vlax-ename->vla-object obj))
    (mapcar
    '(lambda (Att)
    (cons (vla-get-TagString Att) (vla-get-TextString Att))
    )
    (vlax-invoke Obj "GetAttributes")
    )
    )

    (defun SetAtts (Obj Lst / AttVal)
    (setq obj (vlax-ename->vla-object obj))
    (mapcar
    '(lambda (Att)
    (if (setq AttVal (cdr (assoc (vla-get-TagString Att) Lst)))
    (vla-put-TextString Att AttVal)
    )
    )
    (vlax-invoke Obj "GetAttributes")
    )
    (vla-update Obj)
    (princ)
    )
     
    Jim Claypool, Aug 6, 2004
    #4
  5. Thanks!

    BTW, that is the Jul/Aug 2004 issue of AUGIWorld.

    --
    R. Robert Bell


    Just a suggestion. Check out this month's issue of AUGI (you can access it
    online at their website). R. Robert Bell wrote an excellent article about
    working with attributes. I know it clarified a lot of things for me.
    http://www.augi.com/login/welcome.asp
     
    R. Robert Bell, Aug 6, 2004
    #5
  6. Mike Hetherton

    Jürg Menzi Guest

    <VBG>...¦-)

    Cheers
     
    Jürg Menzi, Aug 6, 2004
    #6
  7. As a side note, it is always nice to put faces
    with names (goes for two of you in this thread :)
     
    Jason Piercey, Aug 6, 2004
    #7
  8. That's Part 3 for me. ;^)

    --
    R. Robert Bell


    <VBG>...¦-)

    Cheers
     
    R. Robert Bell, Aug 6, 2004
    #8
  9. Just totally hosed my mystique, no?

    --
    R. Robert Bell


    "Jason Piercey" <JasonATatrengDOTcom> wrote in message
    As a side note, it is always nice to put faces
    with names (goes for two of you in this thread :)
     
    R. Robert Bell, Aug 6, 2004
    #9
  10. Both of ya :)
     
    Jason Piercey, Aug 6, 2004
    #10
  11. Thank you all for your most helpful input, and I am in the process of
    downloading the AUGI newsletter.

    If I still have trouble I will be back.

    Cheers
    Mike
    OZ
     
    Mike Hetherton, Aug 6, 2004
    #11
  12. Mike Hetherton

    coachball8 Guest

    You're very welcome! You didn't really think anyone was paying attention, did you?
     
    coachball8, Aug 7, 2004
    #12
  13. The Augi newsletter was brilliant, I have had a successful weekend playing
    around with attributes, Thank you all.


    Cheers
    Mike
    OZ
     
    Mike Hetherton, Aug 9, 2004
    #13
  14. I'm glad you found the article useful!

    --
    R. Robert Bell


    The Augi newsletter was brilliant, I have had a successful weekend playing
    around with attributes, Thank you all.


    Cheers
    Mike
    OZ
     
    R. Robert Bell, Aug 9, 2004
    #14
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.