Author Topic: Insertionpoint of complex object WITHOUT using nentsel  (Read 7284 times)

0 Members and 1 Guest are viewing this topic.

ArgV

  • Guest
Insertionpoint of complex object WITHOUT using nentsel
« on: December 06, 2009, 04:17:18 PM »
I am trying to get the data list of a block in the blocks collection, but it only gives me the basic info, and not the information I really want from it like the insertionPoint property or the rotation property.

Is there a reason why, and is there a way to get this info from a nested block without having to pick it on screen?

I'm trying to update a directory full of drawings with new blocks using objectDBX, so I'm limited to what I can do.

Heres the part I'm having problems with..
(getName is a sub-routine that checks for x-refs and anonymous or dynamic blocks)

Code: [Select]

(vlax-for block blocks
;; get it's name
(setq name (strcase (getName block)))
(if
   (and ;; the name does not have a "*" or is not model_space or paper_space
     (/= (substr name 1 1) "*")
     (not (wcmatch name "*SPACE*"))
     )
   
   ;; loop through the good list
   ;; if the block is in the badList, insert the good block in it's place

   (while (< cntr (length badList))
     (if
       (= (nth cntr badList) name)
       (progn

(setq blockItem (apply 'vla-item (list blocks name))

                           [b];;Arrrgh!! VLISP will not give the standard information on a block that is nested!
;;I want the insertion point and rotation of this block! [/b]

       insertionPoint (vla-get-insertionpoint blockItem);<- won't work
       rotation (vla-get-rotation blockItem));<-won't work
(vla-insertblock insertionPoint (nth cntr goodList) 1 1 1 rotation)
)
       )
     (setq cntr (1+ cntr))
     )
   )
(setq cntr 1)
)


Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Insertionpoint of complex object WITHOUT using nentsel
« Reply #1 on: December 06, 2009, 04:29:58 PM »
Use something like this:

Code: [Select]
(vlax-for obj (vla-item (vla-get-blocks (vla-get-ActiveDocument (vlax-get-acad-object))) "Block Name")
  (if (eq "AcDbBlockReference" (vla-get-objectname obj))
    (vla-get-insertionpoint obj)))

Hope this helps

ArgV

  • Guest
Re: Insertionpoint of complex object WITHOUT using nentsel
« Reply #2 on: December 07, 2009, 10:04:38 AM »
Use something like this:

Code: [Select]
(vlax-for obj (vla-item (vla-get-blocks (vla-get-ActiveDocument (vlax-get-acad-object))) "Block Name")
  (if (eq "AcDbBlockReference" (vla-get-objectname obj))
    (vla-get-insertionpoint obj)))

Hope this helps

I know this will get an insertionpoint of one of the blocks INSIDE of this main block, but can it get the insertionPoint of the larger block?

thank you much.

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Re: Insertionpoint of complex object WITHOUT using nentsel
« Reply #3 on: December 07, 2009, 10:16:15 AM »
Ok, I am confused ...

You want to know the insertion point of a block from within the blocks collection ... well ... there isn't really an insertion point for a block within the blocks collection. The blocks collection is the collection of all the blocks defined in the drawing, not necessarily those inserted into the drawing. Until a block is inserted, there isn't an insertion point ... there is an Origin point .. i.e. the point at which the insertion point is defined when inserted. The origin is the same as the INSBASE. Perhaps that is what you are looking for.

If you are looking to modify a nested block, you have to read that main block definition and iterate through the objects to find the one you want. Then your nested block will not be a block, but will instead be a blockreference, and as such will have an insertion point.
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

ArgV

  • Guest
Re: Insertionpoint of complex object WITHOUT using nentsel
« Reply #4 on: December 07, 2009, 10:27:14 AM »
Ok, I am confused ...

You want to know the insertion point of a block from within the blocks collection ... well ... there isn't really an insertion point for a block within the blocks collection. The blocks collection is the collection of all the blocks defined in the drawing, not necessarily those inserted into the drawing. Until a block is inserted, there isn't an insertion point ... there is an Origin point .. i.e. the point at which the insertion point is defined when inserted. The origin is the same as the INSBASE. Perhaps that is what you are looking for.

If you are looking to modify a nested block, you have to read that main block definition and iterate through the objects to find the one you want. Then your nested block will not be a block, but will instead be a blockreference, and as such will have an insertion point.

I'm just replacing one large assembly with another one. but to insert the new "better" block, I need to know the insertionPoint and rotation of the original block I'm trying to replace. However, the block I'm trying to replace is a large block with blocks inside of it (nested). So, when I go through the blocks collection, I get the large block, but it does not have an insertionPoint property or rotation property, only basic stuff, and a "count" property which makes it obvious that it's nested.

does that mean I just use the origin property for this block?

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Insertionpoint of complex object WITHOUT using nentsel
« Reply #5 on: December 07, 2009, 10:37:24 AM »
Note that there are BLOCKs which are the definitions stored in the Block Collection.
Then there are INSERTs which are visible objects in the Drawing. These are pointers back to the Block collection but do contain attribute info where as the Block Definitions contain Attribute Definitions.

How clear is the ? :)

