Jump to content

Renaming multiple blocks


shehab10

Recommended Posts

Hi, i have a blocks of Door,Window and furniture that i want to rename them once for all by deleting all characters after "mm" and Prefix starts with "_M"

Ex:"M_Single-Flush - 0915 x 2134mm-180048-Level 1" To Single-Flush - 0915 x 2134mm

as well as windows and Furniture

I attached a very simple dwg that anyone can test on it for me.

 

To be more specific :

1-I want to rename as mentioned all blocks once for all by selection or by Whole drawing "X"

2-i want to have possibility to add list (custom) like deleting character after word "Breuer" same case as "mm"

 

small lisp (copied) but missing funtions that i mentioned above :

 

(defun c:test (/ DATA I NEW OLD SS)
 (if (and (setq ss (ssget "_+.:E:S" '((0 . "INSERT"))));; select single insert
   (setq data (entget (ssname ss 0)));; object definition data
   (setq old (cdr (assoc 2 data)));; block name
   (not (assoc 1 (tblsearch "BLOCK" old)));; not Xref
   (setq i (vl-string-search "mm" old));; mm position
   (setq new (substr old 1 (+ i 2)));; new name
   (not (tblsearch "BLOCK" new));; search if name exists
     );; and
    (command "._rename" "_block" old new)
   );; if
 (princ)
 );; test

 

 

Thanks

sample.dwg

Link to comment
Share on other sites

Welcome to CADTutor shehab10!

 

This code lines remind me something...

 

The problem is that your blocks, often have the same name, excluding the ID and the Level, and AutoCAD does not allow blocks with the same name,

one possible way, is to only remove the Level part from the block name, if suitable, here it is

 

(defun c:test (/ DATA I N NEW OLD SS)
 (if (setq ss  (ssget "_X" '((0 . "INSERT"))));; select insert
   (progn
     (setq n (sslength ss));; sets n with the selection set lenght
     (while (not (minusp (setq n (1- n))));; while n not negative, set n -1
(if (and (setq data (entget (ssname ss n)));; object definition data
  (setq old (cdr (assoc 2 data)));; block name
  (not (assoc 1 (tblsearch "BLOCK" old)));; not Xref
  (setq i (vl-string-search "Level" old));; Level position
  (setq i (1- i));; - before Level
  (setq new (substr old 1 i));; new name removing the level
  (not (tblsearch "BLOCK" new));; search if name exists, and if not
    );; and
  (command "._rename" "_block" old new);; rename the block
);; if
     );; while
   );; progn
 );; if
 (princ)
);; test

 

hope that helps

Henrique

Edited by hmsilva
Code fix
Link to comment
Share on other sites

Yope hmsilva it reminds me you in other places :D , my blocks will not have the same name because revit does not allow two families (blocks) to have the same name adding to that i expect the lisp will have functionality to skip one of two objects have the same name or exception to eliminate the dealing with two blocks have the same name as routine that can be written in lisp (Forgive me i am just guessing :D i do not know lisp so much).

 

i experimented m instead of level, it did remove mm (i just may need it for identifying unit however if it's tedious in lisp it's not so important)

i added word "Breuer" besides "m" as list for generic words to remove character after but no way it is not working!

Also could you add to me line of code that can be added to the above code to remove prefix M_ (i will use it as extra option for abbreviate my block name) ?

Link to comment
Share on other sites

What about prefix "M_" that i want to remove it and anything before it if there was something before it?

 

Perhaps something like this

 

(defun c:test (/ DATA I II N NEW OLD SS)
 (if (setq ss (ssget "_X" '((0 . "INSERT"))));; select insert
   (progn
     (setq n (sslength ss));; sets n with the selection set lenght
     (while (not (minusp (setq n (1- n))));; while n not negative, set n -1
(if (and (setq data (entget (ssname ss n)));; object definition data
  (setq old (cdr (assoc 2 data)));; block name
  (not (assoc 1 (tblsearch "BLOCK" old)));; not Xref
  (setq i (vl-string-search "Level" old));; Level position
  (setq i (1- i));; - before Level
  (if (setq ii (vl-string-search "M_" old));; M_ position
    (setq ii (+ ii 3));; after M_ position
    (setq ii 1);;if not M_ position
    );; if
  (setq new (substr old ii i));; new name removing the level
  (not (tblsearch "BLOCK" new));; search if name exists, and if not
    );; and
  (command "._rename" "_block" old new);; rename the block
);; if
     );; while
   );; progn
 );; if
 (princ)
);; test

 

Henrique

Link to comment
Share on other sites

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