abra-CAD-abra Posted January 11, 2018 Share Posted January 11, 2018 All, In AutoCAD 2016, and when using vlax-for and vla-get-layouts in the code below, I need to switch to a different layout before the new layout names are applied to the layouts. (defun C:DEMO (/ tab str) (vl-load-com) (vlax-for lyt (vla-get-layouts (vla-get-activedocument (vlax-get-acad-object)) ) (setq tab (vla-get-name lyt)) (setq str (substr tab 1 4)) (vla-put-name lyt (strcat "2" str)) ) (princ) ) Any ideas? Thanks Quote Link to comment Share on other sites More sharing options...
BIGAL Posted January 12, 2018 Share Posted January 12, 2018 error: Automation Error. Cannot rename the Model layout need a IF to check tab is not Model (defun C:DEMO (/ tab str) (vl-load-com) (vlax-for lyt (vla-get-layouts (vla-get-activedocument (vlax-get-acad-object)) ) (setq tab (vla-get-name lyt)) (setq str (substr tab 1 4)) (If (/= "Model" tab) (vla-put-name lyt (strcat "2" str)) ) ) (princ) ) (c:demo) Quote Link to comment Share on other sites More sharing options...
abra-CAD-abra Posted January 12, 2018 Author Share Posted January 12, 2018 error: Automation Error. Cannot rename the Model layout need a IF to check tab is not Model (defun C:DEMO (/ tab str) (vl-load-com) (vlax-for lyt (vla-get-layouts (vla-get-activedocument (vlax-get-acad-object)) ) (setq tab (vla-get-name lyt)) (setq str (substr tab 1 4)) (If (/= "Model" tab) (vla-put-name lyt (strcat "2" str)) ) ) (princ) ) (c:demo) Thanks BIGAL, Fixed it. SUBSTR starts at 1, not 0 as with other functions like NTH. (defun C:DEMOX (/ tab str) (vl-load-com) (vlax-for lyt (vla-get-layouts (vla-get-activedocument (vlax-get-acad-object)) ) (setq tab (vla-get-name lyt)) (setq str (substr tab 2 5)) (if (not (eq "MODEL" (strcase (vla-get-name lyt)))) (vla-put-name lyt (strcat "2" str)) ) ) (princ) ) Appreciate your help 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.