Delete Selected Block (not all) and Insert Block

Delete Selected Block (not all) and Insert Block

werner.bianca
Contributor Contributor
2,285 Views
20 Replies
Message 1 of 21

Delete Selected Block (not all) and Insert Block

werner.bianca
Contributor
Contributor

Good morning!
I've been putting together lisps by researching here, mashing things together/trial and error until I'm able to get it to work as I want. But I've been struggling to get this one going (and another one that I'll make a different post for "here")

This one is about "replacing" a selected Block.
The reason why I'm using quotes is because I don't want to Replace the Block reference and Update all, which seems to be the most common lisps when I try to search.
I want to select a block, one at a time, out of many of the same.
In the command I want it to read which block was selected out of 7 options. Depending on which one it is, BLOCK1 gets erased and BLOCK11 is inserted in the same spot. and that insertion point will prompt the following commands to insert another block (BLOCK111) with 3 different options.
The second portion of selection I'm not too concern about because it will be a selection imputed by the user. And I already have an idea on how to work that out.
My problem is that I can't figure out how set it up to use the selected block (or to select a block) instead of a point. I can set it up to insert the BLOCK11 on the right spot. But can't get it to delete BLOCK1. But most of all that it shouldn't affect any of the others blocks of the same name in the drawing.
Please help. I'm not even sure if it is a possibility, specially since I haven't found anything similar.

I'll be working on the continuation of the command. And in case this portion can't be fixed then I'll just set it up to Insert the Blocks (BLOCK11 and BLOCK111) only. But it would still be extremely helpful to have it read the name of the BLOCK1 (since I still have options 1-7) to promp the following insertions.

0 Likes
Accepted solutions (1)
2,286 Views
20 Replies
Replies (20)
Message 2 of 21

Kent1Cooper
Consultant
Consultant

Post the code you have so far.

Kent Cooper, AIA
0 Likes
Message 3 of 21

werner.bianca
Contributor
Contributor

