Jump to content

Recommended Posts

Posted

Hi all,

I am dealing with drawings having almost the same block structure but different names (in this case blocks are mostly furniture like a chair, table etc). 
I want all the same block structure to be identified as one name for which I think block replace program will work.
I have one such program which I am attaching in this post (BRE.lsp)  but it is not so effective as it does not retain the position same as the original block and also it asks to select every reference of the block to be replaced. 
What I need is that the program asks the user to select the one reference of the block which user want to replace( as names are very complicated for the block in this case so picking block by mouse will be handy ) and then prompt for the replacement block by selection, retaining position as well as scale, rotation,other properties, etc same as the original block.

I am also attaching the sample dwg which has chairs and table similar in structure but have different names.
Any help will be appreciated 
Thanks

BRE.lsp

BRsample.dwg

Posted

you could try this one but haven't used or tested it much and it is limited to one block name at the time. Had on my wish list to make option to make something like , hey appie , this is my drawing folder and this this where I have my new blocks , go get'm all... but unfortunately haven't got the time to do so at this moment. Use at own risk and do so first on a few test drawings. If it works , fine , if it doesn't ... can't do anything about it at this time.

 

 

 

  • Like 1
Posted (edited)

Just notice that some chairs are pointing up, some are pointing down when you set rotation = 0 to both. The lisp program can't see when to add 180° to the destination block.

 

For example: you can replace Chair B by Chair F, but chair  A and chair H must be rotated 180°.

 

Any idea on how you want this handled?

 

----

 

Anyway, here is a first version.

First click the block "to be replaced by".

Then I put the "to be replaced" in a while loop.

 

Command RB (for replace blocks)

 

Are you happy with this, or do you, instead of this while loop, want every block to be replaced?  Not sure if I understood your request exactly.

Also, I assume X, Y and Z scale are uniform.  And the blocks are not dynamic.  Else this needs a little more code.

 


(vl-load-com)

(defun _InsertBlock (blockname ip lay sc rot / doc modelSpace insertionPnt blockRefObj clay)

  (setq clay (getvar "CLAYER"))
  (setvar "CLAYER" lay)
 
  (setq acadObj (vlax-get-acad-object))
  (setq doc (vla-get-ActiveDocument acadObj))

  ;; Insert the block
  (setq insertionPnt (vlax-3d-point ip))
  (setq modelSpace (vla-get-ModelSpace doc))
  (setq blockRefObj (vla-InsertBlock modelSpace insertionPnt blockname sc sc sc rot))
 
  (setvar "CLAYER" clay)
    
)

(defun readblock (ent / name ip lay sc rot)
  (list
    (setq name (cdr (assoc 2  (entget ent))))
    (setq ip   (cdr (assoc 10 (entget ent))))
    (setq lay  (cdr (assoc 8  (entget ent))))
    (setq name (cdr (assoc 41 (entget ent))))
    (setq rot  (cdr (assoc 50 (entget ent))))
  )
)

;; Replace Block
(defun c:rb ( / src dst blk)
 
  ;; feel free to change the prompt if it isn't clear
  (setq src (readblock (car (entsel "\nSelect source block, to be replaced by: "))))
 
  (while (setq dst (readblock (setq blk (car (entsel "\nSelect destination block, to replace: ")))))
    (_InsertBlock
      (nth 0 src)
      (nth 1 dst)
      (nth 2 dst)
      (nth 3 dst)
      (nth 4 dst)
    )
    (entdel blk)
  )
)

 

 

Edited by Emmanuel Delay
Posted

Here's another lightly tested with your sample drawing:

(defun c:foo (/ a b d e s z nm)
  (cond	((and (setq a (car (entsel "\nPick block to copy: ")))
	      (setq b (car (entsel "\nPick block to replace: ")))
	      (= "INSERT" (cdr (assoc 0 (entget a))) (cdr (assoc 0 (entget b))))
	      (setq s (ssget "_X" (list '(0 . "insert") (assoc 2 (entget b)))))
	 )
	 (setq nm (cdr (assoc 2 (entget a))))
	 (foreach c (mapcar 'vlax-ename->vla-object (mapcar 'cadr (ssnamex s)))
	   (cond ((vlax-write-enabled-p c)
		  (vla-getboundingbox c 'd 'z)
		  (vla-put-name c nm)
		  (vla-getboundingbox c 'e 'z)
		  (or (equal (vlax-safearray->list d) (vlax-safearray->list e) 1e-4)
		      (vla-put-rotation c (+ pi (vla-get-rotation c)))
		  )
		 )
	   )
	 )
	)
  )
  (princ)
)

 

  • Thanks 1
Posted

@rlx

Thanks, you have put so much effort and time in making this routine.

Posted (edited)
27 minutes ago, AbdRF said:

@rlx

Thanks, you have put so much effort and time in making this routine.

 

That's correct 😓 and most time went into trying to make Lee Mac's block preview work 🤪. Lots of 'trans' & matrix stuff in there. And till this day still don't completely or really understand everything haha. Wrote this for a colleague and I don't think he has ever used it. And I admit , it really is a dragon of a program , lots of options but maybe too much... I wouldn't want to call it a complete waste of time but I also wouldn't want to call it one of my best of most useful programs either in terms of how often I or someone else has used it. Guess its like my toolbox in the garage , I use my cheap screwdrivers all the time but my expensive sawing table once or twice... 

Edited by rlx
  • Like 1
Posted

Hi @Emmanuel Delay

Thanks for looking into it.
I want to replace every instance of the block. Most of the time the blocks are static.
But I am curious to know how can we make this routine work for dynamic blocks.

Also, I was stuck with how to deal with different chair orientation pointing but @ronjonp routine comes to my rescue to some extent.
Thanks, everyone for helping me out @rlx @Emmanuel Delay and @ronjonp

Posted

@rlx

You are simply amazing helping people out with their stuff. It is better to use cheap screwdrivers most of the time haha 😀

Posted
2 minutes ago, AbdRF said:

@rlx

You are simply amazing helping people out with their stuff. It is better to use cheap screwdrivers most of the time haha 😀

 

now you make me blush 😊 .. but the real champ is Lee Mac

  • Like 1
Posted
9 hours ago, rlx said:

 

now you make me blush 😊 .. but the real champ is Lee Mac

 

:beer:

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...