Selectin Nested Blocks

Selectin Nested Blocks

don_scribner
Contributor Contributor
1,847 Views
19 Replies
Message 1 of 20

Selectin Nested Blocks

don_scribner
Contributor
Contributor

Hey there guys and gals,

 

I have a cheesy (to you real programmers anyway!)  lisp that I wrote a gazillion years ago that returns the bock name at the end of a leader.  I then augmented it to find the new company part number in a list and return that.  SO . . . I use ENTSEL to get the block.  Well, I have a fistful of dynamic blocks that I would like to do the same but I want to select the nested blocks.  How would I select that?  Specifically, I created machine screw/washer/lk washer/nut assemblies and I want to be able to call out the nested components without exploding.  Gotta be a way.  

0 Likes
Accepted solutions (1)
1,848 Views
19 Replies
Replies (19)
Message 2 of 20

Moshe-A
Mentor
Mentor

@don_scribner  hi,

 

if you pick a block with (Nentsel) function, it will return the ename of the picked block but also all the enames of its parents blocks up to the inserted block but you want the other direction - yes?!

 

if the inner block contain more then one at the same deep level, do you want all of them?

 

Moshe

 

Message 3 of 20

Kent1Cooper
Consultant
Consultant

@don_scribner wrote:

.... I want to be able to call out the nested components without exploding. ....  


What do you mean by "call out"?  Do you just want to know the Block name of a Block that's nested in another?  Or do you want to do something with it, in Block-editing fashion?  Or Insert another of a nested Block, independent of its host Block?  Or...?

Kent Cooper, AIA
0 Likes
Message 4 of 20

DGCSCAD
Collaborator
Collaborator

This will get you a list of the nested blocks. Tested only on static blocks, but should be good for either:

 