Here's a rough sketch:

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;              Replace BLOCK (1-7 OPTIONS) Command              ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun c:REPO ()
(setvar "cmdecho" 1)
(setq oldsnap (getvar "osmode")) ;Determine current Snap Mode;
(setq oldlayer(getvar "clayer")) ;Determine current Layer;
(command "-layer" "s" "LAYER322" "") ;Change to layer in which command will take action
(setvar "osmode" 64) ;Change Snap Mode to INSERTION only;
	(setq client (getint
	"Select type of Pole to Replace: [1] TYPE1, [2] TYPE2, [3] TYPE3, [4] TYPE4, [5] TYPE5, [6] TYPE6, [7] TYPE7")
	)
	(cond ;POLE TYPE
		;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
		((= CLIENT 1) ;TYPE1 [BLOCK1] REFERENCE; [BLOCK11] INSERTED AT REFERENCE POINT ; [BLOCK111] INSERTED AT RADIUS FROM REFERENCE POINT
			(while (setq Basepoint (entsel "Select pole to replace"))
				(command "insert" "BLOCK11" (cadr Basepoint) "60" "60" "_none" (cdr (assoc 10 (entget (car Basepoint)))))
				(setq client (getint
				"Select type of Replacement: [Q] Same/Hard, [W] 1' Set, [E] 2' Set")
				)
				(cond ;POLE SET
					;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
					((= CLIENT Q)
						(setq Baseradius 7)
						(progn
							(command "circle" Basepoint Baseradius)
							(setq Basecircle (entlast))
							(setvar "osmode" 2875)
							(command "insert" "BLOCK111" "60" "60" pause)
							(command "erase" Basecircle "")
						)
					) ;POLE SET END Condition Q
					;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
					((= CLIENT W)
						(setq Baseradius 8)
						(progn
							(command "circle" Basepoint Baseradius)
							(setq Basecircle (entlast))
							(setvar "osmode" 2875)
							(command "insert" "BLOCK111" "60" "60" pause)
							(command "erase" Basecircle "")
						)
					) ;POLE SET END Condition W
					;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
					((= CLIENT E)
						(setq Baseradius 6)
						(progn
							(command "circle" Basepoint Baseradius)
							(setq Basecircle (entlast))
							(setvar "osmode" 2875)
							(command "insert" "BLOCK111" "60" "60" pause)
							(command "erase" Basecircle "")
						)
					) ;POLE SET END Condition E
					;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
				) ;POLE SET END Condition
			)
		) ;POLE TYPE Condition 1 ;TYPE1 [BLOCK1] [BLOCK11] [BLOCK111]
		;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
		;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
		((= CLIENT 2) ;TYPE2 [BLOCK2] REFERENCE; [BLOCK22] INSERTED AT REFERENCE POINT ; [BLOCK222] INSERTED AT RADIUS FROM REFERENCE POINT
			(while (setq Basepoint (entsel "Select pole to replace"))
				(command "insert" "BLOCK22" (cadr Basepoint) "60" "60" "_none" (cdr (assoc 10 (entget (car Basepoint)))))
				(setq client (getint
				"Select type of Replacement: [Q] Same/Hard, [W] 1' Set, [E] 2' Set"))
				(cond ;POLE SET
					;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
					((= CLIENT Q)
						(setq Baseradius 7)
						(progn
							(command "circle" Basepoint Baseradius "")
							(setq Basecircle (entlast))
							(setvar "osmode" 2875)
							(command "insert" "BLOCK222" "60" "60" pause)
							(command "erase" Basecircle "")
						)
					) ;POLE SET END Condition Q
					;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
					((= CLIENT W)
						(setq Baseradius 8)
						(progn
							(command "circle" Basepoint Baseradius "")
							(setq Basecircle (entlast))
							(setvar "osmode" 2875)
							(command "insert" "BLOCK222" "60" "60" pause)
							(command "erase" Basecircle "")
						)
					) ;POLE SET END Condition W
					;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
					((= CLIENT E)
						(setq Baseradius 6)
						(progn
							(command "circle" Basepoint Baseradius "")
							(setq Basecircle (entlast))
							(setvar "osmode" 2875)
							(command "insert" "BLOCK222" "60" "60" pause)
							(command "erase" Basecircle "")
						)
					) ;POLE SET END Condition E
					;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
				) ;POLE SET END Condition
			)
		) ;POLE TYPE Condition 2 ;TYPE2 [BLOCK2] [BLOCK22] [BLOCK222]
		;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
		;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
		((= CLIENT 3) ;TYPE3 [BLOCK3] REFERENCE; [BLOCK33] INSERTED AT REFERENCE POINT ; [BLOCK333] INSERTED AT RADIUS FROM REFERENCE POINT
			(while (setq Basepoint (entsel "Select pole to replace"))
				(command "insert" "BLOCK33" (cadr Basepoint) "60" "60" "_none" (cdr (assoc 10 (entget (car Basepoint)))))
				(setq client (getint
				"Select type of Replacement: [Q] Same/Hard, [W] 1' Set, [E] 2' Set"))
				(cond ;BLOCK3 SET
					;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
					((= CLIENT Q)
						(setq Baseradius 7)
						(progn
							(command "circle" Basepoint Baseradius "")
							(setq Basecircle (entlast))
							(setvar "osmode" 2875)
							(command "insert" "BLOCK333" "60" "60" pause)
							(command "erase" Basecircle "")
						)
					) ;BLOCK3 SET END Condition Q
					;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
					((= CLIENT W)
						(setq Baseradius 8)
						(progn
							(command "circle" Basepoint Baseradius "")
							(setq Basecircle (entlast))
							(setvar "osmode" 2875)
							(command "insert" "BLOCK333" "60" "60" pause)
							(command "erase" Basecircle "")
						)
					) ;BLOCK3 SET END Condition W
					;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
					((= CLIENT E)
						(setq Baseradius 6)
						(progn
							(command "circle" Basepoint Baseradius "")
							(setq Basecircle (entlast))
							(setvar "osmode" 2875)
							(command "insert" "BLOCK333" "60" "60" pause)
							(command "erase" Basecircle "")
						)
					) ;BLOCK3 SET END Condition E
					;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
				) ;BLOCK3 SET END Condition
			)
		) ;BLOCK3 TYPE Condition 3 ;TYPE3 [BLOCK3] [BLOCK33] [BLOCK333]
		;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
		;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
		((= CLIENT 4) ;TYPE4 [BLOCK4] REFERENCE; [BLOCK44] INSERTED AT REFERENCE POINT ; [BLOCK444] INSERTED AT RADIUS FROM REFERENCE POINT
			(while (setq Basepoint (entsel "Select pole to replace"))
				(command "insert" "BLOCK44" (cadr Basepoint) "60" "60" "_none" (cdr (assoc 10 (entget (car Basepoint)))))
				(setq client (getint
				"Select type of Replacement: [Q] Same/Hard, [W] 1' Set, [E] 2' Set"))
				(cond ;BLOCK3 SET
					;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
					((= CLIENT Q)
						(setq Baseradius 7)
						(progn
							(command "circle" Basepoint Baseradius "")
							(setq Basecircle (entlast))
							(setvar "osmode" 2875)
							(command "insert" "BLOCK444" "60" "60" pause)
							(command "erase" Basecircle "")
						)
					) ;BLOCK3 SET END Condition Q
					;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
					((= CLIENT W)
						(setq Baseradius 8)
						(progn
							(command "circle" Basepoint Baseradius "")
							(setq Basecircle (entlast))
							(setvar "osmode" 2875)
							(command "insert" "BLOCK444" "60" "60" pause)
							(command "erase" Basecircle "")
						)
					) ;BLOCK3 SET END Condition W
					;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
					((= CLIENT E)
						(setq Baseradius 6)
						(progn
							(command "circle" Basepoint Baseradius "")
							(setq Basecircle (entlast))
							(setvar "osmode" 2875)
							(command "insert" "BLOCK444" "60" "60" pause)
							(command "erase" Basecircle "")
						)
					) ;BLOCK3 SET END Condition E
					;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
				) ;BLOCK3 SET END Condition
			)
		) ;BLOCK3 TYPE Condition 4 ;TYPE4 [BLOCK4] [BLOCK44] [BLOCK444]
		;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
		;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
		((= CLIENT 5) ;TYPE5 [BLOCK5] REFERENCE; [BLOCK55] INSERTED AT REFERENCE POINT ; [BLOCK555] INSERTED AT RADIUS FROM REFERENCE POINT
			(while (setq Basepoint (entsel "Select pole to replace"))
				(command "insert" "BLOCK55" (cadr Basepoint) "60" "60" "_none" (cdr (assoc 10 (entget (car Basepoint)))))
				(setq client (getint
				"Select type of Replacement: [Q] Same/Hard, [W] 1' Set, [E] 2' Set"))
				(cond ;BLOCK3 SET
					;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
					((= CLIENT Q)
						(setq Baseradius 7)
						(progn
							(command "circle" Basepoint Baseradius "")
							(setq Basecircle (entlast))
							(setvar "osmode" 2875)
							(command "insert" "BLOCK555" "60" "60" pause)
							(command "erase" Basecircle "")
						)
					) ;BLOCK3 SET END Condition Q
					;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
					((= CLIENT W)
						(setq Baseradius 8)
						(progn
							(command "circle" Basepoint Baseradius "")
							(setq Basecircle (entlast))
							(setvar "osmode" 2875)
							(command "insert" "BLOCK555" "60" "60" pause)
							(command "erase" Basecircle "")
						)
					) ;BLOCK3 SET END Condition W
					;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
					((= CLIENT E)
						(setq Baseradius 6)
						(progn
							(command "circle" Basepoint Baseradius "")
							(setq Basecircle (entlast))
							(setvar "osmode" 2875)
							(command "insert" "BLOCK555" "60" "60" pause)
							(command "erase" Basecircle "")
						)
					) ;BLOCK3 SET END Condition E
					;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
				) ;BLOCK3 SET END Condition
			)
		) ;BLOCK3 TYPE Condition 5 ;TYPE5 [BLOCK5] [BLOCK55] [BLOCK555]
		;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
		;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
		((= CLIENT 6) ;TYPE6 [BLOCK6] REFERENCE; [BLOCK66] INSERTED AT REFERENCE POINT ; [BLOCK666] INSERTED AT RADIUS FROM REFERENCE POINT
			(while (setq Basepoint (entsel "Select pole to replace"))
				(command "insert" "BLOCK66" (cadr Basepoint) "60" "60" "_none" (cdr (assoc 10 (entget (car Basepoint)))))
				(setq client (getint
				"Select type of Replacement: [Q] Same/Hard, [W] 1' Set, [E] 2' Set"))
				(cond ;BLOCK3 SET
					;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
					((= CLIENT Q)
						(setq Baseradius 7)
						(progn
							(command "circle" Basepoint Baseradius "")
							(setq Basecircle (entlast))
							(setvar "osmode" 2875)
							(command "insert" "BLOCK666" "60" "60" pause)
							(command "erase" Basecircle "")
						)
					) ;BLOCK3 SET END Condition Q
					;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
					((= CLIENT W)
						(setq Baseradius 8)
						(progn
							(command "circle" Basepoint Baseradius "")
							(setq Basecircle (entlast))
							(setvar "osmode" 2875)
							(command "insert" "BLOCK666" "60" "60" pause)
							(command "erase" Basecircle "")
						)
					) ;BLOCK3 SET END Condition W
					;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
					((= CLIENT E)
						(setq Baseradius 6)
						(progn
							(command "circle" Basepoint Baseradius "")
							(setq Basecircle (entlast))
							(setvar "osmode" 2875)
							(command "insert" "BLOCK666" "60" "60" pause)
							(command "erase" Basecircle "")
						)
					) ;BLOCK3 SET END Condition E
					;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
				) ;BLOCK3 SET END Condition
			)
		) ;BLOCK3 TYPE Condition 6 ; TYPE6 [BLOCK6] [BLOCK66] [BLOCK666]
		;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
		;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
		((= CLIENT 7) ;TYPE7 [BLOCK7] REFERENCE; [BLOCK77] INSERTED AT REFERENCE POINT ; [BLOCK777] INSERTED AT RADIUS FROM REFERENCE POINT
			(while (setq Basepoint (entsel "Select pole to replace"))
				(command "insert" "BLOCK77" (cadr Basepoint) "60" "60" "_none" (cdr (assoc 10 (entget (car Basepoint)))))
				(setq client (getint
				"Select type of Replacement: [Q] Same/Hard, [W] 1' Set, [E] 2' Set"))
				(cond ;BLOCK3 SET
					;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
					((= CLIENT Q)
						(setq Baseradius 7)
						(progn
							(command "circle" Basepoint Baseradius "")
							(setq Basecircle (entlast))
							(setvar "osmode" 2875)
							(command "insert" "BLOCK777" "60" "60" pause)
							(command "erase" Basecircle "")
						)
					) ;BLOCK3 SET END Condition Q
					;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
					((= CLIENT W)
						(setq Baseradius 8)
						(progn
							(command "circle" Basepoint Baseradius "")
							(setq Basecircle (entlast))
							(setvar "osmode" 2875)
							(command "insert" "BLOCK777" "60" "60" pause)
							(command "erase" Basecircle "")
						)
					) ;BLOCK3 SET END Condition W
					;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
					((= CLIENT E)
						(setq Baseradius 6)
						(progn
							(command "circle" Basepoint Baseradius "")
							(setq Basecircle (entlast))
							(setvar "osmode" 2875)
							(command "insert" "BLOCK777" "60" "60" pause)
							(command "erase" Basecircle "")
						)
					) ;BLOCK3 SET END Condition E
					;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
				) ;BLOCK3 SET END Condition
			)
		) ;BLOCK3 TYPE Condition 7 ; TYPE7 [BLOCK7] [BLOCK77] [BLOCK777]
		;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
	)	