When blocks are created you usually pick an "Base Point". When blocks are Inserted you pick an "Insertion Point" which is stored in the INSERT not the Block.

When you replace a BLOCK in the Block Collection the INSERT(s) in the DWG are updated with this new information but should retain the INSERT information like Insert Point, scale & rotation.

(I think I got that correct)  8-)

AND:
Defining a BLOCK requires a BASE POINT which relates to the objects you included in the Block Definition. This is a point that is relative to the objects in the block.
When you insert a block you create an INSERT object & it's display in the DWG is relative to the Insert Point. The Insert Point is where the Base Point is offset to & the objects in the Block are now displayed relative to there Insert Point.
« Last Edit: December 07, 2009, 10:50:27 AM by CAB »
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Re: Insertionpoint of complex object WITHOUT using nentsel
« Reply #6 on: December 07, 2009, 10:39:15 AM »
That is exactly why I am saying I am confused ...
Are you trying to redefine "large assembly" or are you trying to replace a single insertion of "large assembly" with a new "better" block? They are not the same thing. To redefine "large assembly" you need to iterate through the block definition (the one in the blocks collection) and redefine each element you want to change. If you are merely trying to replace an inserted block (i.e. a block reference) you cannot do that from the block collection. You can only do that by finding the block insertion in the drawing ModelSpace collection or PaperSpace collection ... or ssget the block reference ... and then operate on that block reference ...

Remember, programmatically a block and a block reference are very different creatures.
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: Insertionpoint of complex object WITHOUT using nentsel
« Reply #7 on: December 07, 2009, 10:39:21 AM »
Hi,

To undertand how nested blocks work, you can compare a block definition and the Modelspace (wich is a block definition sort of)

When you insert a block reference in model space its insertion point is about WCS (if the block normal is 0,0,1 ; OCS otherwise, see here)

A nested block ia a block reference inserted in a block definition and it's insertion point is about the Block definition coordinate system which origin is the base point of the 'parent' block definition.

Now, with a simple example "A" bloc is nested in "B" block.
"A" insertion point in "B" is 2,3,0 if you insert "B" in model space at 10,10,0 without any rotation or scaling the insertion point of "A" in model space is 12,13,0 ("A" insertion point + "B" insertion point).
If "B" is rotated or scaled when inserting or in case of multiple nesting levels, getting "A" insertion point coordinates in model space is mor complex. The easiest way to calculate these coordinates is to use a transformation matrix as this returned by nentselp.
If you want to avoid using nentsel(p), you should have to calculate this matrix.

You can see here or there and more searching for RCS2WCS.
Speaking English as a French Frog

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Re: Insertionpoint of complex object WITHOUT using nentsel
« Reply #8 on: December 07, 2009, 10:47:12 AM »
gile,
You are correct, however, block "B" will have an insertion point within block "A" ... and will return an insertion point in relation to OCS. Only if the user needs WCS will nentselp or another calculation of a transformation martrix be needed.

It sounds to me like the task is merely to replace a block insertion with another block. If that is the case, which we still don't have a clear answer, merely redefining the block in the blocks collection will work, OR insert the new block at the insertion point of the BlockReference in ModelSpace or PaperSpace.
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

ArgV

  • Guest
Re: Insertionpoint of complex object WITHOUT using nentsel
« Reply #9 on: December 07, 2009, 11:57:21 AM »
Note that there are BLOCKs which are the definitions stored in the Block Collection.
Then there are INSERTs which are visible objects in the Drawing. These are pointers back to the Block collection but do contain attribute info where as the Block Definitions contain Attribute Definitions.

How clear is the ? :)

