Setting a Name Page Setup to the current layout

Setting a Name Page Setup to the current layout

RockyBrown4134
Collaborator Collaborator
2,077 Views
8 Replies
Message 1 of 9

Setting a Name Page Setup to the current layout

RockyBrown4134
Collaborator
Collaborator

Is there a way to set a page layout to current in Lisp?

 

I have six named page layouts and I want to be able to set them when I call in my paper border, based on the sheet size. I have look on the discussion board and have not seen anything, probably because I have never had to use page layouts before.

 

If there are any suggestions, setting a variable, invoking the command on the command line, or just any better way, please feel free post.

 

I appreciate all the education in the area.

 

Thanks. 

If this response answers your question, Please mark this response as "Accept as Solution"

Rocky Brown
AutoCAD 2020 / Inventor 2020 / Plant 3D
0 Likes
2,078 Views
8 Replies
Replies (8)
Message 2 of 9

Jonathan3891
Advisor
Advisor

Take a look at this;

 

(defun c:layName (/ bNme aNme lay ss att e)
  (vl-load-com)

  (setq bNme "TITLEBLOCK" aNme "ATT")

  (vlax-for lay (vla-get-layouts
                  (vla-get-ActiveDocument (vlax-get-acad-object)))

    (if (and (not (eq "MODEL" (strcase (vla-get-Name lay))))
             (setq ss  (ssget "_X" (list (cons 0 "INSERT")
                                         (cons 2 bNme)
                                         (cons 66 1)
                                         (cons 410 (vla-get-Name lay))))))      
        (foreach att  (vlax-invoke
                        (vlax-ename->vla-object (ssname ss 0)) 'GetAttributes)
          
          (if (apply 'eq (mapcar 'strcase (list aNme (vla-get-TagString att))))
            
            (if (vl-catch-all-error-p
                  (setq e (vl-catch-all-apply 'vla-put-Name
                            (list lay (vla-get-TextString att)))))
              
              (princ (strcat "\n** Error: " (vl-catch-all-error-message e) " **")))))))

  (princ))

Jonathan Norton
Blog | Linkedin
Message 3 of 9

RockyBrown4134
Collaborator
Collaborator

Thanks. I'll give this a try.

 

The is a new piece to the equation. Since AutoCAD LT will not run LISP, is there a way to use page setup from the command line. I was asked to include LT user's and I need to find a way to do so with a diesel expression in a menu, before I commit myself.

If this response answers your question, Please mark this response as "Accept as Solution"

Rocky Brown
AutoCAD 2020 / Inventor 2020 / Plant 3D
0 Likes
Message 4 of 9

hmsilva
Mentor
Mentor

@RockyBrown4134 wrote:

Is there a way to set a page layout to current in Lisp?

I have six named page layouts and I want to be able to set them when I call in my paper border, based on the sheet size. I have look on the discussion board and have not seen anything, probably because I have never had to use page layouts before.

If there are any suggestions, setting a variable, invoking the command on the command line, or just any better way, please feel free post.

...



@RockyBrown4134 wrote:

...

The is a new piece to the equation. Since AutoCAD LT will not run LISP, is there a way to use page setup from the command line. I was asked to include LT user's and I need to find a way to do so with a diesel expression in a menu, before I commit myself.


Hi RockyBrown4134,
unfortunately, with a diesel expression, it should not be possible...

 

Using Auto/Visual LISP, It will be quite easy, but you'll have the LT users problem...

 

The code DSM_dude has shared, will rename each layout tab, with the TITLEBLOCK TAG value from each layout.

 

To set as current a 'Named Page Setup' we'll have to use the copyfrom method to copy the PageSetup from the PlotConfigurations collection to the activelayout object.

 

'I want to be able to set them when I call in my paper border, based on the sheet size'

 

Are you call in your paper border using some code?

 

Henrique

 

 

EESignature

Message 5 of 9

RockyBrown4134
Collaborator
Collaborator

Henrique;

Thank you for your thoughts and input, and they are appreciated.

 


@hmsilva wrote:


unfortunately, with a diesel expression, it should not be possible...

 Using Auto/Visual LISP, It will be quite easy, but you'll have the LT users problem... 


I think I am going to give them a menu pull down for the Page Setup Manager on the Title Block menu. Everything for LT users will be don manually anyway, and this is just another step.

 

 


@hmsilva wrote:

 Are you call in your paper border using some code?


Yes. Setting a variable for the border name (Block name).

          

                       (setq BDRNAME "BORDER_E")

 

Then using the following code to insert the border.

 

                        (command "-insert" BDRNAME INSPT "" "")

 

I will attach the .lsp and .dcl file so that you can take a look. It's still a work in progress, and has some extra code I have not cleaned out yet.

 


@hmsilva wrote:

 The code DSM_dude has shared, will rename each layout tab, with the TITLEBLOCK TAG value from each layout.

 

To set as current a 'Named Page Setup' we'll have to use the copyfrom method to copy the PageSetup from the PlotConfigurations collection to the activelayout object.

 

 


I haven't quiet understood DSM_dude's cod yet, or how to exactly us it. I have downloaded the cod, but have not had a honest chance to use it.

 

As far as the COPYFROM method, let me look at the link you sent me.

 

For the record, I am not that knowledgeable in VBA code. Most of what I have learned has come from you and a few other "favorite" discussion group members. I am very greatfull for all the education that each has given me.

If this response answers your question, Please mark this response as "Accept as Solution"

Rocky Brown
AutoCAD 2020 / Inventor 2020 / Plant 3D
0 Likes
Message 6 of 9

hmsilva
Mentor
Mentor

Hi RockyBrown4134l

 

I'm with a very large workload, so, this is just a starting point....

 

Add to your code this function with one argument, a string with the NamedPageSetup

(defun SetNamePageSetup (name / adoc alayt lst)
    (if (and (vl-position
                 name
                 (vlax-for pltcfg (vla-get-plotconfigurations (setq adoc (vla-get-activedocument (vlax-get-acad-object))))
                     (setq lst (cons (vlax-get pltcfg 'Name) lst))
                 )
             )
             (/= (vla-get-name (setq alayt (vla-get-activelayout adoc))) "Model")
        )
        (vla-copyfrom alayt (vla-item (vla-get-PlotConfigurations adoc) name))
    )
)

and at your's functions, PS-E to PS-A, add a call to the previous function,

 

i.e.

at the PS-A function, add

(SetNamePageSetup "ANSI A")

at the PS-A-P function add

 

(SetNamePageSetup "ANSI A PORTRAIT")

...

 

at the PS-E function add

(SetNamePageSetup "ANSI E")


Hope this helps,
Henrique

 

EESignature

0 Likes
Message 7 of 9

RockyBrown4134
Collaborator
Collaborator

Thanks.  I'll give that a try when I get back to the office. 

If this response answers your question, Please mark this response as "Accept as Solution"

Rocky Brown
AutoCAD 2020 / Inventor 2020 / Plant 3D
0 Likes
Message 8 of 9

RockyBrown4134
Collaborator
Collaborator

Thanks. 

 

 DSM_dude;

 

I am not sure if I follow your code correctly, but do I need to add an attribute to the border block with a value for the border size?

If this response answers your question, Please mark this response as "Accept as Solution"

Rocky Brown
AutoCAD 2020 / Inventor 2020 / Plant 3D
0 Likes
Message 9 of 9

Jonathan3891
Advisor
Advisor

Change "TITLEBLOCK" to the actual block name of your titleblock & "ATT" to whatever attribute you want it to pull the layout name from.

 

 


Jonathan Norton
Blog | Linkedin
0 Likes