(defun c:GNBTest (/ gnb1 gnb1name gnb1blkdef gnb1data lst)
(setq lst '())
(setq gnb1 (car (entsel)))
(setq gnb1name (cdr (assoc 2 (entget gnb1))))
(setq gnb1blkdef (tblobjname "block" gnb1name))
	(while (setq gnb1blkdef (entnext gnb1blkdef))
		(setq gnb1Data (entget gnb1blkdef))
		(if (= (cdr (assoc 0 gnb1Data)) "INSERT")
			(setq lst (cons (cdr (assoc 2 gnb1Data)) lst))
		)
	)
)
AutoCad 2018 (full)
Win 11 Pro
0 Likes
Message 5 of 20

don_scribner
Contributor
Contributor
Below (if it posts) is what I am up against. I start the lisp, select a block. The lisp gets the block name, looks at a list then returns the new part number at the end of a leader. I can select up to 4 blocks and they return concataenated w/ slashes between. The one shown is single blocks clustered together. Below that, is the un-exploded dynamic block that they came from. So, what I would like to do is be able to select those 4 nested blocks without exploding.

[cid:image001.png@01DAFA07.E59938B0]
0 Likes
Message 6 of 20

Kent1Cooper
Consultant
Consultant

@don_scribner wrote:
... (if it posts) ...

[It didn't.  Are you perhaps replying to an email notification of a posting to your topic?  You can't attach things that way, but must come to the website.]

Kent Cooper, AIA
0 Likes
Message 7 of 20

don_scribner
Contributor
Contributor

don_scribner_1-1724949819012.png

 

0 Likes
Message 8 of 20

DGCSCAD
Collaborator
Collaborator

Uploading the block would help.

 

The code I had posted *should get you those names in a list. String those together in the format you need and add it to a leader.

 

*not tested on dynamic blocks

AutoCad 2018 (full)
Win 11 Pro
0 Likes
Message 9 of 20

don_scribner
Contributor
Contributor

OK, I just dropped a dynamic block assembly and my cheezoid lisp (no laughing! It's served me well for years). Explode the nested block and the lisp will return the correct part number based on the block name.  I'd like to do that without exploding. My hope is somebody will say "OH! That's it!!?!?  Just use  xxxget instead!" 

 

0 Likes
Message 10 of 20

DGCSCAD
Collaborator
Collaborator

Thanks for uploading.

Just tested and the code I posted doesn't work for dynamic blocks.

 

¯\_(ツ)_/¯

 

I'd have to dig into things a bit deeper to figure it out, but my time is limited. Hopefully someone with more knowledge on dynamic blocks and nesting comes through with a solution for you.

AutoCad 2018 (full)
Win 11 Pro
0 Likes
Message 11 of 20

komondormrex
Mentor
Mentor
Accepted solution

hey there,

check the following

 

 

 

(defun get_n_parts (insert_ename / name_part_list n_block_list)
	(setq name_part_list '(
							("'F102" "300275")
							("F102" "300275")
							("F103" "306259")
							("F104" "300274")
							("F105" "300272")
							("AF105" "300317")
							("F106" "300278")
							("F107" "300273")
							("AF107" "300318")
							("F108" "300287")
							("F109" "129961")
							("AF109" "300336")
							("F110" "129960")
							("AF110" "300335")
							("F111" "300803")
							("F204" "300750")
							("F206" "CUSTOM")
							("F208" "CUSTOM")
							("F210" "CUSTOM")
							("F212" "CUSTOM")
							("F303" "300294")
							("F305" "300339")
							("F306" "119985")
							("F314" "300751")
							("F316" "129996")
							("F318" "CUSTOM")
							("F403" "300270")
							("F404" "119987")
							("F406" "CUSTOM")
							("F413" "300271")
							("F502" "300295")
							("F503" "119994")
							("F504" "119993")
							("F512" "29962")
							("F513" "119986")
							("F514" "119992")
							("F522" "129963")
							("F523" "300281")
							("F524" "300625")
							("F534" "129952")
							("F573" "300883")
							("F564" "300282")
							("F801F" "300384")
							("F801H" "300747")
							("F802" "129993")
							("F803" "129998")
							("F804" "129944")
							("F805" "445464")
							("F810" "300292")
							("F811" "300293")
							("F812" "306263")
							("F813" "119995")
							("F814" "129964")
							("F815" "300342")
							("F816" "129945")
							("F817" "1107208")
							("F818" "306254")
							("F819" "300724")
							("F820" "UNK")
							("F821" "300338")
							("F824" "300449")
							("F825" "300277")
							("F841" "129966")
							("F844" "300958")
							("F842" "306258")
							("F901" "300356")
							("F901" "300357")
							("F904" "300343")
							("PCHTEK101S" "300277")
							("G101" "303912")
							("G101-O" "303910")
							("G102" "303908")
							("G102-O" "303909")
							("G103" "303911")
							("G104" "300387")
							("G104-5" "300307")
							("G104-75" "300306")
							("G104-157" "300305")
							("G104-225" "300308")
							("G105" "303914")
							("G106-2" "303922")
							("G109-1" "303905")
							("G109-2" "303906")
							("G111" "303901")
							("G111-2" "1136800")
							("G113" "320327")
							("G115" "300502")
							("G121" "303894")
							("G122" "320102")
							("G124" "300441")
							("G131" "303919")
							("G130" "303915")
							("G131-A" "303920")
							("G132" "300309")
							("G133" "3790")
							("G144-157" "300807")
							("G144-5" "300808")
							("G144-75" "303917")
							("G200" "303915")
							("GB106" "300813")
							("GB112" "300918")
							("GB118" "300919")
							("GB131" "303921")
							("GB706" "300920")
							("GB906" "300814")
							("S901" "300284")
							("S902" "300285")
							("S903" "129971")
							("S904" "300876")
							("S905" "320299")
							("S905-3" "320300")
							("S905-4" "320301")
							("S906" "129970")
							("SGT-1" "129949")
							("SGT-2" "129950")
							("SGT-3" "300441")
							("60S" "302450")
							("60RFB" "302449")
							("60H-1F" "302451")
							("60H-1M" "302452")
							("60H-2F" "302447")
							("60H-2M" "302448")
							("BP-1" "302455")
							("RT-1" "302453")
							("RET-3" "302489")
							("4P4" "302454")
							("J-RECEIVER" "302456")
							("VE-RS" "302492")
							("VE-HS" "302464")
							("VE-SC" "302465")
							("VE-MC" "302509")
							("VE-MCC" "302510")
							("CLSR-1" "300388")
							("CLSR-3" "302472")
							("LTC-C" "302469")
							("LTC-CC" "302466")
							("RF-3" "302438")
							("H-MC" "302509")
							("H-MCC" "302510")
							("PQ-HB" "302483")
							("PQ-RB" "302484")
							("35S" "302443")
							("35RF-B" "302442")
							("35RF-LTB" "302446")
							("35H-1F" "302444")
							("35H-1M" "302445")
							("35H-2F" "302440")
							("35H-2M" "302441")
							("4P4_ASSY" "302454_306258")
							("90SB" "302514")
							("90RFB" "302515")
							("90RD" "302513")
							("90H" "300395")
							("90HCL" "300394")
							("90BP" "302512")
							("BP-2" "302512")
							("C-S5" "302494")
							("C-S7" "302497")
							("C-S12" "302495")
							("C-SC5" "119983")
							("C-SC7" "300223")
							("C-SC12" "300240")
							("C-R5" "302498")
							("C-R7" "302500")
							("C-R12" "302499")
							("C-H5" "302493")
							("C-H7" "302496")
							("C-H12" "     ")
							("C-RF" "302462")
							("C-RC5-7" "302486")
							("C-HC5" "302487 ")
							("C-RC7-12" "119970")
							("C-RC12" "302488 ")
							("VE-RS" "302492")
							("VE-HS" "302464")
							("VE-SC" "302465")
							("VE-MC" "302509")
							("VE-MCC" "302510")
							("VE-M" "119989")
							("CLSR-1" "300388")
							("CLSR-3" "302472")
							("LTC-C" "302469")
							("LTC-CC" "302466")
							("RF-3 " "302438")
							("H-MC " "302509")
							("H-MCC" "302510")
							("RET-3" "302489")
							("3RF" "302476")

							("SC-1" "302485")
							("CLSR-3" "302472")
							("LPG-IS" "302502")

							("LPGS-IS" "302503")
							("LPG-IS" "302502")
							("LPG-RF" "302473")

							("LPG-P" "302474")
							("LPG-C" "302565")
							("RF-3" "302438")
							("H-RCC" "302504")
							("H-RC" "302505")
						  )
	)
	(vlax-map-collection (vla-item (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object)))
								   (vla-get-effectivename (vlax-ename->vla-object insert_ename))
						 )
						 '(lambda (object)
							(if (and
									 (= "AcDbBlockReference" (vla-get-objectname object))
									 (minusp (vlax-get object 'visible))
								)
								(setq n_block_list (append n_block_list (list (vla-get-effectivename object))))
							)
						  )
	)
	(setq part_list (mapcar '(lambda (n_name) (cond
												((= "F" (substr n_name 1 1)) (cadr (assoc (strcase (substr n_name 1 4)) name_part_list)))
												((= "G" (substr n_name 1 1)) (cadr (assoc (strcase (substr n_name 1 7)) name_part_list)))
												(t nil)
											  )
							 )
							 n_block_list
					)
	)
	(apply 'strcat (cdr (apply 'append (mapcar '(lambda (part) (list "/" part)) (vl-remove nil part_list)))))
)

(defun c:mleader_nested (/ insert_data)
	(setq insert_data (entsel "\nPick a block: ")
		  part_string (get_n_parts (car insert_data))
	)
	(if (/= "" part_string)
		(progn
			(vl-cmdf "_.mleader" "_non"
								 (getpoint "\nPick Mleader root point: ")
								 "_non"
								 pause
								 (get_n_parts (car insert_data))
			)
			(entmod (append (entget (entlast)) '((8 . "dimensions"))))
		)
		(princ "\nNo part found in block picked")
	)
	(princ)
)

 

 

 

 

0 Likes
Message 12 of 20

don_scribner
Contributor
Contributor

First of all . . .WOW!  You know your stuff.  This is why I ask.  It goes a bit too far though.  It brings back all the blocks within the dynamic block, even the ones in other visibility states.  I was hoping to be able to select the single visible block, or maybe all those in the current vstate.  Probably seems counter intuitive for some people.  In my position, I have to reinvent the wheel for 20+ very custom skylights (no rectangles) per week to the tune of maybe 900K or better.  SO, speed and no typing it the key. 

0 Likes
Message 13 of 20

komondormrex
Mentor
Mentor

updated #11 to visible only.

0 Likes
Message 14 of 20

Sea-Haven
Mentor
Mentor

Just a comment would the parts list be better as say a text file ? Say a CSV file can then live in excel etc making adding more a bit easier, with data sorted by name/number etc.

0 Likes
Message 15 of 20

john.uhden
Mentor
Mentor

@Sea-Haven ,

My answer would be yes... use a .csv file that's readable by all appropriate users.  That way it can be edited just once without having to update the software to all the users' machines.

John F. Uhden

0 Likes
Message 16 of 20

Sea-Haven
Mentor
Mentor

A couple of minutes work.

 

0 Likes
Message 17 of 20

don_scribner
Contributor
Contributor

K,

 

Sorry about not getting back to you sooner.  Been insane here. Come fall, everybody wants to button up their building projects against the weather and since we manufacture skylights . . . .

 

I didn't understand your message about #11.  

0 Likes
Message 18 of 20

komondormrex
Mentor
Mentor

i mean i updated the code in the message 11 so that it will mleader the blocks that are visible only. 

0 Likes
Message 19 of 20

don_scribner
Contributor
Contributor

K,

 

I emailed also but is seems to be undeliverable. 

 

On my screen, your code is in message 7 not 11. Go figure.  Story of my life.  But . . .

I tried the lisp and it works wonderfully! Thanks so much.  I had to explode blocks, especially the dynamic assemblies that we use. 

 

Thanks again!

 

Message 20 of 20

komondormrex
Mentor
Mentor

you are much welcome)

0 Likes