Jump to content

Recommended Posts

Posted

Hi Guys,

 

Hope you are all enjoying this new year :)

 

Just a short question, but how can one tell the difference between an XRef and Block when retrieveing such entities using the entsel function?

 

Both appear as "INSERT" entities....

Posted

Check the group 70 dxf flag of the block definition (not the INSERT entity).

Posted

here's one way also, only xrefs have paths,

 

(defun c:test (/ blk s)
  (setq blk (tblnext "BLOCK" t))
  (while blk
     (if (assoc 1 blk)            ;Check if XRef Path Exists
    (setq blk_list (strcat blk_list (cdr (assoc 1 blk)) "\n"))
     ) ;_ end_if
     (setq blk (tblnext "BLOCK"))
  ) ;_ end_while
  (alert blk_list)
  (princ)
) ;_ end_defun

Posted

Excellent - Thanks for your replies, much appreciated.

 

Wizman, I like your method, but the tblnext definition doesn't contain a dxf group 1, so the string returns nil...or it could be because the strcat is trying to string together something that is nil.

 

rkmcswain - when looking at the group 70 dxf of the table definition - is it sufficient to say that if it is not nil, then it is an xref?

Posted

rkmcswain, would this work?

 

(defun c:test (/ blk xlist)
   (setq blk (tblnext "BLOCK" T))
   (setq xlist "XREFS: \n")
   (while blk
   (if (/= (cdr (assoc 70 blk)) nil)
       (setq xlist (strcat xlist (cdr (assoc 2 blk)) "\n"))
   ) ;_  end if
   (setq blk (tblnext "BLOCK"))
   ) ;_  end while
   (alert xlist)
   (princ)
) ;_  end defun


Posted

rkmcswain - when looking at the group 70 dxf of the table definition - is it sufficient to say that if it is not nil, then it is an xref?

 

No. Group 70 is a bit-coded value. Check for the bit code 4 in that group.

 

Example:

 

(defun is-xref (name)
 (if (eq 4 (logand 4 (cdr (assoc 70 (tblsearch "block" name)))))
   t
   nil
 )
)

Posted

Lee,

 

if you want to test it with an ENAME:

 

[b][color=BLACK]([/color][/b]defun is_ent_xref [b][color=FUCHSIA]([/color][/b]e[b][color=FUCHSIA])[/color][/b]
 [b][color=FUCHSIA]([/color][/b]and [b][color=NAVY]([/color][/b]= [b][color=MAROON]([/color][/b]type e[b][color=MAROON])[/color][/b] 'ENAME[b][color=NAVY])[/color][/b]
      [b][color=NAVY]([/color][/b]= [color=#2f4f4f]"INSERT"[/color] [b][color=MAROON]([/color][/b]cdr [b][color=GREEN]([/color][/b]assoc 0 [b][color=BLUE]([/color][/b]entget e[b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b]
      [b][color=NAVY]([/color][/b]=
        [b][color=MAROON]([/color][/b]logand
          [b][color=GREEN]([/color][/b]cdr
            [b][color=BLUE]([/color][/b]assoc 70
              [b][color=RED]([/color][/b]tblsearch [color=#2f4f4f]"BLOCK"[/color]
                [b][color=PURPLE]([/color][/b]cdr
                  [b][color=TEAL]([/color][/b]assoc 2
                    [b][color=OLIVE]([/color][/b]entget e[b][color=OLIVE])[/color][/b][b][color=TEAL])[/color][/b][b][color=PURPLE])[/color][/b][b][color=RED])[/color][/b][b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b]
                      4[b][color=MAROON])[/color][/b]
                       4[b][color=NAVY])[/color][/b]
                         [b][color=FUCHSIA])[/color][/b]
                          [b][color=BLACK])[/color][/b]

 

 

Returns T / nil

 

-David

Posted

Thanks for the info - I just don't quite understand the use of

 

"logand" (cdr of group 70) 4

 

I have read the ACAD help on "logand" and still don't understand what it is getting at?

 

you are comparing the group 70 code with 4? but comparing it how?

 

Thanks once again guys.

Posted
Thanks for the info - I just don't quite understand the use of

 

"logand" (cdr of group 70) 4

 

I have read the ACAD help on "logand" and still don't understand what it is getting at?

 

you are comparing the group 70 code with 4? but comparing it how?

 

Thanks once again guys.

 

Basically.... if you look up group 70 for BLOCKS, you will see that:

0 = no flags are set

1 = indicates an anonymous block

2 = block has non-constant attribute defs

4 = block is an xref

8 = block is an xref overlay

...and so on.

 

Notice the pattern there... 1, 2, 4, 8, 16, 32, 64, etc.

 

If the "4" bit is set (which indicates this is an xref), then the value of group 70 will be the sum of 4 plus whatever other values are set.

 

So if this is a plain block, the group 70 value may be 0.

If the block has attributes the group 70 value may be 2

If this is an xref overlay, then the group 70 value may be 12 (4 + 8).

 

What does LOGAND do and why does it work? Check this out, specifically the third post.

Posted

RKMcSwain, You are a legend! :)

 

Thanks loads for the explanation - I thought I'd never understand it after reading the ACAD help - but that link is brilliant for explaining things! :)

 

Thanks Loads Guys for all your replies and for taking the time out to help me - much appreciated as always :)

 

Cheers

 

Lee

Posted
RKMcSwain, You are a legend!
Not me... I figured it out one day just like everybody else... :-)

 

Thanks loads for the explanation - I thought I'd never understand it after reading the ACAD help - but that link is brilliant for explaining things!

 

This sort of logic applies in many other places. OSMODE, group 70 for polylines, group 90 for viewports, group 70 of all (I think) the various tables (like layers, styles, Ltype), etc.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...