Jump to content

Recommended Posts

Posted

Hi, I am trying to find the most simple way to use Blockreplace or Replace command. I know when you type Replace then Enter it asks you to select the block you want to replace it with but you have to type "=" then Enter to be able to select the block. THEN you have to select another block but still have to type "=" then Enter and select it... I'm trying to create a lisp code similar to this...

 

 

(Defun C:RB1 (/ SS )

(SetQ SS (SSGet))

(Command "Replace" "=" SS SS "Y")

)

[code]

 

 

Sorry if it did not wrap the code but I did click the "#" button and it did nothing. I can't remember how to wrap code in here. Wish there was an example.

Posted

Hi, I am trying to find the most simple way to use Blockreplace or Replace command. I know when you type Replace then Enter it asks you to select the block you want to replace it with but you have to type "=" then Enter to be able to select the block. THEN you have to select another block but still have to type "=" then Enter and select it... I'm trying to create a lisp code similar to this...

 

 

:

(Defun C:RB1 (/ SS )

(SetQ SS (SSGet))

(Command "Replace" "=" SS SS "Y")

)

/[code]

 

 

Sorry if it did not wrap the code but I did click the "#" button and it did nothing. I can't remember how to wrap code in here. Wish there was an example.

Posted

Hi DJ. For the code tags...

[code]
Your code here
[/code]

 

 

As a side note, in your try you substitute the old block for the same old block.

(Command "Replace" "=" SS SS "Y")

Also the way that function works, when you have to tell cad with what block you want to replace the original with, either you provide a string with the name of the block, or hit "=" and make a selection.

 

As for using the replace command, I found out that that command have a very weird behavior (using 2015 here). When you launch "replace" it launches the "-BLOCKREPLACE" command. The strange thing is that I get this message "Unknown command "-BLOCKREPLACE". Press F1 for help." no matters the method I tried (command/command-s/vl-cmdf "-BLOCKREPLACE"). (same for trying to use "REPLACE" as a command/command-s or vl-cmdf). That is the 1rst time I see that kind of behavior. Basically what it seems to mean is that you might have to "mimic" the whole replace command. I'd help further but i'm in a hurry.

Posted

Hi Jef,

 

 

What I am trying to do with that command is click new block I am trying to replace with an existing one. Rather than deleting the old one, renaming the new one, and moving it to the insert point. I just want to know if there is a way to tell it "ok pause for a minute while I select the new block then select the old block". It asks me to press "="

Posted
Great stuff Tharwat!!!

 

Thank you halam. Happy to hear that.

Posted

I have been having some problems with replacing blocks with lisp too,

Biggest problem was to replace a NON-annotative block for a annotative block.

I managed to fix this with a quite simple work-around.

 

- Get the coordinates of the block

- Insert new block on those coordinates

- Delete old block

That way to never have any problem with annotations.

 

; setq oldblocksome in a way you like first...
; setq newblocksome in a way you like first...

(if (/= newblockname "")
(progn
(setq blockobjecten (ssget "_X" (list (cons 0 "INSERT")(cons 2 oldblockname))))
(setq n (sslength blockobjecten))
	(repeat n
		(setq ensel (ssname blockobjecten (setq n (1- n))))  
		(setq enlist (entget ensel))		;; Set DXF group codes          
		(setq xyz (cdr (assoc 10 enlist)))	;; Set coordinates
		(command "-insert" newblockname xyz "1" "1" "")
	)
	(command "ERASE" blockobjecten "")
)
)

 

(This a a global replace code)

  • 3 weeks later...

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...