Jump to content

Layouts - vlax-for and vla-get-layouts


abra-CAD-abra

Recommended Posts

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

Link to comment
Share on other sites

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)

Link to comment
Share on other sites

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

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