Block Replace Tool
Johandre 05 Mar 2020
I think it would be handy to have a replace-block feature where it's possible to change out one block for another.
I found this LISP code, but get "error: invalid SSGET mode string" when I try it:
Something like AutoCAD's BLOCKREPLACE may be a good start, but it replaces all blocks, where I would like to select which blocks to replace.
If anybody has a working script, I'd really appreciate it, and if there are any plans to include this in nanoCAD officially, you have my vote!
I found this LISP code, but get "error: invalid SSGET mode string" when I try it:
(defun c:QW4 (/ ss nbl) (prompt "\nSelect block: ") (if (setq ss (ssget "_:S:E" '((0 . "INSERT")))) (progn (setq ss (entget (setq ss (ssname ss 0)))) (redraw (cdr (assoc 330 ss)) 3) (prompt "\nSelect blocks to be replaced: " ) (while (setq nbl (ssget "_:S:E" '((0 . "INSERT")))) (setq nbl (entget (setq nbl (ssname nbl 0)))) (entmod (subst (assoc 2 nbl) (assoc 2 ss) ss ) ) (redraw entBlock 4) ) ) ) (princ) ) (prompt "Type >> Qw4 <<")
Something like AutoCAD's BLOCKREPLACE may be a good start, but it replaces all blocks, where I would like to select which blocks to replace.
If anybody has a working script, I'd really appreciate it, and if there are any plans to include this in nanoCAD officially, you have my vote!
Johandre 05 Mar 2020
I found this version that works. Does anybody know of a script that gives me a dialogue box instead of having to type the block names?
(defun c:Qw4 (/ Jr_replaceall answr ent idx nbl obj ss) (vl-load-com) (if (not Jr_replaceall) (setq Jr_replaceall "Single") ) (Command "-.Undo" "_Be") (if (and (setq ss (ssget ":S" '((0 . "INSERT")))) (progn (initget "S A") (if (setq answr (getkword "\nReplace only this block or replace All [Single / All]:")) (setq Jr_replaceall answr) (setq answr Jr_replaceall) ) ) (setq nbl (getstring "\nBlock name to replace with: ")) (tblobjname "BLOCK" nbl) ) (progn (if (eq Jr_replaceall "A") (setq ss (ssget "x" (list '(0 . "INSERT") (assoc 2 (entget (ssname ss 0)))))) ) (setq idx -1) (while (setq ent (ssname ss (setq idx (1+ idx)))) (setq obj (vlax-ename->vla-object ent)) (vla-put-name obj nbl) (vla-update obj) ) ) ) (command "_.Undo" "_End") (princ (strcat "\nReplaced " (itoa idx) " Blocks")) (princ) )
Johandre 06 Mar 2020
One step ahead of you! Once I get the hang of it more, I'll try DCL files with my LSP ones to see if that works.
I'm not quite there yet, but a dialogue box is less important than the fact there is a functioning tool available already.
I'm not quite there yet, but a dialogue box is less important than the fact there is a functioning tool available already.
pguimber 06 Mar 2020
Johandre, on 06 March 2020 - 11:48 AM, said:
One step ahead of you!
On this subject, anyway I suck!
hardly good at copying other people's code !
For example to list the coordinates of the points I use ptexport.lsp. I can change decimals but that's it.
I can do scripts, but it's really not my first skill.
Spoiler
Johandre, on 06 March 2020 - 11:48 AM, said:
is less important than the fact there is a functioning tool available already
So much the better !
Kreator 06 Mar 2020
BTW, you can use SPOILER and SQL BBCodes (LSP not available, CODE doesn't fit) formatting to make code more readable and compact
Spoiler
pguimber 06 Mar 2020
Ok, thank's...
Indeed it is more sympathetic!
It's clean and easy to read. Thank you
Indeed it is more sympathetic!
It's clean and easy to read. Thank you
Spoiler