See the top rated post in this thread. Click here

Results 1 to 9 of 9

Thread: need help with a LISP to get nested object ename from a block without UI

  1. #1
    Member
    Join Date
    2014-05
    Posts
    15
    Login to Give a bone
    0

    Default need help with a LISP to get nested object ename from a block without UI

    Hi All,

    I don't script often, so please forgive my ignorance.

    I need to obtain the ename from a "point" object within a specific block or block definition. But, I need to be able to do it without user input. The block is dynamic, so can't be exploded (which wouldn't help anyway, as the ename would change).

    I am able to identify the block, insert a new copy, and select it with either ssget "L", entlast. But, I haven't been able to step through the block with entnext in order to find my "point". I tried using nentselp to select the point. But, it keeps selecting a nested lwpolyline segment which has an endpoint sharing the same location. But, I can't use the lwpolyline for my purpose.

    The reason that I need the ename is that I use it to create an INSERT FIELD within all the remaining instances of that block which are already existing within the drawing. Making that info part of the block definition is insufficient, as copy/paste from other active drawings creates unique enames. Those unique enames do not always update within the INSERT FIELD between drawings. So, I am attempting to automate my manual process of normalizing the INSERT FIELD data to the current drawing's block definition.

    I'm attaching the "CONN.dwg" file, which has the nested point located at (-0.2,0.0).

    I don't need a full routine. But I would definitely appreciate any help in reliably isolating that point, so that I can plug that data into my LISP.

    Kindest Regards,

    Jesse
    Attached Files Attached Files

  2. #2
    Administrator Opie's Avatar
    Join Date
    2002-01
    Location
    jUSt Here (a lot)
    Posts
    9,105
    Login to Give a bone
    0

    Default Re: need help with a LISP to get nested object ename from a block without UI

    Could you insert the block into a carrier block, set your field as desired, save to file. And then explode the carrier block on insert?
    If you have a technical question, please find the appropriate forum and ask it there.
    You will get a quicker response from your fellow AUGI members than if you sent it to me via a PM or email.
    jUSt

  3. #3
    All AUGI, all the time
    Join Date
    2010-06
    Posts
    962
    Login to Give a bone
    1

    Default Re: need help with a LISP to get nested object ename from a block without UI

    Hi,

    With the following codes you can iterate your block object with entnext and the variable p would hold the entity name of the first point object that could be found in the selected block.

    Code:
    (if (and (setq s (car (entsel "\nPick a block :")))
             (= (cdr (assoc 0 (setq e (entget s)))) "INSERT")
             (setq o (tblobjname "BLOCK" (cdr (assoc 2 e))))
             )
      (while (and (not p) (setq o (entnext o)))
        (and (= (cdr (assoc 0 (entget o))) "POINT")
             (setq p o)
             )
        )
      )

  4. #4
    Member
    Join Date
    2014-05
    Posts
    15
    Login to Give a bone
    0

    Default Re: need help with a LISP to get nested object ename from a block without UI

    Hi Opie,

    I don't think so. This block is already inside of a carrier block, which updates other attributes through fields. And there are many copies of this block throughout any one drawing, which tie to other carrier blocks. Exploding those carrier blocks is what has caused the issue I am trying to correct.

    Thanks, though.

    - - - Updated - - -

    Thanks, Tharwat. I'll give this a shot and see what happens.

  5. #5
    Member
    Join Date
    2014-05
    Posts
    15
    Login to Give a bone
    0

    Default Re: need help with a LISP to get nested object ename from a block without UI

    Quote Originally Posted by Tharwat View Post
    Hi,

    With the following codes you can iterate your block object with entnext and the variable p would hold the entity name of the first point object that could be found in the selected block.

    Code:
    (if (and (setq s (car (entsel "\nPick a block :")))
             (= (cdr (assoc 0 (setq e (entget s)))) "INSERT")
             (setq o (tblobjname "BLOCK" (cdr (assoc 2 e))))
             )
      (while (and (not p) (setq o (entnext o)))
        (and (= (cdr (assoc 0 (entget o))) "POINT")
             (setq p o)
             )
        )
      )
    This is great! Thanks!

    It did throw an error through one of it's recursions. But, it still returned the entity name that I need. I can probably adjust the loop to address that.

    I will also test this on another block which has (2) points which need the same treatment. I'm sure it'll do the trick!

    Can't tell you how much I appreciate this!

  6. #6
    Member
    Join Date
    2014-05
    Posts
    15
    Login to Give a bone
    0

    Default Re: need help with a LISP to get nested object ename from a block without UI

    Quote Originally Posted by Opie View Post
    Could you insert the block into a carrier block, set your field as desired, save to file. And then explode the carrier block on insert?
    Hi Opie,

    I don't think so. This block is already inside of a carrier block, which updates other attributes through fields. And there are many copies of this block throughout any one drawing, which tie to other carrier blocks. Exploding those carrier blocks is what has caused the issue I am trying to correct.

    Thanks, though.

  7. #7
    All AUGI, all the time
    Join Date
    2010-06
    Posts
    962
    Login to Give a bone
    0

    Default Re: need help with a LISP to get nested object ename from a block without UI

    Quote Originally Posted by jessevas656864 View Post
    This is great! Thanks!

    Can't tell you how much I appreciate this!
    You're welcome.

    Quote Originally Posted by jessevas656864 View Post
    It did throw an error through one of it's recursions. But, it still returned the entity name that I need. I can probably adjust the loop to address that.
    Actually it should not throw any error at all unless you added any codes of yours to them or so.

    Quote Originally Posted by jessevas656864 View Post
    I will also test this on another block which has (2) points which need the same treatment. I'm sure it'll do the trick!
    The codes would stop on the first point object found as I declared in my first post but you can ask for any help if you stuck with any.

    Good luck.

  8. #8
    Member
    Join Date
    2014-05
    Posts
    15
    Login to Give a bone
    0

    Default Re: need help with a LISP to get nested object ename from a block without UI

    Quote Originally Posted by jessevas656864 View Post
    This is great! Thanks!

    It did throw an error through one of it's recursions. But, it still returned the entity name that I need. I can probably adjust the loop to address that.

    I will also test this on another block which has (2) points which need the same treatment. I'm sure it'll do the trick!

    Can't tell you how much I appreciate this!
    I can't find the button to format as code.

    Here is what I am using as my base (below). There are (9) block definitions in all which will be processed. Since one of them has (2) points, I will be making a list of (Point#,entity name); which I will then process into my INSERT FIELDS.

    (COMMAND "_.-INSERT" "CONN.DWG" "0,0" 1 0)
    (setq x 1)
    (if (and (setq blst0 (entlast))
    (= (cdr (assoc 0 (setq blst1 (entget blst0)))) "INSERT")
    (setq blst2 (tblobjname "BLOCK" (cdr (assoc 2 blst1))))
    );and
    (while (and (not (= blst2 nil)) (setq blst2 (entnext blst2)))
    (and (= (cdr (assoc 0 (entget blst2))) "POINT")
    (setq blst3 (append blst3 (list (list (cons (cdr (assoc 0 (entget blst2))) x) blst2))))
    (setq x (+ x 1))
    );and
    );while
    );if

  9. #9
    All AUGI, all the time
    Join Date
    2010-06
    Posts
    962
    Login to Give a bone
    0

    Default Re: need help with a LISP to get nested object ename from a block without UI

    Quote Originally Posted by jessevas656864 View Post
    I can't find the button to format as code.
    Hit the button 'Go Advanced' below on the right side hand then from the new page hit the hash tag # or you can type the following but without spaces as I do.
    [ c o d e ] YOUR CODES HERE [ / c o d e ]

    Code:
    (setq var (mapcar 'getvar '(ATTDIA ATTREQ)))
    (mapcar 'setvar '(ATTDIA ATTREQ) '(0 0))
    
    (if (tblsearch "BLOCK" "CONN")
        (setq blk (vlax-invoke (vlax-get (vla-get-activelayout (vla-get-activedocument (vlax-get-acad-object))) 'Block)
                    'insertblock '(0. 0. 0.) "CONN" 1. 1. 1. 0.)
              blst0 (vlax-vla-object->ename blk)
              )
        (and (or (setq dwg (findfile "CONN.dwg"))
                 (alert "Can't find drawing.")
                 )
             (or (setq old (entlast)) (setq old ""))
             (not (command "_.-INSERT" dwg "0,0" 1 0 ""))
             (and (not (eq old (setq new (entlast))))
                  (setq blst0 new))
             )
        )
    (mapcar 'setvar '(ATTDIA ATTREQ) var)
    
    
    (if (and blst0
             (= (cdr (assoc 0 (setq blst1 (entget blst0)))) "INSERT")
             (setq blst2 (tblobjname "BLOCK" (cdr (assoc 2 blst1))))
             )
      (while (and blst2 (not (= (cdr (assoc 0 (setq ent (entget blst2)))) "SEQEND")))
        (and (= (setq pnt (cdr (assoc 0 ent))) "POINT")
             (setq blst3 (cons (list pnt blst2) blst3)))
        (setq blst2 (entnext blst2))
        )
      )
    
    (vl-load-com)

Similar Threads

  1. Get vla-ObjectID or ename for table cell
    By deheylen690271 in forum AutoLISP
    Replies: 3
    Last Post: 2018-03-15, 11:29 PM
  2. Lisp to add an MText object that contains an object property
    By sheila.bjerreskov717262 in forum AutoLISP
    Replies: 7
    Last Post: 2013-07-22, 05:58 PM
  3. Select & entget object information in XREF and block-in-block with Lisp
    By Wish List System in forum AutoCAD Wish List
    Replies: 0
    Last Post: 2012-11-14, 09:11 AM
  4. ename issue
    By parkerfeldman in forum AutoLISP
    Replies: 1
    Last Post: 2009-08-21, 02:53 PM
  5. Replies: 7
    Last Post: 2006-04-19, 05:42 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
  •