#Nested Block Access
8 messages in this thread
I am trying to access Nested block information. For example if I have
a block named TEMP and within that block is another block named TEMP1 with
attributes in it, how would I access the entget information in
those attributes. I am aware of nentsel, but that is based on user
selection. I want to access the information from ssget. Is there any
way to do this ? If anyone knows please let me know.
Thanks !
Cynthia – I'll assume that when you say "I have a block named TEMP and within
that block is another block named TEMP1", means that the block TEMP contains
an INSERTION of the block TEMP1.
Be that the case, you can access the defining entities of any block, using the
(tblsearch) function. This function returns a list similar to that returned by
the (entget) function. The -2 group in this list, is the entity name of the
first defining entity in the block (unless the block has no defining entities,
in which case, the -2 group will contain the entity name of the ENDBLK entity).
You can then use (entnext) and (entget) to examine the defining entities in a
block, once you've obtained the entity name of the first entity from the block
table entry's -2 group. If you apply this to your TEMP block, then you will
find the insertion and attributes of the TEMP1 block, in the defining entities
of TEMP.
For example:
(setq block_data (tblsearch "block" "TEMP"))
(setq ent (cdr (assoc -2 block_data)))
(while ent
(setq edata (entget ent))
(if (and (eq (cdr (assoc 0 edata)) "INSERT")
(eq (cdr (assoc 2 edata)) "TEMP1")
)
(princ "\nFound an insertion of TEMP1")
)
(setq ent (entnext ent))
)
-TonyT.
Hi Cynthia. The simplest way (although probably not the most efficient) is
to pass the main insert entity name to the (tblsearch) command and then
(entnext) through its subentities until you get to the nested block, then
repeat the (tblsearch) on it as needed. I think that this process will work
indefinitely — the only part I'm unsure about is that when you use the
block definition it is essentially a relative reference, that depends on
the insertion point and insertion layer for certain group results. I
haven't experimented with it yet… I'll see if I have a routine for
stepping through nested entities and pop it into a message to you. Perhaps
some of our Adesk buddies could give us a hint. <g>
Brian Boatright
Brian – The "main insert entity name" isn't what she needs to pass to the
(tblsearch) function. (Tblsearch) wants the NAME of the block.
To transform coordinates from model to world space in nested blocks, is a
bit tricky, and requires the composite model-to-world transformation matrix
that is currently only available by calling (NENTSEL). I've been requesting
that this matrix be accessable without requiring user interaction, but I don't
know what the status of that is.
-TonyT.
Tony,
Yes, now that you mention it, I realize my error. There's a little
confusion over the word "name". What you are saying is that it wants the 2
group, *not* the -1 group.
As to the matrix, I thought (not very deeply) that the (trans) function
could translate from MCS to WCS… or was that ECS to WCS… ?! Just what
IS the difference between MCS and ECS?
Brian
Brian – The "MCS" or Model Coordinate System is the coordinate system that a
block's defining entities are expressed in. So, if you have a circle with a
center at 2,2 in a block definition, that coordinate is in MCS coordinates, and
it is translated to WCS coordinates by applying the transformation matrix that
describes the rotation and translation that must be applied to the MCS coord's,
to compute the WCS coordinates. The WCS is the world coordinate system.
The (trans) function doesn't convert from MCS->WCS, but can be used to convert
from WCS to MCS coordinates, by first converting to the ECS of a block insert-
ion, and then scaling the coordinates by the recipricol of the insertion scale
factor(s).
-TonyT.
Ah ha! I knew that… just didn't know it was called the MCS! <g> So, as I
now understand it, the MCS -> WCS Matrix does the following:
1. Translate all points relative to the insertion point.
2. Rotate all points polar to the insertion point.
3. Scale all points relative to the scale factors.
Does this about sum it up? Seems that if I could find my matrix book, one
could figure out a matrix calculation that would achieve this. I *did* have
a book on 3d matrices that dealt with translation formulas….
Brian (Hmmm…. <gears turning>)
Thankyou gentlemen for all of the advice !, I will let you know how
it all works out. I am basically trying to create a quality assurance
checklist for the AutoCAD database. We have existing AutoCAD standards for
our company and I am trying to create a routine to
generate a quality exceptions report on each drawing database. If
you are aware of any tools to make this kind of a job easier, I would
appreciate it if you would let me know.
Thanks
C.