Applying Page setup

Applying Page setup

will.wydock
Advocate Advocate
2,089 Views
5 Replies
Message 1 of 6

Applying Page setup

will.wydock
Advocate
Advocate

Hi,

I am working on a subroutine that inserts a titleblock and creates a template but I am having a problem with applying a page setup to the layout tab. How can I apply the pagesetup to the active document layout?  Below is what i have gotten so far. When i run this nothing seems to happen when applying the pagesetup.

 

(defun tbandTemp (prjnum titlb projectlocation titleinfo pagesetup /)

;;; Set Titleblock Resource file
	(setq acadobj(vlax-get-acad-object))
	(setq doc (vla-get-ActiveDocument acadobj))
	(setq newtemp (strcat projectlocation "\\" shtloc prjnum))
	(setq titleblock (strcat projectlocation "\\" resloc prjnum "XRTB.dwg"))
;	(alert titleblock)
	(setvar "cmdecho" 0)
	(setvar "filedia" 0)
	(vl-file-copy (strcat cadtb titlb) titleblock)
	(setvar "tilemode" 0)
	(if (gcs-Make-Layer "G-TITL-BLOK")
	  (setvar "CLAYER" "G-TITL-BLOK")
	)
	(command "-XREF" "Attach" titleblock "0,0"  "1"  "1"  "0")
	(vlax-for pc (vla-get-plotconfigurations doc) (vla-delete pc))
	(command "._-PSETUPIN" "C:\\_Genesis-CAD_\\Templates\\GEI-PAGE SETUPS.dwt" pagesetup)
	(SetNamePageSetup pagesetup)
	(if (gcs-Make-Layer "G-TITL-FLDS")
	  (setvar "CLAYER" "G-TITL-FLDS")
	)
	(vla-SaveAs doc newtemp ac2013_Template)
	(setvar "cmdecho" 1)
	(setvar "filedia" 1)
)
(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))
    )
)
0 Likes
Accepted solutions (1)
2,090 Views
5 Replies
Replies (5)
Message 2 of 6

will.wydock
Advocate
Advocate

What i have found so far is that the routine applies the pagesetup to the active layout. My page setups are all set to extents but the view graphically the view does not change, almost as if AutoCAD does not recognize any elements within the layout. Is there a different/better way for applying the page setups to sheets?

0 Likes
Message 3 of 6

ronjonp
Advisor
Advisor

Try adding:

(vlax-invoke alayt 'refreshplotdeviceinfo)

after you apply the setup.

0 Likes
Message 4 of 6

will.wydock
Advocate
Advocate

I tried what you suggested and  i got the following error.

; error: bad argument type: VLA-OBJECT nil

 

And in case i placed it at the wrong location this was the code

(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))
		(vlax-invoke alayt 'refreshplotdeviceinfo)
    )
	
)
0 Likes
Message 5 of 6

ronjonp
Advisor
Advisor

You need (progn) when using an if statement that has multiple returns:

(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")
      )
    (progn (vla-copyfrom alayt (vla-item (vla-get-plotconfigurations adoc) name))
	   (vlax-invoke alayt 'refreshplotdeviceinfo)
    )
  )
)

You also might take a look the the post HERE. It's an example how to copy a pagesetup to all tabs.

0 Likes
Message 6 of 6

ronjonp
Advisor
Advisor
Accepted solution

Here is another way to write your function to apply a pagesetup to the current tab:

(defun pagesetuptocurrentlayout	(name / ad lyt ps)
  (setq pc (vla-get-plotconfigurations (setq ad (vla-get-activedocument (vlax-get-acad-object)))))
  (cond	((and (= 0 (vlax-get (setq lyt (vla-get-activelayout ad)) 'modeltype))
	      (= 'vla-object (type (setq ps (vl-catch-all-apply 'vla-item (list pc name)))))
	 )
	 (vla-copyfrom lyt ps)
	 (vlax-invoke lyt 'refreshplotdeviceinfo)
	)
  )
)
;; (pagesetuptocurrentlayout "_PDF 24x36")
0 Likes