LISP - how to recognize deep entities

Discussion in 'AutoCAD' started by Franz@@@architettura, Nov 27, 2006.

  1. how i can understand the name of the attribute of a block in AutoCad?
    i need to change the value of an attribute in a block by a lisp and in my
    block there are many attributes. how can i identify the one i need?
    entget is not enough.
    thanks

    franz
     
    Franz@@@architettura, Nov 27, 2006
    #1
  2. Franz@@@architettura

    per.corell Guest

    Hi

    Entget only return the entity list ,within that there are several group
    lists holding various information . What you need to do is to find the
    functions that will check if some information are a "member of any of
    these lists and if they are, your function must return these and
    proberly the block entity name . ----- in Lisp you write somthing like
    ; is "what you are looking for" member of any of the lists in the
    blocks entsel find , yield these blocks entity name and put them in a
    list. ------ then use entsel to pick them one by one.
     
    per.corell, Nov 27, 2006
    #2
  3. I have a routine on my website called attcopy that copies attributes from
    one block to another, if the attributes have the same tag. All the code you
    need for what you want to do should be in there.
     
    Michael Bulatovich, Nov 27, 2006
    #3
  4. thank a lot for your answers
    for mr Michael:
    you're an architect like me and probably you've face a stupid problem like
    mine: i've a block in which attributes are peculiarities of the rooms in
    which is placed like identification of the building, of the floor and
    obviously the room. Each time i change my layout i must edit the block
    attribute to reorder the room number. I'm just looking for a lisp able to
    put an incremental number in the right attribute's place.


    thank for any help

    Francesco Panzeri
     
    Franz@@@architettura, Nov 27, 2006
    #4
  5. Franz@@@architettura

    Mr. B Guest

    Here's a Lisp routine I wrote which exchanges two different symbols with 12
    Attributes in each of them. You should be able to get what you want out of
    this if you are somewhat familiar with LISP.

    WHATCH OUT for word wrapping:



    ;; Xchnages Existing Block with New Block with
    ;; 12 attributes - Retains Attributes Text

    (defun dxf (code elist1)
    (cdr (assoc code elist1))
    );dxf

    ; **********************
    ; *** PROGRAM START ****
    ; **********************
    (defun C:XAT12 ( / exAtTxt1a exAtTxt1b exAtTxt1c exAtTxt1d exAtTxt1e exAtTxt1f
    exAtTxt1g exAtTxt1h)
    (setvar "cmdecho" 1)
    (setq curlyr (getvar "clayer")) ; get current layer

    ; Symbol size IF selected from Block Folder
    (setq figscl (getvar "UserR1")) ; find Figure Scale factor
    (setq figscI (getvar "UserI1")) ; find Figure Scale factor
    (setq Inmm (getvar "USerI1")) ; find if Inches 1 or MM 0
    (if (= Inmm 1) (setq figscal (/ figscl 25.4)))
    (if (= Inmm 0) (setq figscal figscl))


    ; Select NEW Symbol
    ; *****************
    ; (princ "\n--> Use a WINDOW selection to Pick the NEW Symbol!! <--")
    (princ "\nChoose one -NEW- Symbol: ")
    (setq AttPick1 (ssget (list (cons 0 "insert"))))

    (setq ename (ssname AttPick1 0))
    (setq elist1 (entget ename))
    (setq newAttnam1 nil)
    (setq newAttscl1 nil)
    (setq newAttsym1 (dxf 2 elist1)) ;block name

    ; Select Symbols to Change
    ; ************************
    ; Loop
    (while (<= test 100)

    (princ "\nChoose one -EXISTING- Symbol to change: ")
    (setq exPick1a (ssget (list (cons 0 "insert"))))

    (setq ename (ssname exPick1a 0))
    (setq elist1 (entget ename))
    ;get Attribute Text
    (setq exAtTxt1a (cdr (assoc 1 elist1))) ;set Attribute Text
    #1
    (setq exAtt1a (dxf 2 elist1)) ;block name
    (setq exSymscl1a (dxf 41 elist1)) ;block scale
    (setq exInspt1a (dxf 10 elist1)) ;block insertion
    point
    (setq exRotan1a (angtos (dxf 50 elist1))) ;block rotation
    angle
    (setq exLyrnam1a (dxf 8 elist1)) ;block layer

    (command "layer" "s" Exlyrnam1a "") ;set working layer -
    temp

    (setq elist1 (entnext (dxf -1 elist1)))
    (setq elist1 (entget elist1))
    (/= "SEQEND" (dxf 0 elist1))

    ; Find Attribute Text IF it exists
    (if (= "ATTRIB" (dxf 0 elist1))
    (setq exAtTxt1a (cdr (assoc 1 elist1))) ;set Attribute Text
    #1
    );if

    ; Get Attribute Text #2
    (setq elist2 (entget (entnext (entnext ename))))
    (setq exAtTxt1b (cdr (assoc 1 elist2))) ;set Attribute Text
    #2

    ; Get Attribute Text #3
    (setq elist2 (entget (entnext (entnext (entnext ename)))))
    (setq exAtTxt1c (cdr (assoc 1 elist2))) ;set Attribute Text
    #3

    ; Get Attribute Text #4
    (setq elist2 (entget (entnext (entnext (entnext (entnext ename))))))
    (setq exAtTxt1d (cdr (assoc 1 elist2))) ;set Attribute Text
    #4

    ; Get Attribute Text #5
    (setq elist2 (entget (entnext (entnext (entnext (entnext (entnext
    ename)))))))
    (setq exAtTxt1e (cdr (assoc 1 elist2))) ;set Attribute Text
    #5

    ; Get Attribute Text #6
    (setq elist2 (entget (entnext (entnext (entnext (entnext (entnext (entnext
    ename))))))))
    (setq exAtTxt1f (cdr (assoc 1 elist2))) ;set Attribute Text
    #6

    ; Get Attribute Text #7
    (setq elist2 (entget (entnext (entnext (entnext (entnext (entnext (entnext
    (entnext ename)))))))))
    (setq exAtTxt1g (cdr (assoc 1 elist2))) ;set Attribute Text
    #7

    ; Get Attribute Text #8
    (setq elist2 (entget (entnext (entnext (entnext (entnext (entnext (entnext
    (entnext (entnext ename))))))))))
    (setq exAtTxt1h (cdr (assoc 1 elist2))) ;set Attribute Text
    #8

    ; Get Attribute Text #9
    (setq elist2 (entget (entnext (entnext (entnext (entnext (entnext (entnext
    (entnext (entnext (entnext ename)))))))))))
    (setq exAtTxt1h (cdr (assoc 1 elist2))) ;set Attribute Text
    #9

    ; Get Attribute Text #10
    (setq elist2 (entget (entnext (entnext (entnext (entnext (entnext (entnext
    (entnext (entnext (entnext (entnext ename))))))))))))
    (setq exAtTxt1h (cdr (assoc 1 elist2))) ;set Attribute Text
    #10

    ; Get Attribute Text #11
    (setq elist2 (entget (entnext (entnext (entnext (entnext (entnext (entnext
    (entnext (entnext (entnext (entnext (entnext ename)))))))))))))
    (setq exAtTxt1h (cdr (assoc 1 elist2))) ;set Attribute Text
    #11

    ; Get Attribute Text #12
    (setq elist2 (entget (entnext (entnext (entnext (entnext (entnext (entnext
    (entnext (entnext (entnext (entnext (entnext (entnext ename))))))))))))))
    (setq exAtTxt1h (cdr (assoc 1 elist2))) ;set Attribute Text
    #12

    ; Delete Existing Symbol
    (command "erase" exPick1a "")

    ; Insert New Symbol
    (command "-insert" newAttsym1 exInspt1a exSymscl1a "" exRotan1a exAtTxt1a
    exAtTxt1b exAtTxt1c
    exAtTxt1d exAtTxt1e
    exAtTxt1f exAtTxt1g exAtTxt1h)

    ) ; while

    ; *** END ***
    (setvar "clayer" curlyr) ;reset working layer
    (princ)(terpri)
    ) ;end Defun
     
    Mr. B, Nov 27, 2006
    #5
  6. I've got another one on my site that will generate attribute sequences for
    multiple block insertions.
    It can give you a fixed prefix or suffix, can start form any number, and
    increment by any number...
    However it only works with blocks containing a single attribute, but you are
    free to modify it to suit yourself.

    It's named BSEQ.LSP
     
    Michael Bulatovich, Nov 27, 2006
    #6
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.