When blocks are created you usually pick an "Base Point". When blocks are Inserted you pick an "Insertion Point" which is stored in the INSERT not the Block.

When you replace a BLOCK in the Block Collection the INSERT(s) in the DWG are updated with this new information but should retain the INSERT information like Insert Point, scale & rotation.

(I think I got that correct)  8-)

AND:
Defining a BLOCK requires a BASE POINT which relates to the objects you included in the Block Definition. This is a point that is relative to the objects in the block.
When you insert a block you create an INSERT object & it's display in the DWG is relative to the Insert Point. The Insert Point is where the Base Point is offset to & the objects in the Block are now displayed relative to there Insert Point.


Hmph. These blocks have attributes and everything. Perhaps I should just rename the block to the name of the block I'm inserting, and then insert the new block and update. ?

This other stuff is going to drive me nuts.

Suppose I have a block "A". block "A" contains blocks "B", "C", "D", "E", and "F". I don't care about B - F, I just want the point in which to insert block "A", which contains a re-definition (as it were) of the old "A" block.

I've been working with Java the last 3 months, and forgot what I used to know about blocks!


ArgV

  • Guest
Re: Insertionpoint of complex object WITHOUT using nentsel
« Reply #10 on: December 07, 2009, 12:03:05 PM »
gile,
You are correct, however, block "B" will have an insertion point within block "A" ... and will return an insertion point in relation to OCS. Only if the user needs WCS will nentselp or another calculation of a transformation martrix be needed.

It sounds to me like the task is merely to replace a block insertion with another block. If that is the case, which we still don't have a clear answer, merely redefining the block in the blocks collection will work, OR insert the new block at the insertion point of the BlockReference in ModelSpace or PaperSpace.

Ok. I have old block. Old block has changed. I want drawing to reflect these changes with the new "improved" block. It's a pretty common operation, however I'm using objectDBX, and going through several thousand drawings to do so.

Pulling from an excel spreadsheet, if it finds a block the same name as cell A1, it replaces it with an insert by the name in B1. And so on and so fourth through each block in each drawing.


Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Re: Insertionpoint of complex object WITHOUT using nentsel
« Reply #11 on: December 07, 2009, 12:11:20 PM »
Ok, so you want to redefine a block ... lets call it block "A" ... to do this, you want to get the insertion point of block "A" so you can put the new block in its place. Great .. now we are getting somewhere ... except you can't do that using a block from the blocks collection .. that is merely the definition of a block ...

To use an insertion point, you have to have an "INSERT" .. which is a BlockReference, you have a "BLKDEF" i.e. Block ...

You have a few options:
A) Select all of the inserted blocks in the drawing, either through an iteration of every element in the drawing, or by opening the drawing and using a select call to find them all, then get the insertion point of each INSERT and put your new INSERT there.

OR

B) Take the block definition (from the Blocks Collection) and delete all objects in it .. then add the items you want to that block definition.

OR

C) Insert the redefined BLOCK from a file, causing the definition to be overwritten.
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Insertionpoint of complex object WITHOUT using nentsel
« Reply #12 on: December 07, 2009, 12:57:14 PM »
When I posted, I was under the impression that you wanted to modify the nested block within the BLOCK definition in some way, but it now appears that you want to replace the INSERT in the drawing, at each occurrence.

As Keith points out, this can be done using a SelectionSet, or Iterating through the objects in the drawing, or if the new block is defined in the block table, then you can just substitute the name of the new block for the old in the INSERT.

Lee

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Insertionpoint of complex object WITHOUT using nentsel
« Reply #13 on: December 07, 2009, 01:16:50 PM »
One more point ArgV,

You can check the available properties/methods that are applicable to an object, using either:

Code: [Select]
(vlax-dump-object <obj> t)

Or

Code: [Select]
(vlax-property-available-p <obj> 'Property)

(vlax-method-applicable-p <obj> 'Method)

And hence you will correctly find that the BLOCK Definition does not have the InsertionPoint property  :wink:

Lee

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Insertionpoint of complex object WITHOUT using nentsel
« Reply #14 on: December 07, 2009, 01:25:55 PM »
I would go with option B from Keith's post.

Edit: Especially if you want to go the ObjectDBX route.

Edit:  Maybe this post will give you the general idea of one way to do it.
[ http://www.theswamp.org/index.php?topic=23128.0 ]
« Last Edit: December 07, 2009, 01:34:08 PM by T.Willey »
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.