Results 1 to 5 of 5

Thread: Getting subentity data from entity. . .

  1. #1
    I could stop if I wanted to
    Join Date
    2009-04
    Location
    Houston, TX
    Posts
    204
    Login to Give a bone
    0

    Question Getting subentity data from entity. . .

    I have a block which consists of a circle with a single letter inside, and 2 attributes. I need to get the data for the circle, but I stepped through the entity using entnext, and I see the attributes come up, but no info on the circle before I get back to the block itself. . .

    I read somewhere stepping through should give you info on ALL subentities. I would just use nentsel, but the routine starts by asking me to select 2 blocks, and if I have to go select the blocks again I might as well just do the whole operation manually.

    Any help on how to automatically get the data for the circle subentity from the block would be appreciated.

    Also, before I go to this issue, when I ran the following code, I was getting bad argument errors. I'm sure I am using WAY too many variables, I first tried running it without (RQX1 TQY1 LQX1 BQY1 RQX2 TQY2 LQX2 BQY2) and I got an error, so I thought maybe I would have to get the X and Y coordinate seperately then just stick that variable in the list XYZ to make it work. Not sure what's going on with it, still new to this and looking for a solution. .

    Code:
    ; Define the function (the program). 
    (defun c:WIRE ( / ENT1 ENT2 INFO1 INFO2 SUB1 SUB2 RAD1 RAD2 RQX1 TQY1 LQX1 BQY1 RQX2 TQY2 LQX2 BQY2 RQ1 TQ1 LQ1 BQ1 RQ2 TQ2 LQ2 BQ2 OLDCE *error*)
      ; Save the current value of cmdecho then redefine it. 
      (setq OLDCE (getvar "cmdecho"))
      (setvar "cmdecho" 1)
      (defun *error* (errmes)
        (princ (strcat "\nExecution of WIRE halted by the following error: " ERRMES))
        (setvar "cmdecho" OLDCE)
        (setq *error* OLDERR)
        (prin1)
      )
    
      ; GET a ENTITY from the user and store it in ENT1. 
      (setq ENT1 (car (entsel "\nSelect the first block. ")))
    
      ; GET a ENTITY from the user and store it in ENT2. 
      (setq ENT2 (car (entsel "\nSelect the last block. ")))
    
      ; EXTRACT the Insertion point from the entity ENT1 and store it in INFO1.
      (setq INFO1 (cdr (assoc 10 (entget ENT1)))) 
    
      ; EXTRACT the Insertion point from the entity ENT2 and store it in INFO2.
      (setq INFO2 (cdr (assoc 10 (entget ENT2))))
    
      ; GET the SUBENTITY of ENT1 and store it in SUB1.  (At a loss for what code I need to do this).
      (setq SUB1 (nentsel (ENT1)))
    
      ; GET the SUBENTITY of ENT2 and store it in SUB2.  (At a loss for what code I need to do this).
      (setq SUB2 (nentsel (ENT2)))
    
      ; GET the Radius of the first SUBENTITY and store it in RAD1.
      (setq RAD1 (cdr (assoc 40 (entget SUB1))))
    
      ; GET the Radius of the last SUBENTITY and store it in RAD2.
      (setq RAD2 (cdr (assoc 40 (entget SUB2))))
    
      ; CALCULATE the X coordinate for RQ1 and store it in RQX1.
      (setq RQX1 (+ (nth 0 INFO1) RAD1))
    
      ; CALCULATE the Y coordinate for TQ1 and store it in TQY1.
      (setq TQY1 (+ (nth 1 INFO1) RAD1))
    
      ; CALCULATE the X coordinate for LQ1 and store it in LQX1.
      (setq LQX1 (- (nth 0 INFO1) RAD1))
    
      ; CALCULATE the Y coordinate for BQ1 and store it in BQY1.
      (setq BQY1 (- (nth 1 INFO1) RAD1))
    
      ; CALCULATE the X coordinate for RQ2 and store it in RQX2.
      (setq RQX2 (+ (nth 0 INFO2) RAD2))
    
      ; CALCULATE the Y coordinate for TQ2 and store it in TQY2.
      (setq TQY2 (+ (nth 1 INFO2) RAD2))
    
      ; CALCULATE the X coordinate for LQ2 and store it in LQX2.
      (setq LQX2 (- (nth 0 INFO2) RAD2))
    
      ; CALCULATE the Y coordinate for BQ2 and store it in BQY2.
      (setq BQY2 (- (nth 1 INFO2) RAD2))    
    
      ; GET the RIGHT QUADRANT of the first entity and store it in RQ1.
      (setq RQ1 (list (RQX1) (nth 1 INFO1) 0.0))
    
      ; GET the TOP QUADRANT of the first entity and store it in TQ1.
      (setq TQ1 (list (nth 0 INFO1) (TQY1) 0.0))
    
      ; GET the LEFT QUADRANT of the first entity and store it in LQ1.
      (setq LQ1 (list (LQX1) (NTH 1 INFO1) 0.0))
    
      ; GET the BOTTOM QUADRANT of the first entity and store it in BQ1.
      (setq BQ1 (list (nth 0 INFO1) (BQY1) 0.0))
    
      ; GET the RIGHT QUADRANT of the last entity and store it in RQ2.
      (setq RQ2 (list (RQX2) (nth 1 INFO2) 0.0))
    
      ; GET the TOP QUADRANT of the last entity and store it in TQ2.
      (setq TQ2 (list (nth 0 INFO2) (TQY2) 0.0))
    
      ; GET the LEFT QUADRANT of the last entity and store it in LQ2.
      (setq LQ2 (list (LQX2) (NTH 1 INFO2) 0.0))
    
      ; GET the BOTTOM QUADRANT of the last entity and store it in BQ2.
      (setq BQ2 (list (nth 0 INFO2) (BQY2) 0.0))
    
      ; Reset "cmdecho" to previous value. 
      (setvar "cmdecho" OLDCE)
      ; Exit quietly (no return value.)
      (prin1)
    )
    Last edited by Opie; 2009-06-05 at 06:04 PM. Reason: [code] tags added

  2. #2
    Administrator rkmcswain's Avatar
    Join Date
    2004-09
    Location
    Earth
    Posts
    9,804
    Login to Give a bone
    0

    Default Re: Getting subentity data from entity. . .

    If I understand you right, you just want to view properties of block components.

    You need to iterate the block definition. Here is one way:

    Code:
    
    (setq a (tblobjname "BLOCK" "MYBLOCK"))
    (while a
      (if (setq a (entnext a))
        (progn
          (princ "\n Entity = ")
          (princ (cdr (assoc 0 (entget a))))
        ) 
      )
    )
    ;;;
    ;;; returns something like this
    ;;; Entity = CIRCLE
    ;;; Entity = TEXT
    ;;; Entity = ATTDEF
    ;;; Entity = ATTDEF
    ;;;
    
    R.K. McSwain | CAD Panacea |

  3. #3
    I could stop if I wanted to
    Join Date
    2009-04
    Location
    Houston, TX
    Posts
    204
    Login to Give a bone
    0

    Default Re: Getting subentity data from entity. . .

    Take a look at the block I uploaded.

    Suppose you have two of them, have already seleted them both via entsel. Now you want to get the subentity data for the circle, without having to use nentsel. What's the code going to look like. I would think you could just use nentsel and just supply the variable name you assigned to both of the blocks when you selected them the first time. .
    Attached Files Attached Files

  4. #4
    Certifiable AUGI Addict
    Join Date
    2015-11
    Location
    Jo'burg SA
    Posts
    4,512
    Login to Give a bone
    0

    Default Re: Getting subentity data from entity. . .

    OK, considering that both "blocks" are inserts of the same block. I.e. they're block references (or in DXF "INSERT" types, or in ActiveX AcDbBlockReference) you can obtain the internal elements using the old AutoLisp methods (as per RK's code) or the newer VisualLisp code with the ActiveX vla/vlax functions. But to show this clearly, lets expand on RK's code. 1st you need to obtain the block's name so you can get hold of the block definition:
    Code:
    (setq en (entsel)) ;Get a block's ename through entsel
    (setq ed (entget (car en))) ; Get DXF data of en
    (if (= (cdr (assoc 0 ed)) "INSERT") ;Check if it's an inserted block reference
      (progn
        (setq blkname (cdr (assoc 2 ed))) ;Get the block's name from the Insert's DXF data
        (setq bn (tblobjname "BLOCK" blkname)) ;Get the ename of the Block Definition
        ;; Continue with RK's code from here (entnext bn) gives the 1st entity contained inside the block
      )
      (prompt "\nThis is not a block reference ... nothing to do.")
    )
    Notice that if you do this again on another insert of the block, the same block definition is given & the stepping through the block's def will give you the same entities again. There is actually only one circle entity, even though you may bave 1000's of this same block inserted all over the DWG, there's still only one circle inside the block. Thus its data will also always be the same.

    Now noticing the block you've uploaded. There's also some ATTDEF entities. This is an exception to the above method. An ATTDEF entity is an attribute definition, which while part of a block definition will not be the same thing as displayed by an insert of that block. When a block (with attdefs) is inserted, some extra entities with (cdr (assoc 0 ed)) of "ATTRIB" follows the blockref (or "INSERT"). So here, you can simply get the ATTRIB entities using entnext after the block reference (INSERT).

  5. #5
    Administrator rkmcswain's Avatar
    Join Date
    2004-09
    Location
    Earth
    Posts
    9,804
    Login to Give a bone
    0

    Default Re: Getting subentity data from entity. . .

    Thanks for the expanded explanation...
    R.K. McSwain | CAD Panacea |

Similar Threads

  1. CP34-1: Extended Entity Data
    By Autodesk University in forum Customization and Programming
    Replies: 0
    Last Post: 2013-03-30, 02:11 AM
  2. Save structured data in an entity
    By jason907238 in forum Dot Net API
    Replies: 19
    Last Post: 2012-08-29, 07:06 PM
  3. Replies: 0
    Last Post: 2009-04-15, 02:42 PM
  4. Object data from entity to FDO Feature data property
    By vlee in forum AutoCAD Map 3D - Data Connect (FDO)
    Replies: 3
    Last Post: 2009-04-09, 04:59 PM
  5. Three programs using EXTENDED ENTITY DATA
    By aaronic_abacus in forum AutoLISP
    Replies: 1
    Last Post: 2007-01-02, 01:13 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
  •