Results 1 to 7 of 7

Thread: Selecting blocks in xrefed drawing

  1. #1
    Member
    Join Date
    2008-06
    Posts
    16
    Login to Give a bone
    0

    Default Selecting blocks in xrefed drawing

    I'm using the following line to get the layer name of an object that is in a xrefed drawing:

    (setq layertochange (cdr (assoc 8 (entget (car (nentsel "Select item on Layer to Change Layer Color:
    "))))))

    It works fine for basic objects in the xrefed drawing, but if the object happens to be a block, I want it to return the layer name that the block is on. It returns the layer name of the object that is inside the block. How can I modify it to get the layer name that the block is on??

    Thanks:
    Steve

  2. #2
    AUGI Addict
    Join Date
    2005-08
    Posts
    1,043
    Login to Give a bone
    0

    Default Re: Selecting blocks in xrefed drawing

    This should give you what you want.

    Code:
    (defun c:NList (/ Sel EntList Data tempType NListString LayName tempLw tempClr)
        
        (setq NListString "")
        (if (setq Sel (nentsel "\n Select object to list properties of it, and of partent entities if nested: "))
            (progn
                (if (> (length Sel) 2)
                    (setq EntList (append (list (car Sel)) (last Sel)))
                    (setq EntList (list (car Sel)))
                )
                (foreach ent EntList
                    (if (equal (type ent) 'ENAME)
                        (progn
                            (setq Data (entget Ent))
                            (setq NListString
                                (strcat
                                    NListString
                                    "\n Entity type: "
                                    (setq tempType (cdr (assoc 0 Data)))
                                    (cond
                                        (
                                            (and
                                                (= tempType "INSERT")
                                                (/=
                                                    (cdr
                                                        (assoc
                                                            1
                                                            (entget
                                                                (tblobjname
                                                                    "block"
                                                                    (cdr
                                                                        (assoc 2 Data)
                                                                    )
                                                                )
                                                            )
                                                        )
                                                    )
                                                    ""
                                                )
                                            )
                                            (strcat
                                                " [ Xref - "
                                                (cdr (assoc 2 Data))
                                                " ]"
                                            )
                                        )
                                        ((= tempType "INSERT")
                                            (strcat 
                                                " [ "
                                                (cdr (assoc 2 Data))
                                                " ]"
                                            )
                                        )
                                        (T "")
                                    )
                                    "\n    Layer: "
                                    (setq LayName (cdr (assoc 8 Data)))
                                    "\n    Linetype: "
                                    (if (assoc 6 Data)
                                        (cdr (assoc 6 Data))
                                        (strcat
                                            "ByLayer [ "
                                            (cdr
                                                (assoc
                                                    6
                                                    (entget
                                                        (tblobjname "layer" LayName)
                                                    )
                                                )
                                            )
                                            " ]"
                                        )
                                    )
                                    "\n    Color: "
                                    (if (assoc 62 Data)
                                        (if (equal (setq tempClr (cdr (assoc 62 Data))) 0)
                                            "ByBlock"
                                            (itoa tempClr)
                                        )
                                        (strcat
                                            "ByLayer [ "
                                            (itoa
                                                (cdr
                                                    (assoc
                                                        62
                                                        (entget
                                                            (tblobjname "layer" LayName)
                                                        )
                                                    )
                                                )
                                            )
                                            " ]"
                                        )
                                    )
                                    "\n    Lineweight: "
                                    (if (assoc 370 Data)
                                        (progn
                                            (setq tempLw (cdr (assoc 370 Data)))
                                            (cond
                                                ((equal tempLw -3)
                                                    "Default"
                                                )
                                                ((equal tempLw -2)
                                                    "ByBlock"
                                                )
                                                (t
                                                    (strcat (rtos (/ tempLw 100.) 2 2) " mm")
                                                )
                                            )
                                        )
                                        (progn
                                            (setq tempLw
                                                (cdr
                                                    (assoc
                                                        370
                                                        (entget
                                                            (tblobjname "layer" LayName)
                                                        )
                                                    )
                                                )
                                            )
                                            (strcat
                                                "ByLayer [ "
                                                (if (equal tempLw -3)
                                                    "Default"
                                                    (strcat (rtos (/ tempLw 100.) 2 2) " mm")
                                                )
                                                " ]"
                                            )
                                        )
                                    )
                                    "\n"
                                )
                            )
                        )
                    )
                )
                (alert NListString)
            )
        )
        (princ)
    )
    Attached Images Attached Images

  3. #3
    Member
    Join Date
    2008-06
    Posts
    16
    Login to Give a bone
    0

    Default Re: Selecting blocks in xrefed drawing

    Thanks Tim. That does exactly what I asked for, and I will use that for a "object inspect" routine.

    But another idea was to have a LISP program that changed the color of the layer the block is on. For example, the architects insert a door block on an xrefed base plan. I want to change the door color from red to something else, like maybe grey.

    Is there a key line or codeword that returns the block layer instead of the object layer? (I try, but I'm very much a novice at AutoLisp.)

    Thanks:
    Steve

  4. #4
    AUGI Addict
    Join Date
    2005-08
    Posts
    1,043
    Login to Give a bone
    0

    Default Re: Selecting blocks in xrefed drawing

    When you use ' nentsel ' what is returned looks like
    Code:
    <Entity name: 7e841570>
    (1422.12 1506.24 0.0)
    ((-96.0 1.17562e-014 0.0) (-1.17562e-014 -96.0 0.0) (0.0 0.0 96.0) (1420.7 
    1493.0 0.0))
    (<Entity name: 7e832490> <Entity name: 7edbace0>)
    This first is the lowest entity. The last ( if selected a nested entity ) will be a list of the nested path to said entity. So in this case the entity is nested within two entities. So if you want the line, you will get the ' car ' of the list returned by ' nenetsel '. If you want to know which block that line is from, then you will take the ' car (last ' of the list that is returned.

    Hope that makes sense, and steers you in the right direction.

  5. #5
    Member
    Join Date
    2008-06
    Posts
    16
    Login to Give a bone
    0

    Default Re: Selecting blocks in xrefed drawing

    Yes, that makes sense. I tried adding the "last" command in my code:

    (setq layertochange (cdr (assoc 8 (entget (car (last (nentsel "Select item to find its layer:
    ")))))))

    It works just like I wanted.

    Now I just have to figure out how to make it work for either a block or a simple object liike a line. It looks like the (if (> (length Sel) 2)....) can be modified to tell me if a block or a line was selected.

    Thanks:
    Steve

  6. #6
    AUGI Addict
    Join Date
    2005-08
    Posts
    1,043
    Login to Give a bone
    0

    Default Re: Selecting blocks in xrefed drawing

    Quote Originally Posted by sragan View Post
    Yes, that makes sense. I tried adding the "last" command in my code:

    (setq layertochange (cdr (assoc 8 (entget (car (last (nentsel "Select item to find its layer:
    ")))))))

    It works just like I wanted.
    Good to hear.

    Quote Originally Posted by sragan View Post
    Now I just have to figure out how to make it work for either a block or a simple object liike a line. It looks like the (if (> (length Sel) 2)....) can be modified to tell me if a block or a line was selected.
    More correct would be to say that is lets you know if you select a nested item or not. The only gotcha ( I know of ) is with attributes. It will return a list of two items, since attributes are their own objects, but are still associated with blocks. Just something to watch out for.

    Quote Originally Posted by sragan View Post
    Thanks:
    Steve
    You're welcome.

  7. #7
    Member
    Join Date
    2008-06
    Posts
    16
    Login to Give a bone
    0

    Default Re: Selecting blocks in xrefed drawing

    Yes, that makes sense. I tried adding the "last" command in my code:

    (setq layertochange (cdr (assoc 8 (entget (car (last (nentsel "Select item to find its layer:
    ")))))))

    It works just like I wanted.

    Now I just have to figure out how to make it work for either a block or a simple object liike a line. It looks like the (if (> (length Sel) 2)....) can be modified to tell me if a block or a line was selected.

    Thanks:
    Steve

Similar Threads

  1. Replies: 4
    Last Post: 2013-11-26, 02:43 PM
  2. Replies: 1
    Last Post: 2012-06-06, 12:29 AM
  3. Field XREFed into a drawing to update according to SSM properties
    By autocad.wishlist1734 in forum AutoCAD Wish List
    Replies: 0
    Last Post: 2009-02-01, 06:40 PM
  4. Selecting Xlines within blocks.
    By Peter Sedlacek in forum AutoCAD General
    Replies: 5
    Last Post: 2007-05-18, 06:55 AM
  5. Selecting OSnaps on Blocks
    By spencer.67965 in forum AutoCAD General
    Replies: 3
    Last Post: 2006-01-09, 08:10 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •