Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 02/12/2019 in all areas

  1. Look here ==> https://www.cadtutor.net/forum/topic/66534-layout-rename-fail/?tab=comments#comment-545615
    1 point
  2. Toolbars will be a thing of the past. The classic interface will soon be called obsolete. So many programs utilize the ribbon. Do they have "classic" toolbars that a user can switch to? Resistance is futile.
    1 point
  3. If you want to reliably rename layouts (or indeed any collection in which the item name constitutes a primary key and therefore must be unique), you will need to first rename the items to a temporary placeholder which is guaranteed to be unique within the current set and also unique within the target set. For example, with the code posted so far in this thread, there is no test as to whether the target name is already used by another item in the collection. Hence, if you were to run the program, reorder the layouts or delete & add a new layout with the same name, then the next run of the program would fail. This is because each layout is individually renamed as the code iterates over a set, and therefore every renaming operation must ensure that the target name does not conflict with another item in the set. Furthermore, you cannot guarantee that the order in which the layouts appear in the layout collection will match the order of layouts in a drawing (hence the purpose of the taborder property). One way to achieve a reliable rename is as follows: ;; Renumber Layouts - Lee Mac ;; Sequentially numbers all Paperspace layouts, with an optional prefix & suffix. (defun c:rl ( / int lst lyn ord pre sed suf ) ;; Obtain a valid (optional) prefix & suffix (setq pre (validstring "\nSpecify prefix <none>: ") suf (validstring "\nSpecify suffix <none>: ") lyn (list (strcase pre)) ) ;; Obtain list of layout objects, current names, and sort index (vlax-for lyt (vla-get-layouts (vla-get-activedocument (vlax-get-acad-object))) (if (= :vlax-false (vla-get-modeltype lyt)) (setq lst (cons lyt lst) lyn (cons (strcase (vla-get-name lyt)) lyn) ord (cons (vla-get-taborder lyt) ord) ) ) ) ;; Construct a unique seed for temporary renaming (setq sed "%") (while (vl-some '(lambda ( x ) (wcmatch x (strcat "*" sed "*"))) lyn) (setq sed (strcat sed "%")) ) ;; Temporarily rename layouts to ensure no duplicate keys when renumbering (setq int 0) (foreach lyt lst (vla-put-name lyt (strcat sed (itoa (setq int (1+ int))))) ) ;; Rename layouts in tab order, with prefix & suffix (setq int 0) (foreach idx (vl-sort-i ord '<) (vla-put-name (nth idx lst) (strcat pre (padzeros (itoa (setq int (1+ int))) 2) suf)) ) (princ) ) (defun padzeros ( str len ) (if (< (strlen str) len) (padzeros (strcat "0" str) len) str) ) (defun validstring ( msg / rtn ) (while (not (or (= "" (setq rtn (getstring t msg))) (snvalid rtn) ) ) (princ (strcat "\nThe name cannot contain the characters \\<>/?\":;*|,=`")) ) rtn ) (vl-load-com) (princ)
    1 point
  4. (defun c:rt5 ( / y s n l) ;; Tharwat - 14.Dec.2018 ;; (setq n 0 l (layoutlist)) (if (and (/= (setq s (getstring t "\nSpecify New Layout Prefix :")) "") (/= (setq s (vl-string-left-trim " " s)) "") ) (vlax-for x (vla-get-Layouts (vla-get-ActiveDocument (vlax-get-acad-object))) (or (eq (strcase (vla-get-name x)) "MODEL") (member (setq y (strcat s (itoa (setq n (1+ n))))) l) (vla-put-Name x y) ) ) (princ "\nNil or invalid input.") ) (princ) ) (vl-load-com)
    1 point
×
×
  • Create New...