(command "layer" "s" oldlayer "") ;Layer back to previous;
(setvar "osmode" oldsnap) ;Snap Mode back to previous;
(princ)
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;            END Replace BLOCK (1-7 OPTIONS) Command            ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
0 Likes
Message 4 of 21

SeeMSixty7
Advisor
Advisor

Hi there. Looking at your code see that you are doing a lot of repetitive efforts. Functions are a great way to reduce your code, errors and make it more readable.

 

I adjusted your code based on what you had and guessed at some of the items you may be trying to accomplish.

I added 3 new functions

dxf utility function to get the assoc code of a entity data list

placeblock function to place the block for you. If you provide a rotation angle it will use it other wise it will pause for user input.

placeotherblock this one calls placeblock after prompting user for a specific action of which I did not see any difference.

I removed the circle placements as they seemed pointless Looks like you were trying to use these to place the block with or something. Not sure. The various radius coudl be applied still if needed, but you were erasing the circle when done anyway.

 

Take a look ask questions and let's see if we can get you on your way.

;;This is just a handy function
(defun dxf (code elist)
   (cdr (assoc code elist))
)
;this one will insert the block optional rotation prompt
(defun placeblock(blockname blockinspoint blockscale blockrotation)
	(setq lastent (entlast))
	(command "insert" blockname blockinspoint blockscale blockscale)
	(if blockrotation
		(command blockrotation)
		(command pause)
	)
	(if (= lastent (entlast))
		(setq rval (entlast))
		(setq rval nil)
	)
	rval
)
(defun placeotherblock (blockname blockinspoint blockscale blockrotation)
	(setq client (getint
				"Select type of Replacement: [1] Q-Same/Hard, [2] W-1' Set, [3] E-2' Set")
	)
    ;;if you really want to prompt for a keyword then use getkword with initget function
	(if client
		(progn
			(cond
				((= CLIENT 1)
					(placeblock blockname blockinspoint blockscale blockrotation)
				)
				((= CLIENT 2)
					;there does not seem to be any difference here
					(placeblock blockname blockinspoint blockscale blockrotation)
				) ;POLE SET END Condition W
				((= CLIENT 3)
					;there does not seem to be any difference here
					(placeblock blockname blockinspoint blockscale blockrotation)
				) ;POLE SET
			)
		)
		(princ "\nNo option selected:")
	)
)
(defun c:REPO ()
	(setvar "cmdecho" 1)
	(setq oldsnap (getvar "osmode")) ;Determine current Snap Mode;
	(setq oldlayer(getvar "clayer")) ;Determine current Layer;
	(command "-layer" "s" "LAYER322" "") ;Change to layer in which command will take action
	;(setvar "osmode" 64) ;Change Snap Mode to INSERTION only; Not needed we will get the ins point directly
	(setvar "osmode" 0) ;Change OSNAP to none
	(setq client (getint
	"Select type of Pole to Replace: [1] TYPE1, [2] TYPE2, [3] TYPE3, [4] TYPE4, [5] TYPE5, [6] TYPE6, [7] TYPE7")
	)
	(while (setq Basepoint (entsel "Select pole to replace"))
		(setq selectpoint (cadr basepoint)
			  selectedentity (car basepoint)
			  selecteddata (entget selectedentity)
			  basepoint (dxf 10 selecteddata)
			  baserotation (dxf 50 selecteddata);this is in radians
		)
		(placeblock (strcat "BLOCK" (itoa (* client 11))) basepoint 60.0 (/ baserotation (/ pi 180.0)))
		;;There does not seem to be any actual variation below are you planning to prompt for data attributes user rotation?
		(placeotherblock (strcat "BLOCK" (itoa (* client 111))) basepoint 60.0 (/ baserotation (/ pi 180.0)))
	)
	(command "layer" "s" oldlayer "") ;Layer back to previous;
	(setvar "osmode" oldsnap) ;Snap Mode back to previous;
	(princ)
)
Message 5 of 21

