shehab10 Posted August 25, 2013 Share Posted August 25, 2013 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 Quote Link to comment Share on other sites More sharing options...
hmsilva Posted August 25, 2013 Share Posted August 25, 2013 (edited) 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 August 26, 2013 by hmsilva Code fix Quote Link to comment Share on other sites More sharing options...
shehab10 Posted August 26, 2013 Author Share Posted August 26, 2013 Yope hmsilva it reminds me you in other places , 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 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) ? Quote Link to comment Share on other sites More sharing options...
Tharwat Posted August 26, 2013 Share Posted August 26, 2013 (if (setq ss "_X" (ssget '((0 . "INSERT"))));; select insert Henrique , you have added the mode string before the function ssget Quote Link to comment Share on other sites More sharing options...
hmsilva Posted August 26, 2013 Share Posted August 26, 2013 Good catch, Tharwat Already fixed, yesterday, I was almost asleep... Quote Link to comment Share on other sites More sharing options...
shehab10 Posted August 27, 2013 Author Share Posted August 27, 2013 What about prefix "M_" that i want to remove it and anything before it if there was something before it? Quote Link to comment Share on other sites More sharing options...
hmsilva Posted August 27, 2013 Share Posted August 27, 2013 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.