PDA

View Full Version : Nested Blocks



peter
2011-11-22, 02:57 PM
Someone asked me a couple days ago about nested blocks
so I said I would start a thread about it. Thoughts?



(vl-load-com)

; Command line function to get the list of nested blocks in a
; selected block and print them to the command line,

(defun C:GetNestedBlockList (/
lstNestedBlocks
objBlock
strItem
)
(if (and (setq objBlock (vlax-ename->vla-object (car (entsel "\nSelect Block: "))))
(IsBlock objBlock)
)
(foreach strItem (reverse (GetNestedBlockList objBlock))
(print strItem)
)
)
(prin1)
)

; Recursive Function to search for and return a list of nested blocks

(defun GetNestedBlockList (objBlock
/
objItem
)
; lstNestedBlocks needs to be local to the
; calling function See Above
(if (setq lstNestedBlocks (cons (list (strcase (vla-get-name objBlock))
(strcase (vla-get-effectivename objBlock))
objBlock)
lstNestedBlocks))
(vlax-for objItem
(vla-item (vla-get-blocks
(vla-get-document objBlock))
(vla-get-name objBlock))
(if (IsBlock objItem)
(GetNestedBlockList objItem))))
lstNestedBlocks
)

; Function to check if an object is a block reference
(defun IsBlock (objSelection)
(wcmatch (vla-get-objectname objSelection) "AcDbBlockReference,AcDbMInsertBlock")
)

BlackBox
2011-11-22, 03:20 PM
No Sir, I just don't like them.

http://insider2.idahosteelheads.com/wp-content/uploads/2010/11/Mr__Horse_by_Ren_and_Stimpy_Club1.jpg

peter
2011-11-22, 04:50 PM
No Sir, I just don't like them.

Nested blocks or the functions or Thoughts?

BlackBox
2011-11-22, 06:17 PM
Nested blocks or the functions or Thoughts?

Sorry for my ambiguity, Peter - I'm not a fan of nested blocks.

Perhaps this is just the result of the industry in which I work; nested blocks in my work are just not necessary. At most, we'll use a handful of Dynamic blocks, but even that is few and far between.

As for code... I've only skimmed, but I know you to be quite thorough. :beer:If I can make the time, I'll put together a variation that comes to mind, my friend.

As for thoughts... Especially going into the Holidays... I'm trying to stay away from those things altogether! Sadly, this is becoming increasingly difficult to accomplish, the older I get. :lol: LoL

peter
2011-11-22, 08:08 PM
Nested Blocks have one application I use...

I created dynamic block components of a conglomerate dynamic block. Since dynamic blocks are fundamentally 2d (xy plane), by making the sub blocks orient on the xz plane, I was able to create a dynamic block that changes dimensions in x,y and z directions.

That is where this code came from.

P-


The code could be also used to drill down into block definitions and return lists of object including blocks




(vl-load-com)
;
; Command line function to get the list of nested objects
; in a selected block and print them to the command line,

(defun C:GetNestedObjectList (/
lstNestedObjects
objBlock
objItem
)
(if (and (setq objBlock (vlax-ename->vla-object (car (entsel "\nSelect Block: "))))
(IsBlock objBlock)
)
(foreach objItem (reverse (GetNestedObjectList objBlock))
(print (vla-get-objectname objItem))
)
)
(prin1)
)


(defun GetNestedObjectList (objBlock
/
objBlockDef
objItem
)
; lstNestedObjects need to be local to the calling function See Above
(if (and (setq lstNestedObjects (cons objBlock
lstNestedObjects
)
)
(IsBlock objBlock)
(setq objBlockDef (vla-item
(vla-get-blocks
(vla-get-document objBlock))
(vla-get-name objBlock))
)
(> (vla-get-count objBlockDef) 0)
)
(vlax-for objItem objBlockDef
(GetNestedObjectList objItem)
)
)
(princ "*")
lstNestedObjects
)



(defun IsBlock (objSelection)
(wcmatch (vla-get-objectname objSelection) "AcDbBlockReference,AcDbMInsertBlock")
)

Jeff H
2011-11-24, 04:19 PM
Peter - I'm not a fan of nested blocks.

Perhaps this is just the result of the industry in which I work; nested blocks in my work are just not necessary.

More times than not you get files with nested blocks that just cause more hassle and can not find the benefits in that situation.

On the other hand they can be beneficial if used when appropriate.

For example what Peter mentioned or,
a simple generic example might be a drawing that has a ton of blocks and each have a certain small part connected, and now that part changes. Change once or 250 different definitions.

BlackBox
2011-11-24, 05:23 PM
Absolutely I see that nested block may be beneficial in other industries (Mechanical/Electrical perhaps?).

There's just very little necessity for those of us in Transportation that standard, or dynamic blocks (at most) do not provide (i.e. light poles, drainage structures, utilities, signing and pavement markings, etc.).

Jeff H
2011-11-24, 06:12 PM
Renderman what exactly is the Transportation industry?
I know what transportation is but when I think of roads I associate it with civil.

I thought you quit or something had not seen you post for a month or so.

Good to see your are well and Happy Thanksgiving

BlackBox
2011-11-25, 03:30 AM
Renderman what exactly is the Transportation industry?
I know what transportation is but when I think of roads I associate it with civil.


Transportation does fall under the Civil umbrella, however it is a sepearate discipline from Urban Land, Environmental Infrastructure, and Landscape for example. There's also the issue of the scale and scope of a company as to how they break out these projects; a smaller design firm may roll roadway and site development into one group. My employer is fairly large and each of the above mentioned disciplines (among many others) have their own teams locally, regionally, and internationally.

There's more to it than that, but hopefully that provides some level of clarification.



I thought you quit or something had not seen you post for a month or so.

Good to see your are well and Happy Thanksgiving

No, I've not quit, I'm still working for the same employer. LoL

I took a slight vacation from my AutoCAD brethren to cross train on Microstation. I'm now working on some State projects that require that I use their MS customized suite for pay item data, etc. I've been Beta testing the State's Civil 3D kit for over a year now, but must work with MS until they make the C3D kit available for production... Or the private / County / City side of transportation opens back up. LoL damned economy.

Happy Thanksgiving to you as well, Jeff.