werner.bianca
Contributor
Contributor

When I first start trying to figure out how to program it(since I don't have much experience) I just make all the options the same to start and then make variations for each option for testing. Whatever works would them get simplified and applied by using setvar and other functions.
The main reason for the command is that we have a map of existing equipment. Some of them are being replaced, but there's 3 variations of installation. The idea was to make a lisp that would use the existing (BLOCK1) to get the base point. That one block would then be deleted and a remove (BLOCK11) inserted in it's place. After that the lisp prompts to ask which of the 3 types of installation is being done (this sets the radius of which the install (BLOCK111) has to be placed from the original point. Now the blocks should remain at 0 rotation in this case.
As you can see I'm struggling on a few parts of it. But I'm at trial and error stage at this point. I can't figure out if it's even a possibility for the command to use a block instead of a specific point as the base for the lisp. And to erase only the selected block. Cause if I can use the block to get the name, that would skip the first client selection and set up the rest of the command a bit better.
And then second, the circle part to place the install equipment was taken from another set of lisps I've used before that would set a circle down for the placement of the block, asking the client the distance and erasing the circle after the block placement. But my lisp is actually not even going that far, it starts the circle command and its not taking the radius imputed in the command and it wont prompt to the final block insertion.
I knew before I started trying to put this lisp together that it was going to be a challenge. But I know it'll help me understand the whole thing a lot better.
Thank you so much for taking the time to help! I truly appreciate it.
Going to try out your recommendations now, I'll keep you posted.

Happy Halloween!

Message 6 of 21

SeeMSixty7
Advisor
Advisor

It sounds like you are doing just fine! Keep plugging along and you will learn quite a bit more. There are so many helpful people on here to help you do just that.

 

Since you mentioned getting the blocks name would help. You can use the DXF 2 code to get just that from the 

(dxf 2 selecteddata) ; This equals the block name of the selected block.

 Do you think you still need the circle or is there more information we can get from the original block that we can use automatically? The more you can do without user input the better your accuracy will be, and less likely for errors.

 

Good luck,

Message 7 of 21

ВeekeeCZ
Consultant
Consultant

Since you're learning. You should use a standardized user prompts... Nice and clickable...

 

image.png

 

  (initget "1 2 3 4")
  (setq client (getint "Select type of Pole to Replace [type 1/type 2/type 3/type 4]: "))

For some reason, the result is still an integer!

Message 8 of 21

werner.bianca
Contributor
Contributor

Will DXF prompt it to select a block as reference or use whatever block is selected?
Cause the block insertion point determines the insertion of the following two blocks, and the name determines which block are being inserted after. As far as the 3 options for the last block, I'll have to keep them. But is there a way to limit the block insertion point to the distance radius without a circle?
The insertion point will vary between radius 6, 7 and 8, and the direction N, NE, E, SE, S, SW, W and NW. Would love to lock it into those angles if possible, maybe make a blocks of circle with the divisions of ranges (like the image attached).
That would take away the problem of the circle radius, I can just have a different block for each and have it deleted by the end of the command after the BLOCK111 is inserted?

0 Likes
Message 9 of 21

SeeMSixty7
Advisor
Advisor

"Will DXF prompt it to select a block as reference or use whatever block is selected?"

Using the code I sent you before with the dxf utility function

try this:

(defun dxf (code elist)
   (cdr (assoc code elist))
)
(defun c:getblockinfo()
(setq myblock (entsel "\nSelect Block:")) ; Allows you to select an entity (block is preferred but does not limit)
(if myblock ; this checks to see if anything was selected
(progn ; this is program block as the conditional will only execute one block for true and one optional for false
(setq myent (car myblock) ;gets the ename of the entity selected
mypt (cadr myblock);gets the point used to select the entity
mydata (entget myent) ; returns a list of dxf data associated with the entity
enttype (dxf 0 mydata) ; Entity type, for a block it will be INSERT there is a difference between a block definition and a block insert
entlayer (dxf 8 mydata) ; this is the layer of the entity (for a block the layer it is inserted on
entinspt (dxf 10 mydata) ; the insertion point of the inserted block
entscale (dxf 41 mydata) ; XScale factor of the block Y=42 and Z = 43
entrot (dxf 50 mydata) ; Rotation of the block in Radians (not degrees)
entname (dxf 2 mydata) ;Name of the block
enthand (dxf 5 mydata) ; this is the unique identifier in this drawing for this block you can use this to grab this entity later if needed.
);close setq
);close progn
);close if
);close defun


We didn't do anything with the getblockinfo routine other than assign variables but you can now see how to get those values and use them to your advantage.

 

"The insertion point will vary between radius 6, 7 and 8, and the direction N, NE, E, SE, S, SW, W and NW. "

Are you saying the block will be inserted with a rotation based on the radius and inserted at a point based on that radius? Is the block a directional item that you  place on the circular block? If might be useful to provide a dwg that shows the initial state and then a sample of what it would look like when done.

 

Message 10 of 21

werner.bianca
Contributor
Contributor

Had to pause the work on this lisp, cause I'm pretty sure I made a mistake when I combined the lisps.

The command is following through the stages, but nothing is being inserted. And I can't find where I made the mistake. 😖

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun dxf (code elist)
   (cdr (assoc code elist))
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;        Replace BLOCK (1-7 OPTIONS) Command        ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun c:BLOCKREP ()
(setq oldsnap (getvar "osmode") ;Determine current Snap Mode;
		oldlayer (getvar "clayer") ;Determine current Layer;
		ExBlock (entsel "Select block being replaced:"));
	(progn
		(setq myent (car ReBlock);gets the ename of the entity selected
			mypt (cadr ReBlock);gets the point used to select the entity
			entinspt (dxf 10 mydata);the insertion point of the inserted block
			entname (dxf 2 mydata);name of the block
			enthand (dxf 5 mydata);
		)
	)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
	(if (= entname "BLOCK1")
		(setq ReBlock "BLOCK11"
			InBlock "BLOCK111")
	)
	(if (= entname "BLOCK2")
		(setq ReBlock "BLOCK22"
			InBlock "BLOCK222")
	)
	(if (= entname "BLOCK3")
		(setq ReBlock "BLOCK33"
			InBlock "BLOCK333")
	)
	(if (= entname "BLOCK4")
		(setq ReBlock "BLOCK44"
			InBlock "BLOCK444")
	)
	(if (= entname "BLOCK5")
		(setq ReBlock "BLOCK55"
			InBlock "BLOCK555")
	)
	(if (= entname "BLOCK6")
		(setq ReBlock "BLOCK66"
			InBlock "BLOCK666")
	)
	(if (= entname "BLOCK7")
		(setq ReBlock "BLOCK77"
			InBlock "BLOCK777")
	)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(setvar "osmode" 64) ;Change Snap Mode to INSERTION only;
(command "layer" "s" "0" "") ;Change to layer in which command will take action
(command "insert" ReBlock entinspt "1" "1" 0)
(initget "1 2 3")
(setq client (getint "Select type of Replacement: [1' Set/2' Set/3 Same-Hard]: "))
	(cond ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
		((= CLIENT 1)
			(setq Baseradius 7)
			(progn
				(command "insert" "Radius7" entinspt "1" "1" 0)
				(setq Basecircle (entlast))
				(setvar "osmode" 512)
				(command "insert" InBlock "1" "1" pause)
				(command "erase" Basecircle "")
			)
		) ;BLOCK SET END Condition 1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
		((= CLIENT 2)
			(setq Baseradius 8)
			(progn
				(command "insert" "Radius8" entinspt "1" "1" 0)
				(setq Basecircle (entlast))
				(setvar "osmode" 512)
				(command "insert" InBlock "1" "1" pause)
				(command "erase" Basecircle "")
			)
		) ;BLOCK SET END Condition 2
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
		((= CLIENT 3)
			(setq Baseradius 6)
			(progn
				(command "insert" "Radius6" entinspt "1" "1" 0)
				(setq Basecircle (entlast))
				(setvar "osmode" 512)
				(command "insert" InBlock "1" "1" pause)
				(command "erase" Basecircle "")
			)
		) ;BLOCK SET END Condition 3
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
	) ;BLOCK SET END Condition
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(command "layer" "s" oldlayer "") ;Layer back to previous;
(setvar "osmode" oldsnap) ;Snap Mode back to previous;
(princ)
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;      END Replace BLOCK (1-7 OPTIONS) Command      ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
0 Likes
Message 11 of 21

ronjonp
Mentor
Mentor

One thing that stands out is 'reblock' does not exist .. should be 'exblock' ? Also, where is 'mydata' being set?

image.png

You could also simplify all the if statements setting 'reblock' & 'inblock' to this:

(if (wcmatch (strcase entname) "BLOCK#")
  (setq	reblock	(strcat entname (setq n (substr entname (strlen entname))))
	inblock	(strcat reblock n)
  )
)

 

Message 12 of 21

werner.bianca
Contributor
Contributor

Thank you, I'm slowly going blind with the codes.
At one point it worked to inset the blocks, but I lost track of my changes to the code. Cause then I wasn't using the original block as a reference to determine the following steps.

However, it was not placing the radius block on the correct point.


It still won't work. Nothing is getting inserted, but it is asking me the question for the second stage of the command.  I'm getting the following message:

 


Command: BLOCKREP
Select block being replaced:layer
Current layer: "0"
Enter an option [?/Make/Set/New/Rename/ON/OFF/Color/Ltype/LWeight/TRansparency/MATerial/Plot/Freeze/Thaw/LOck/Unlock/stAte/Description/rEconcile/Xref]: s
Enter layer name to make current or <select object>: 0 Enter an option [?/Make/Set/New/Rename/ON/OFF/Color/Ltype/LWeight/TRansparency/MATerial/Plot/Freeze/Thaw/LOck/Unlock/stAte/Description/rEconcile/Xref]:
Command: insert Enter block name or [?]:
Command:
Command: 1 Unknown command "1". Press F1 for help.
Command: 1 Unknown command "1". Press F1 for help.
Command: 0
Command: Select type of Replacement: [1' Set/2' Set/3 Same-Hard]: 1 insert Enter block name or [?]: Radius7
Units: Unitless Conversion: 1.0000
Specify insertion point or [Basepoint/Scale/X/Y/Z/Rotate]:
Command: 1 Unknown command "1". Press F1 for help.
Command: 1 Unknown command "1". Press F1 for help.
Command: 0
Command: insert Enter block name or [?]:
Command: 1 Unknown command "1". Press F1 for help.
Command: 1 Unknown command "1". Press F1 for help.
Command: *Cancel*

0 Likes
Message 13 of 21

ronjonp
Mentor
Mentor

The easiest way to describe what you are trying to accomplish would be to post a drawing that has your blocks and a before and after.

Message 14 of 21

SeeMSixty7
Advisor
Advisor

You seemed to have copy and pasted some from here and some from there. So quite a bit does not flow.

 

This is a rough reform of what you had. I created a couple of association lists to avoid the multiple ifs or conditional blocks. 

Take a look and let me know what needs tweaking. I assumed the pause in the insert command was actually for the insertion point. is that correct?

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun dxf (code elist)
   (cdr (assoc code elist))
)

(defun placemyblockset(radiusinfo pbsinblock pbsreblock inspoint)
	(setq Baseradius (nth 1 radiusinof))
	(command "insert" (nth 2 radiusinfo inspoint "1" "1" 0)
	(setq Basecircle (entlast))
	(setvar "osmode" 512)
	(command "insert" pbsInBlock pause "1" "1" 0); Thsi pauses for insertion point and uses 0 rotation
	(entdel basecircle)
	(setq lastent (entlast))
	(command "insert" pbsreblock inspoint 1 1 0)
)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;        Replace BLOCK (1-7 OPTIONS) Command        ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun c:BLOCKREP ()
	(setq oldsnap (getvar "osmode") ;Determine current Snap Mode;
	  	  oldlayer (getvar "clayer") ;Determine current Layer;
		  ExBlock (entsel "Select block being replaced:")
		  mydata (entget (car exblock))
		  entblkname (dxf 2 mydata);name of the block
		  entblkhand (dxf 5 mydata);
		  blocklist (list (list "BLOCK1" "BLOCK11" "BLOCK111"); Create an Association list for your blocks
						  (list "BLOCK2" "BLOCK22" "BLOCK222")
						  (list "BLOCK3" "BLOCK33" "BLOCK333")
						  (list "BLOCK4" "BLOCK44" "BLOCK444")
						  (list "BLOCK5" "BLOCK55" "BLOCK555")
						  (list "BLOCK6" "BLOCK66" "BLOCK666")
						  (list "BLOCK7" "BLOCK77" "BLOCK777")
					  )
		  entinspt (dxf 10 mydata);the insertion point of the inserted block
		  reblock (nth 1 (assoc entblkname (blocklist)))
		  inblock (nth 2 (assoc entblkname (blocklist)))
	)
	(setvar "osmode" 64) ;Change Snap Mode to INSERTION only;
	(command "layer" "s" "0" "") ;Change to layer in which command will take action
	(command "insert" ReBlock entinspt "1" "1" 0)

	(initget "1 2 3")
	(setq client (getint "Select type of Replacement: [1' Set/2' Set/3 Same-Hard]: ")
		  baseassoclist (list (list 1 7 "Radius7") (list 2 8 "Radius8") (list 3 6 "Radius6"))
	)
	(placemyblockset (assoc client baseassoclist) inblock reblock entinspt)) 

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
	(command "layer" "s" oldlayer "") ;Layer back to previous;
	(setvar "osmode" oldsnap) ;Snap Mode back to previous;
	(princ)
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;      END Replace BLOCK (1-7 OPTIONS) Command      ;;;;;
0 Likes
Message 15 of 21

werner.bianca
Contributor
Contributor

Here is the file I'm using to test the lisp.
Added the idea behind it on a step by step in the drawing as you can see on the image below:

image.png

0 Likes
Message 16 of 21

werner.bianca
Contributor
Contributor

That block list made the code so clean! Thank you! I wasn't sure how to do that.

 

Added a couple parenthesis that were missing because it wouldn't load, but still getting the following error:

Command: BLOCKREP
Select block being replaced:; error: syntax error

 

 

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun dxf (code elist)
   (cdr (assoc code elist))
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun placemyblockset(radiusinfo pbsinblock pbsreblock inspoint)
	(setq Baseradius (nth 1 radiusinof))
	(command "insert" (nth 2 radiusinfo inspoint "1" "1" 0))
	(setq Basecircle (entlast))
	(setvar "osmode" 512)
	(command "insert" pbsInBlock pause "1" "1" 0); Thsi pauses for insertion point and uses 0 rotation
	(entdel basecircle)
	(setq lastent (entlast))
	(command "insert" pbsreblock inspoint 1 1 0)
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;        Replace BLOCK (1-7 OPTIONS) Command        ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun c:BLOCKREP ()
	(setq oldsnap (getvar "osmode") ;Determine current Snap Mode;
	  	  oldlayer (getvar "clayer") ;Determine current Layer;
		  ExBlock (entsel "Select block being replaced:")
		  mydata (entget (car exblock))
		  entblkname (dxf 2 mydata);name of the block
		  entblkhand (dxf 5 mydata);
		  blocklist (list (list "BLOCK1" "BLOCK11" "BLOCK111"); Create an Association list for your blocks
						  (list "BLOCK2" "BLOCK22" "BLOCK222")
						  (list "BLOCK3" "BLOCK33" "BLOCK333")
						  (list "BLOCK4" "BLOCK44" "BLOCK444")
						  (list "BLOCK5" "BLOCK55" "BLOCK555")
						  (list "BLOCK6" "BLOCK66" "BLOCK666")
						  (list "BLOCK7" "BLOCK77" "BLOCK777")
					  )
		  entinspt (dxf 10 mydata);the insertion point of the inserted block
		  reblock (nth 1 (assoc entblkname (blocklist)))
		  inblock (nth 2 (assoc entblkname (blocklist)))
	)
	(setvar "osmode" 64) ;Change Snap Mode to INSERTION only;
	(command "layer" "s" "0" "") ;Change to layer in which command will take action
	(command "insert" ReBlock entinspt "1" "1" 0)

	(initget "1 2 3")
	(setq client (getint "Select type of Replacement: [1' Set/2' Set/3 Same-Hard]: ")
		  baseassoclist (list (list 1 7 "Radius7") (list 2 8 "Radius8") (list 3 6 "Radius6"))
	)
	(placemyblockset (assoc client baseassoclist) inblock reblock entinspt) 

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
	(command "layer" "s" oldlayer "") ;Layer back to previous;
	(setvar "osmode" oldsnap) ;Snap Mode back to previous;
	(princ)
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;      END Replace BLOCK (1-7 OPTIONS) Command      ;;;;;

 

0 Likes
Message 17 of 21

ronjonp
Mentor
Mentor

Give this a try. The second block inserted is offset at +5 XY. Next is logic on what dictates 6', 7' or 8' radius.

(defun c:foo (/ el i n s)
  ;; RJP » 2019-11-05
  (if (setq s (ssget ":L" '((0 . "insert") (2 . "BLOCK#"))))
    (foreach e (vl-remove-if 'listp (mapcar 'cadr (ssnamex s)))
      (setq n (cdr (assoc 2 (setq el (entget e)))))
      (if (tblobjname "block" (setq n (strcat n (setq i (substr n (strlen n))))))
	(entmod (append el (list (cons 2 n))))
	(princ (strcat "\nBlock '" n "' not defined in drawing..."))
      )
      (if (tblobjname "block" (setq n (strcat n i)))
	(entmakex (list	'(0 . "INSERT")
			(assoc 8 el)
			(cons 2 n)
			(mapcar '+ (assoc 10 el) '(0 5 5 5))
			(assoc 50 el)
		  )
	)
	(princ (strcat "\nBlock '" n "' not defined in drawing..."))
      )
    )
  )
  (princ)
)

 2019-11-05_12-19-53.gif

Message 18 of 21

SeeMSixty7
Advisor
Advisor
Accepted solution

Here is more along the lines you were headed with a few tweaks hopefully to help you learn. @ronjonp has created you a  much more condensed routine. I assumed you were going to use varying block names so that's why you didn't use the multipliers in the block name. I also replaced your Radius block with a 1R block. No need to have multiple temp blocks the sclae will control the radius of the 1R circle block. It's attached in your sample drawing.

 


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (defun dxf (code elist) (cdr (assoc code elist)) ) (defun placemyblockset(radiusinfo pbsinblock pbsreblock inspoint) (setq Baseradius (nth 1 radiusinfo)) (command "insert" "ReferenceRadius" inspoint baseradius baseradius 0) (setq Basecircle (entlast)) (setvar "osmode" 512) (command "insert" pbsInBlock pause "1" "1" 0); Thsi pauses for insertion point and uses 0 rotation (entdel basecircle) (setq lastent (entlast)) (command "insert" pbsreblock inspoint 1 1 0) ) (defun c:BLOCKREP () (setq oldsnap (getvar "osmode") ;Determine current Snap Mode; oldlayer (getvar "clayer") ;Determine current Layer; ExBlock (entsel "Select block being replaced:") mydata (entget (car exblock)) entblkname (dxf 2 mydata);name of the block entblkhand (dxf 5 mydata); blocklist (list (list "BLOCK1" "BLOCK11" "BLOCK111"); Create an Association list for your blocks (list "BLOCK2" "BLOCK22" "BLOCK222") (list "BLOCK3" "BLOCK33" "BLOCK333") (list "BLOCK4" "BLOCK44" "BLOCK444") (list "BLOCK5" "BLOCK55" "BLOCK555") (list "BLOCK6" "BLOCK66" "BLOCK666") (list "BLOCK7" "BLOCK77" "BLOCK777") ) entinspt (dxf 10 mydata);the insertion point of the inserted block reblock (nth 1 (assoc entblkname blocklist)) inblock (nth 2 (assoc entblkname blocklist)) ) (setvar "osmode" 64) ;Change Snap Mode to INSERTION only; (command "layer" "s" "0" "") ;Change to layer in which command will take action (command "insert" ReBlock entinspt "1" "1" 0) (entdel (dxf -1 mydata)) (initget "1 2 3") (setq client (getint "Select type of Replacement: [1' Set/2' Set/3 Same-Hard]: ") baseassoclist (list (list 1 7) (list 2 8) (list 3 6)) ) (placemyblockset (assoc client baseassoclist) inblock reblock entinspt) (command "layer" "s" oldlayer "") ;Layer back to previous; (setvar "osmode" oldsnap) ;Snap Mode back to previous; (princ) )
Message 19 of 21

werner.bianca
Contributor
Contributor

OMG! Perfect!

Thank you sooooo much!

Message 20 of 21

SeeMSixty7
Advisor
Advisor

Glad to hear that worked out!

0 Likes