Attribute Append Lisp

Discussion in 'AutoCAD' started by Brockster, Feb 20, 2004.

  1. Brockster

    Brockster Guest

    Okay you Lisper, I need your help. I need a lisp/script to append the existing text of two attribute into one with some additional text. Example, the five attributes are;
    TITLE1
    TITLE2
    TITLE3
    TITLE4
    TITLE5

    The results I need is the following:
    TITLE3<space><dash><space>SITE
    TITLE2<space><dash><space>TITLE1
    TITLE4<space><dash><space>TITLE5

    I will be running the lisp/script with a batch program. Thanks in advance.
     
    Brockster, Feb 20, 2004
    #1
  2. (defun ConnectTwoAttributesWithADash (Attribute1 Attribute2)
    (strcat Attribute1 (chr 32) (chr 45) (chr 32) Attribute2))

    usage:

    (ConnectTwoAttributesWithADash TITLE3 SITE)
    (ConnectTwoAttributesWithADash TITLE2 TITLE1)
    (ConnectTwoAttributesWithADash TITLE4 TITLE5)

    existing text of two attribute into one with some additional text. Example,
    the five attributes are;
     
    Rick Francken, Feb 20, 2004
    #2
  3. Brockster

    Rudy Tovar Guest

    There's that dreaded word again, "I need"....

    How's about

    (definefunction command:name (symbol) (set-symbol symbol
    (nestedentityselect))(printcommandline)
    )



    existing text of two attribute into one with some additional text. Example,
    the five attributes are;
     
    Rudy Tovar, Feb 20, 2004
    #3
  4. Brockster

    Jon Guest

    Hey Herman, this one is definitely a no go.

    Jon
     
    Jon, Feb 20, 2004
    #4
  5. Brockster

    Brockster Guest

    Rick, I kind of understand your solution. So, I create the following;

    (defun ConnectTwoAttributesWithADash (TITLE1 TITLE2)
    (strcat TITLE1 (chr 32) (chr 45) (chr 32) TITLE2))

    Do I need a separate lisp for each of the three lines?

    Rudy, I don't get yours. Can you give me an example using my attribute names?
     
    Brockster, Feb 20, 2004
    #5
  6. Well, basically the function just takes two strings and makes a new string
    in the format of
    "String1 - String2"
    So yeah, each time you want to create a new title in that format, just call
    the function with the two strings you want put together.

    Say you want the title to be "FRED - ALBERT"... just call the function like
    this...

    (setq *NewTitle* (ConnectTwoAttributesWithADash "FRED" "ALBERT"))

    or using variables in the arguments you pass...

    (setq Attribute1 "FRED")
    (setq Attribute2 "ALBERT")
    (setq *NewTitle* (ConnectTwoAttributesWithADash Attribute1 Attribute2))

    then do what you need to do by using the variable *NewTitle*
     
    Rick Francken, Feb 20, 2004
    #6
  7. Brockster

    Brockster Guest

    This doesn't seem to work for me and let me clarify why. The reference I made to TITLE1 is the attribute name, same for TITLE2, etc. belonging to a block named Title-Info. I have 150 drawing files using this attribute block. The attribute text strings varies from drawing to drawing. Now, I would like to call-up a lisp program using my batch program by using the command name "Merge-Attr" and have the attribute's value merged in the manner I have below. The word Site is an additional text to the attribute string.

    In a drawing the values of the five TITLE attributes might be:
    TITLE1=Arlington
    TITLE2=Rosslyn
    TITLE3=Virginia
    TITLE4=Discipline
    TITLE5=Civil

    The lisp needs to do the following:
    Virginia<space><dash><space>Site
    Rosslyn<space><dash><space>Arlington
    Discipline<space><dash><space>Civil

    In which the displayed results would look like this in the my titleblock sheet:
    Virginia - Site
    Rosslyn - Arlington
    Discipline - Civil

    I hope this clarification helps and I do appreciate your effort and thank you in advance...
     
    Brockster, Feb 20, 2004
    #7
  8. Brockster

    Rudy Tovar Guest

    Let me correct myself or perhaps the way your phrased the request.

    "I'm working on a utility to replace attribute values with new values,
    here's the utility I've been working on, could someone help me finish it".

    (defun c:uptitle (/)

    (setq a (ssget "x" '((0 . "insert")(2 . "<blockname>"))))
    (setq tb (ssname ss 0))
    ;scan tb values
    ;(entmod (setq val (subst new-attr-value old-attr-value data)))
    ;etc.
    (princ)
    )

    names?
     
    Rudy Tovar, Feb 20, 2004
    #8
  9. Brockster

    ECCAD Guest

    Brockster,
    You could try this. Cut-paste below - save as "fixtitle.lsp"
    In your Script - do:
    Open filename..
    (Load "fixtitle.lsp")
    qsave
    Open filename..
    (Load "fixtitle.lsp")

    ---------------------
    ;;
    ;; Local DXF Function
    ;;
    (defun dxf (code elist)
    (cdr (assoc code elist))
    ); end function dxf
    ;;
    (setvar "CMDECHO" 0)
    ;;
    ;; Get selection set of the Title Block
    ;;
    (setq A1 nil)
    (setq A1 (ssget "X")); Select All Entities..Blocks
    (setq C 0 SITE "" TITLE1 "" TITLE2 "" TITLE3 "" TITLE4 "" TITLE5 ""); init
    ;;
    (setq B 0); Set B Len to 0 for init
    (if (/= A1 nil); If A1 (selection set) is nil, do nothing.
    (setq B (sslength A1)); check number of members in 'A1' selection set.
    (setq B 0); else, set length to zero.
    ); end if
    ;;
    ;; A = selection set of entities
    ;; B = sslength of A
    ;; C = Counter for number of entities found
    ;;
    (if (> B 0)
    (progn
    (repeat B
    (setq D (entget (ssname ss C)))
    (if (and
    (= "INSERT" (cdr (assoc 0 D))); case of BLOCKS
    (/= (cdr (assoc 66 D)) nil)); with Attrib's following
    (progn
    (setq en (entget (entnext (dxf -1 D))))
    (if (/= en nil)
    (progn
    (setq G nil)
    (setq G (cdr (assoc 0 en)))
    (while (/= "SEQEND" (cdr (assoc 0 en)))
    (setq ex (entget (entnext (dxf -1 en))))
    (setq G nil)
    (setq G (cdr (assoc 0 ex)))
    (if (= "ATTRIB" G); case of attributes
    (progn
    (setq tag_name (strcase (cdr (assoc 2 en))))
    (setq val (cdr (assoc 1 en))); get Attr Value
    (if (= tag_name "SITE")(setq SITE val)); Site
    (if (= tag_name "TITLE1")(setq TITLE1 val))
    (if (= tag_name "TITLE2")(setq TITLE2 val))
    (if (= tag_name "TITLE3")(setq TITLE3 val))
    (if (= tag_name "TITLE4")(setq TITLE4 val))
    (if (= tag_name "TITLE5")(setq TITLE5 val))
    ); end progn
    ); end if
    (setq en ex); swap next entity
    ); end while
    ); end progn
    ); end if
    ); end progn
    ); end if
    (setq C (+ C 1) D nil); entity counter
    ); end repeat
    ); end progn
    ); end if
    ;;
    ;; IF the SITE value /= "" then add all as long string..
    ;;
    (if (= SITE "")
    (progn
    (prompt "\n "); blank line feed..
    (prompt "\nCould not locate TAGNAME - [SITE] in This Drawing..")
    ); end progn
    ); end if
    ;;
    (if (/= SITE "")
    (progn
    (setq Str (strcat SITE " - " TITLE1 " - " TITLE2 " - " TITLE3 " - " TITLE4 " - " TITLE5))

    ; Do something with the string here..
    ; e.g. (command "_text" "1,0" "0.125" "0" Str); or such..

    ); end progn
    ); end if
    (princ)
    -----------------
    ;; By Bob Shaw, Control Systems & Services, Inc (http://www.bobscadshop.com)
    ;; E-Mail:
    ;;
    Cheers,
    Bob
     
    ECCAD, Feb 20, 2004
    #9
  10. Brockster

    Brockster Guest

    Wow, now, that's impressive. At a glance, it look like the pieces are there that I'm looking for. I'm about to leave the office, so I'll try it on Monday and get back to you. Thanks so much!!
     
    Brockster, Feb 20, 2004
    #10
  11. Brockster

    ECCAD Guest

    Brockster,
    I'll be unavailable Monday, Tuesday, back Wed.
    Bob
     
    ECCAD, Feb 20, 2004
    #11
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.