Jump to content

Recommended Posts

Posted

Hello,

I was using this lisp routine to create layouts, but now I'm having errors when I tried to make page-setup modifications on the created layout. I'm not that good with VLA so I can't figure out why I'm getting:

 error: Automation Error. Invalid input

My guess is somewhere after this line:

;*ASSIGN BLACK-GRAY-WHITE.CTB TO THE LAYOUT:

line:

 

;Creates Layouts, by predefining Sheetsize and Orientation,
; and continious frame picking(rectangle/block) with name input for each layout

(defun C:VLD_LAYOUT2 (/ OBJ1 SHTSIZE LNAME1 layoutObj ssVP)
 (vl-load-com)
 (setq acadApp (vlax-get-Acad-object))
 (setq acadDoc (vla-get-ActiveDocument acadApp))
 (setq layouts (vla-get-Layouts acadDoc))
 (COMMAND "PSLTSCALE" "0")

;*PREDEFINING SHEETSIZE:
   (initget "A4 A3 A2 A1 A0")
   (setq SHTSIZE
       (cdr
           (assoc (cond ((getkword "\nChoose [A4/A3/A2/A1/A0] <A4>: ")) ("A4"))
              '(
                   ("A4" . "ISO full bleed A4 (297.00 x 210.00 MM)")
                   ("A3" . "ISO full bleed A3 (420.00 x 297.00 MM)")
                   ("A2" . "ISO full bleed A2 (594.00 x 420.00 MM)")
                   ("A1" . "ISO full bleed A1 (841.00 x 594.00 MM)")
                   ("A0" . "ISO full bleed A0 (841.00 x 1189.00 MM)")
               )
           )
       )
   )
;*PREDEFINING ORIENTATION:
;   (initget "Landscape Portrait")
;   (setq OR-LP (cond ((getkword "\nChoose [Landscape/Portrait] <Landscape>: ")) ("Landscape"))) ;Haven't figured out how to assign this to pagesetup

;*CONTINIOUS OBJECT SELECTION AND NAME INPUT FOR EACH LAYOUT:
  (while (setq OBJ1 (ssget "_:S:E" '((0 . "INSERT,LWPOLYLINE"))))
       (vla-getboundingbox (vlax-ename->vla-object (ssname OBJ1 0)) 'mn 'mx)
  (setq LNAME1 (getstring "\nSpecify Layout name:"))

;*DELETE THE LAYOUT NAMED LNAME1 IF IT EXISTS:
 (vlax-for objLayout layouts
   (if (= (vla-get-name objLayout) LNAME1)
     (progn
       (princ
         (strcat "\nDeleted Layout named "
             (vla-get-name objLayout) "..."
         )
       )
       (vla-delete objLayout) ;delete the Layout
       (vlax-release-object objLayout) ; release the Layout Object
     );progn
   );if
 ) ;vlax-for

;*CREATE THE NEW LAYOUT, NAMED LNAME1: 
 (setq layoutObj (vla-add layouts LNAME1))

;*MAKE THE NEW LAYOUT ACTIVE:
(if (/= LNAME1 (getvar 'ctab))
    (setvar 'ctab LNAME1)
)

; (vla-put-activelayout acadDoc layoutObj) ; Alternate vla method
;  (COMMAND "_.LAYOUT" "NEW" LNAME1) ; Alternate non-vla method
;  (COMMAND "_.LAYOUT" "SET" LNAME1) ; Alternate non-vla method

;*ASSIGN BLACK-GRAY-WHITE.CTB TO THE LAYOUT:
 (vla-put-StyleSheet layoutObj "BLACK-GRAY-WHITE.CTB")

;*ASIGN DWF CONFIGURATION TO THE LAYOUT:
 (if (= (substr (vlax-variant-value (vla-getvariable acadDoc "ACADVER")) 1 2) "15")
   (vla-put-configname layoutObj "PublishToWeb DWF.pc3") 
   (vla-put-configname layoutObj "DWG To PDF.pc3")
 ) ;if

;*ASSIGN THE DEFINED SHEETSIZE TO THE LAYOUT: 
 (vla-put-canonicalmedianame layoutObj SHTSIZE)

;*DELETES THE INITIAL VIEWPORT, FROM THE CREATED LAYOUT:
  (setq ssVP
  (ssget "_x"
  (list '(0 . "VIEWPORT") (cons 410 (getvar 'ctab)))
  )
  )
  (command "erase" ssVP "")

;*CREATES NEW VIEWPORT FOR THE LAYOUT:
  (COMMAND "_.VPORTS" "FIT")

  (COMMAND "_.MSPACE")
  (command "_.ZOOM"
  (trans (vlax-safearray->list mn) 0 1)
  (trans (vlax-safearray->list mx) 0 1)
  )
  (COMMAND "_.PSPACE")
  (COMMAND "_.CTAB" "MODEL")
  ) ;end of while
  (princ)
)



Posted

Ok, I figured it out.

But still got the issue for the layout orientation option:

 

;;; Creates Layouts, by predefining Sheetsize and Orientation,
;;; and continious frame picking(rectangle/block) with name input for each layout

(defun c:QuickLayouts (/ SHTSIZE OBJ1 GET-OR-LP SET-OR-LP LNAME1 ssVP mn mx)
 (vl-load-com)
 (setq acadApp (vlax-get-Acad-object))
 (setq acadDoc (vla-get-ActiveDocument acadApp))
 (setq layouts (vla-get-Layouts acadDoc))
 (COMMAND "PSLTSCALE" "0")

;*Predefining SHEETSIZE:
   (initget "A4 A3 A2 A1 A0")
   (setq SHTSIZE
       (cdr
           (assoc (cond ((getkword "\nChoose [A4/A3/A2/A1/A0] <A4>: ")) ("A4"))
              '(
                   ("A4" . "ISO_full_bleed_A4_(297.00_x_210.00_MM)")
                   ("A3" . "ISO_full_bleed_A3_(420.00_x_297.00_MM)")
                   ("A2" . "ISO_full_bleed_A2_(594.00_x_420.00_MM)")
                   ("A1" . "ISO_full_bleed_A1_(841.00_x_594.00_MM)")
                   ("A0" . "ISO_full_bleed_A0_(841.00_x_1189.00_MM)")
               )
           )
       )
   )

;*Predefining Orientation (Landscape/Portrait):
  (initget "Landscape Portrait")
  (setq GET-OR-LP (cond ((getkword "\nChoose [Landscape/Portrait] <Landscape>: ")) ("Landscape"))) ;Haven't figured out how to assign this to pagesetup
                (cond
	 ((= GET-OR-LP "Landscape") (setq SET-OR-LP (vla-put-PlotRotation layoutObj ac0degrees)))
	 ((= GET-OR-LP "Portrait") (setq SET-OR-LP (vla-put-PlotRotation layoutObj ac90degrees)))
                );cond

;*Continious Object selection:
  (while (setq OBJ1 (ssget "_:S:E" '((0 . "INSERT,LWPOLYLINE"))))
       (vla-getboundingbox (vlax-ename->vla-object (ssname OBJ1 0)) 'mn 'mx)

;*Continious layout name input:
  (setq LNAME1 (getstring "\nSpecify Layout name:"))

;*Delete the layout, named LNAME1 if it exists:
 (vlax-for objLayout layouts
   (if (= (vla-get-name objLayout) LNAME1)
     (progn
       (princ
         (strcat "\nDeleted Layout named "
             (vla-get-name objLayout) "..."
         )
       )
       (vla-delete objLayout) ;delete the Layout
       (vlax-release-object objLayout) ; release the Layout Object
     );progn
   );if
 ) ;vlax-for

;*Create the new layout, named LNAME1: 
 (setq layoutObj (vla-add layouts LNAME1))

;*Assign BLACK-GRAY-WHITE.CTB to the Layout:
 (vla-put-StyleSheet layoutObj "BLACK-GRAY-WHITE.CTB")

;*Assign DWF configuration to the Layout:
 (if (= (substr (vlax-variant-value (vla-getvariable acadDoc "ACADVER")) 1 2) "15")
   (vla-put-configname layoutObj "PublishToWeb DWF.pc3")
   (vla-put-configname layoutObj "DWG To PDF.pc3")
 ) ;if

;*Assign predefined SHEETSIZE to the Layout: 
 (vla-put-canonicalmedianame
   layoutObj
   SHTSIZE
 )

;*Make the new Layout Active:
 (vla-put-activelayout acadDoc layoutObj) 

;*Deletes the initial viewport, from the created layout:
  (setq ssVP
  (ssget "_x"
  (list '(0 . "VIEWPORT") (cons 410 (getvar 'ctab)))
  )
  )
  (command "erase" ssVP "")

;*Creates new viewport, for the layout:
  (COMMAND "_.VPORTS" "FIT")
  (COMMAND "_.MSPACE")
  (command "_.ZOOM"
  (trans (vlax-safearray->list mn) 0 1)
  (trans (vlax-safearray->list mx) 0 1)
  )
  (COMMAND "_.PSPACE")
  (COMMAND "_.CTAB" "MODEL")
  ); end of while
  (princ)
  )


;;; Plots all layouts in the drawing:

(defun c:QuickPlotLayouts ( )
(foreach lay (layoutlist) ;lay = each item in the layoutlist
  (setvar 'CTab lay)
  (COMMAND  "-PLOT" "N" "" "" "" "" "N" "Y")
  ); end of foreach function
 (command "CTAB" "MODEL")
)

 

Could anyone help? I'm still newbie with these lisp stuff.

Posted

I'm not entirely sure but at first glance

 

 

 (vla-put-PlotRotation layoutObj ac0degrees) 

layoutObj , where do you define this? (before you use it)

 

 

should this be ? :

 

 

 (setq layoutObj (vla-get-ActiveLayout (vla-get-activedocument (vlax-get-acad-object)))) 

gr. Rlx

Posted

Here I define it:

;*Create the new layout, named LNAME1: 
 (setq layoutObj (vla-add layouts LNAME1))

I was looking for examples for creating layout with pagesetup in a couple of blogs, so I may have errors.

 

edit: I don't know how apply this

setq SET-OR-LP

after I created the layout

Posted (edited)
Here I define it:

;*Create the new layout, named LNAME1: 
 (setq layoutObj (vla-add layouts LNAME1))

I was looking for examples for creating layout with pagesetup in a couple of blogs, so I may have errors.

 

edit: I don't know how apply this

setq SET-OR-LP

after I created the layout

 

 

I'm really starting to fall behind with my work ;-) But alwayz try to make time for a quick answer :-)

 

 

What I mean , your app starts with c:QuickLayouts , but you use layoutObj (to set orientation) before you (try to) define it. If i'm correct you want to save the orientation to the active layout , the one your working with , so first make sure the layout where you want to save your settings to is defined , is active , so put (setq layoutObj (vla-get-ActiveLayout acadDoc)) right after (setq layouts (vla-get-Layouts acadDoc))

 

 

at least I think...

 

 

update : I've add a routine I was working on , well part of it anyway , to plot using vla-commands. More or less as a learning exercise. Might be of interest... or not...

 

gr. Rlx

GrrPrr.LSP

Edited by rlx
Posted

Thank you for replying, Rlx!

I'll try to learn from your routine. But I still can't figure out how to apply (correctly) this setq function, after user inputs his Landscape/Portrait choice and the layout is created:

 

;*Set the Layout orientation:
(setq SET-OR-LP (OR-VAL))

 

;;; Creates Layouts, by predefining Sheetsize and Orientation,
;;; and continious frame picking(rectangle/block) with name input for each layout

(defun c:QuickLayouts2 (/ SHTSIZE OBJ1 GET-OR-LP SET-OR-LP OR-VAL LNAME1 ssVP mn mx)
 (vl-load-com)
 (setq acadApp (vlax-get-Acad-object))
 (setq acadDoc (vla-get-ActiveDocument acadApp))
 (setq layouts (vla-get-Layouts acadDoc))
 (setq layoutObj (vla-get-ActiveLayout acadDoc))
 (COMMAND "PSLTSCALE" "0")

;*Predefining SHEETSIZE:
   (initget "A4 A3 A2 A1 A0")
   (setq SHTSIZE
       (cdr
           (assoc (cond ((getkword "\nChoose [A4/A3/A2/A1/A0] <A4>: ")) ("A4"))
              '(
                   ("A4" . "ISO_full_bleed_A4_(297.00_x_210.00_MM)")
                   ("A3" . "ISO_full_bleed_A3_(420.00_x_297.00_MM)")
                   ("A2" . "ISO_full_bleed_A2_(594.00_x_420.00_MM)")
                   ("A1" . "ISO_full_bleed_A1_(841.00_x_594.00_MM)")
                   ("A0" . "ISO_full_bleed_A0_(841.00_x_1189.00_MM)")
               )
           )
       )
   )

;*Predefining Orientation (Landscape/Portrait):
  (initget "Landscape Portrait")
  (setq GET-OR-LP (cond ((getkword "\nChoose [Landscape/Portrait] <Landscape>: ")) ("Landscape"))) ;Haven't figured out how to assign this to pagesetup
                (cond
	 ((= GET-OR-LP "Landscape") (setq OR-VAL (vla-put-PlotRotation layoutObj ac0degrees)))
	 ((= GET-OR-LP "Portrait") (setq OR-VAL (vla-put-PlotRotation layoutObj ac90degrees)))
                );cond

;*Continious Object selection:
  (while (setq OBJ1 (ssget "_:S:E" '((0 . "INSERT,LWPOLYLINE"))))
       (vla-getboundingbox (vlax-ename->vla-object (ssname OBJ1 0)) 'mn 'mx)

;*Continious layout name input:
  (setq LNAME1 (getstring "\nSpecify Layout name:"))

;*Delete the layout, named LNAME1 if it exists:
 (vlax-for objLayout layouts
   (if (= (vla-get-name objLayout) LNAME1)
     (progn
       (princ
         (strcat "\nDeleted Layout named "
             (vla-get-name objLayout) "..."
         )
       )
       (vla-delete objLayout) ;delete the Layout
       (vlax-release-object objLayout) ; release the Layout Object
     );progn
   );if
 ) ;vlax-for

;*Create the new layout, named LNAME1: 
 (setq layoutObj (vla-add layouts LNAME1))

;*Assign BLACK-GRAY-WHITE.CTB to the Layout:
 (vla-put-StyleSheet layoutObj "BLACK-GRAY-WHITE.CTB")

;*Assign DWF configuration to the Layout:
 (if (= (substr (vlax-variant-value (vla-getvariable acadDoc "ACADVER")) 1 2) "15")
   (vla-put-configname layoutObj "PublishToWeb DWF.pc3")
   (vla-put-configname layoutObj "DWG To PDF.pc3")
 ) ;if

;*Assign predefined SHEETSIZE to the Layout: 
 (vla-put-canonicalmedianame
   layoutObj
   SHTSIZE
 )

;*Make the new Layout Active:
 (vla-put-activelayout acadDoc layoutObj) 

;*Set the Layout orientation:
(setq SET-OR-LP (OR-VAL))

;*Deletes the initial viewport, from the created layout:
  (setq ssVP
  (ssget "_x"
  (list '(0 . "VIEWPORT") (cons 410 (getvar 'ctab)))
  )
  )
  (command "erase" ssVP "")

;*Creates new viewport, for the layout:
  (COMMAND "_.VPORTS" "FIT")
  (COMMAND "_.MSPACE")
  (command "_.ZOOM"
  (trans (vlax-safearray->list mn) 0 1)
  (trans (vlax-safearray->list mx) 0 1)
  )
  (COMMAND "_.PSPACE")
  (COMMAND "_.CTAB" "MODEL")
  ); end of while
  (princ)
  )


;;; Plots all layouts in the drawing:

(defun c:QuickPlotLayouts ( )
(foreach lay (layoutlist) ;lay = each item in the layoutlist
  (setvar 'CTab lay)
  (COMMAND  "-PLOT" "N" "" "" "" "" "N" "Y")
  ); end of foreach function
 (command "CTAB" "MODEL")
)

Posted

edit: I am aware of this trick with comparsion between width and height to get and set the rotation, but its too much for my mind to handle :)

Posted

But I still can't figure out how to apply (correctly) this setq function, after user inputs his Landscape/Portrait choice and the layout is created:

 

 

I don't think you need the setq because (vla-put-PlotRotation layoutObj ac0degrees) does what it says , it puts ac0degrees to your layout. When you want to read it then its another story , then you would use (setq or-val (vla-get-PlotRotation layoutObj))

 

 

see also http://help.autodesk.com/view/ACD/2016/ENU/?guid=GUID-E612859D-AEC5-414F-B1D5-24C0CF6A4F48

 

 

Well, day is done for me , closing down here...

 

 

gr. Rlx

Posted

Thank you for helping me, Rlx!

I've fixed my issue - gotta say that was damn hard for a newbie.

Heres the final version:

;;; Creates Layouts, by predefining Sheetsize and Orientation,
;;; and continious frame picking(rectangle/block) with name input for each layout

(defun c:QuickLayouts (/ SHTSIZE OBJ1 GET-OR-LP LNAME1 OR-VAL ssVP mn mx)
 (vl-load-com)
 (setq acadApp (vlax-get-Acad-object))
 (setq acadDoc (vla-get-ActiveDocument acadApp))
 (setq layouts (vla-get-Layouts acadDoc))
 (setq layoutObj (vla-get-ActiveLayout acadDoc))
 (COMMAND "PSLTSCALE" "0")

;*Predefining SHEETSIZE:
   (initget "A4 A3 A2 A1 A0")
   (setq SHTSIZE
       (cdr
           (assoc (cond ((getkword "\nChoose [A4/A3/A2/A1/A0] <A4>: ")) ("A4"))
              '(
                   ("A4" . "ISO_full_bleed_A4_(297.00_x_210.00_MM)")
                   ("A3" . "ISO_full_bleed_A3_(420.00_x_297.00_MM)")
                   ("A2" . "ISO_full_bleed_A2_(594.00_x_420.00_MM)")
                   ("A1" . "ISO_full_bleed_A1_(841.00_x_594.00_MM)")
                   ("A0" . "ISO_full_bleed_A0_(841.00_x_1189.00_MM)")
               )
           )
       )
   )

;*Predefining Orientation (Landscape/Portrait):
  (initget "Landscape Portrait")
  (setq GET-OR-LP (cond ((getkword "\nChoose [Landscape/Portrait] <Landscape>: ")) ("Landscape"))) ;Haven't figured out how to assign this to pagesetup
                

;*Continious Object selection:
  (while (setq OBJ1 (ssget "_:S:E" '((0 . "INSERT,LWPOLYLINE"))))
       (vla-getboundingbox (vlax-ename->vla-object (ssname OBJ1 0)) 'mn 'mx)

;*Continious layout name input:
  (setq LNAME1 (getstring "\nSpecify Layout name:"))

;*Delete the layout, named LNAME1 if it exists:
 (vlax-for objLayout layouts
   (if (= (vla-get-name objLayout) LNAME1)
     (progn
       (princ
         (strcat "\nDeleted Layout named "
             (vla-get-name objLayout) "..."
         )
       )
       (vla-delete objLayout) ;delete the Layout
       (vlax-release-object objLayout) ; release the Layout Object
     );progn
   );if
 ) ;vlax-for

;*Create the new layout, named LNAME1: 
 (setq layoutObj (vla-add layouts LNAME1))

;*Assign BLACK-GRAY-WHITE.CTB to the Layout:
 (vla-put-StyleSheet layoutObj "BLACK-GRAY-WHITE.CTB")

;*Assign DWF configuration to the Layout:
 (if (= (substr (vlax-variant-value (vla-getvariable acadDoc "ACADVER")) 1 2) "15")
   (vla-put-configname layoutObj "PublishToWeb DWF.pc3")
   (vla-put-configname layoutObj "DWG To PDF.pc3")
 ) ;if

;*Assign predefined SHEETSIZE to the Layout: 
 (vla-put-canonicalmedianame
   layoutObj
   SHTSIZE
 )

;*Make the new Layout Active:
 (vla-put-activelayout acadDoc layoutObj) 

;*Set the Layout orientation:
 (cond
 ((= GET-OR-LP "Landscape") (setq OR-VAL (vla-put-PlotRotation layoutObj ac0degrees)))
 ((= GET-OR-LP "Portrait") (setq OR-VAL (vla-put-PlotRotation layoutObj ac90degrees)))
 );cond

;*Deletes the initial viewport, from the created layout:
  (setq ssVP
  (ssget "_x"
  (list '(0 . "VIEWPORT") (cons 410 (getvar 'ctab)))
  )
  )
  (command "erase" ssVP "")

;*Creates new viewport, for the layout:
  (COMMAND "_.VPORTS" "FIT")
  (COMMAND "_.MSPACE")
  (command "_.ZOOM"
  (trans (vlax-safearray->list mn) 0 1)
  (trans (vlax-safearray->list mx) 0 1)
  )
  (COMMAND "_.PSPACE")
  (COMMAND "_.CTAB" "MODEL")
  ); end of while
  (princ)
  )


;;; Plots all layouts in the drawing:

(defun c:QuickPlotLayouts ( )
(foreach lay (layoutlist) ;lay = each item in the layoutlist
  (setvar 'CTab lay)
  (COMMAND  "-PLOT" "N" "" "" "" "" "N" "Y")
  ); end of foreach function
 (command "CTAB" "MODEL")
)

Posted
Thank you for helping me, Rlx!

I've fixed my issue - gotta say that was damn hard for a newbie.

Heres the final version:

;;; Creates Layouts, by predefining Sheetsize and Orientation,
;;; and continious frame picking(rectangle/block) with name input for each layout

(defun c:QuickLayouts (/ SHTSIZE OBJ1 GET-OR-LP LNAME1 OR-VAL ssVP mn mx)
 (vl-load-com)
 (setq acadApp (vlax-get-Acad-object))
 (setq acadDoc (vla-get-ActiveDocument acadApp))
 (setq layouts (vla-get-Layouts acadDoc))
 (setq layoutObj (vla-get-ActiveLayout acadDoc))
 (COMMAND "PSLTSCALE" "0")

;*Predefining SHEETSIZE:
   (initget "A4 A3 A2 A1 A0")
   (setq SHTSIZE
       (cdr
           (assoc (cond ((getkword "\nChoose [A4/A3/A2/A1/A0] <A4>: ")) ("A4"))
              '(
                   ("A4" . "ISO_full_bleed_A4_(297.00_x_210.00_MM)")
                   ("A3" . "ISO_full_bleed_A3_(420.00_x_297.00_MM)")
                   ("A2" . "ISO_full_bleed_A2_(594.00_x_420.00_MM)")
                   ("A1" . "ISO_full_bleed_A1_(841.00_x_594.00_MM)")
                   ("A0" . "ISO_full_bleed_A0_(841.00_x_1189.00_MM)")
               )
           )
       )
   )

;*Predefining Orientation (Landscape/Portrait):
  (initget "Landscape Portrait")
  (setq GET-OR-LP (cond ((getkword "\nChoose [Landscape/Portrait] <Landscape>: ")) ("Landscape"))) ;Haven't figured out how to assign this to pagesetup
                

;*Continious Object selection:
  (while (setq OBJ1 (ssget "_:S:E" '((0 . "INSERT,LWPOLYLINE"))))
       (vla-getboundingbox (vlax-ename->vla-object (ssname OBJ1 0)) 'mn 'mx)

;*Continious layout name input:
  (setq LNAME1 (getstring "\nSpecify Layout name:"))

;*Delete the layout, named LNAME1 if it exists:
 (vlax-for objLayout layouts
   (if (= (vla-get-name objLayout) LNAME1)
     (progn
       (princ
         (strcat "\nDeleted Layout named "
             (vla-get-name objLayout) "..."
         )
       )
       (vla-delete objLayout) ;delete the Layout
       (vlax-release-object objLayout) ; release the Layout Object
     );progn
   );if
 ) ;vlax-for

;*Create the new layout, named LNAME1: 
 (setq layoutObj (vla-add layouts LNAME1))

;*Assign BLACK-GRAY-WHITE.CTB to the Layout:
 (vla-put-StyleSheet layoutObj "BLACK-GRAY-WHITE.CTB")

;*Assign DWF configuration to the Layout:
 (if (= (substr (vlax-variant-value (vla-getvariable acadDoc "ACADVER")) 1 2) "15")
   (vla-put-configname layoutObj "PublishToWeb DWF.pc3")
   (vla-put-configname layoutObj "DWG To PDF.pc3")
 ) ;if

;*Assign predefined SHEETSIZE to the Layout: 
 (vla-put-canonicalmedianame
   layoutObj
   SHTSIZE
 )

;*Make the new Layout Active:
 (vla-put-activelayout acadDoc layoutObj) 

;*Set the Layout orientation:
 (cond
 ((= GET-OR-LP "Landscape") (setq OR-VAL (vla-put-PlotRotation layoutObj ac0degrees)))
 ((= GET-OR-LP "Portrait") (setq OR-VAL (vla-put-PlotRotation layoutObj ac90degrees)))
 );cond

;*Deletes the initial viewport, from the created layout:
  (setq ssVP
  (ssget "_x"
  (list '(0 . "VIEWPORT") (cons 410 (getvar 'ctab)))
  )
  )
  (command "erase" ssVP "")

;*Creates new viewport, for the layout:
  (COMMAND "_.VPORTS" "FIT")
  (COMMAND "_.MSPACE")
  (command "_.ZOOM"
  (trans (vlax-safearray->list mn) 0 1)
  (trans (vlax-safearray->list mx) 0 1)
  )
  (COMMAND "_.PSPACE")
  (COMMAND "_.CTAB" "MODEL")
  ); end of while
  (princ)
  )


;;; Plots all layouts in the drawing:

(defun c:QuickPlotLayouts ( )
(foreach lay (layoutlist) ;lay = each item in the layoutlist
  (setvar 'CTab lay)
  (COMMAND  "-PLOT" "N" "" "" "" "" "N" "Y")
  ); end of foreach function
 (command "CTAB" "MODEL")
)

 

Not sure what I did to help but if it works , it works :-)

 

Gr. Rlx

Posted

BlackBox, this function looks very powerful!

However, I'm not used to work with page setups as you can see. But this is a good alternate option.

For your suggestion it would be better to apply certain "PageSetupName" to a certain range of layout list.

Example: layout1, layout2.. layout4 should be A1 landscape; layout5... layout8 A3 portrait and so on..

In my opinion the easiest way to achieve it is to use listboxs (as Lee mac's routines) and apply one to another.

Thank you for your suggestions and help! I tried to reply you in the other forum.

  • 3 weeks later...
Posted

You're welcome to employ the function I offered as code-behind any UI component(s), or custom Command(s) you like.

 

The example I posted above iterates the LAYOUTLIST resultant list of all Layouts; to apply various named Page Setups to sub-sets of Layouts, simply supply the applicable sub-set of Layout(s) and named Page Setup to apply to same.

 

Cheers

Posted

Another suggestion if you have a look at this I used it for plot layout range method as an example of applying to a range of layouts.

 

NOT TESTED
(ah:getval2 "Enter Start tab number" 6 4 "Enter End tab number" 6 4)
(setq numlay (ATOI val1))
(setq numend (ATOI val2))

(textscr)
(setq len (+ (- numend numlay) 1))

(repeat len
(vlax-for lay (vla-get-Layouts (vla-get-activedocument (vlax-get-acad-object)))
(if (= numlay (vla-get-taborder lay))
(progn  
(setq layname (vla-get-name lay))
(setvar "ctab" layname )
(vla-SetActivePageSetup layname “YourPageSetupName”)
) ; progn
) ; if
) ; for

 

getvals put in autoload etc or just add to above use getvals2

; Input  Dialog box with variable title
; multiple lines of dcl supported
; add extra lines if required by copying code defun
; By Alan H 2015

; example code just use these next two lines
; (if (not AH:getval1)(load "getvals.lsp"))
; (ah:getval1 "Enter size " 5 4)  ;

; 1 line dcl
; sample code (ah:getval1 "line 1" 5 4)
(defun AH:getval1 (title width limit / fo)
; you can hard code a directory if you like for dcl file
(setq fo (open (setq fn (vl-filename-mktemp "" "" ".dcl")) "w"))
(write-line "ddgetval : dialog {" fo)
(write-line " : row {" fo)
(write-line ": edit_box {" fo)
(write-line (strcat "    key = "  (chr 34) "key1" (chr 34) ";") fo)
(write-line  (strcat " label = "  (chr 34) title (chr 34) ";"  )   fo)
; these can be replaced with shorter value etc
(write-line (strcat "     edit_width = " (rtos width 2 0) ";" ) fo)
(write-line (strcat "     edit_limit = " (rtos limit 2 0) ";" ) fo)
(write-line "   is_enabled = true;" fo)
(write-line "    }" fo)
(write-line "  }" fo)
(write-line "ok_only;}" fo)
(close fo)

(setq dcl_id (load_dialog  fname))
(if (not (new_dialog "ddgetval" dcl_id))
(exit))
(action_tile "key1" "(setq val1 $value)")
(mode_tile "key1" 3)
(start_dialog)
(done_dialog)
(unload_dialog dcl_id)
; returns the value of val1 as a string
) ; defungetval1

; 2 line dcl
; sample code 
; (if (not AH:getval2)(load "getvals.lsp"))
; (ah:getval2 "line 1" 5 4 "line2" 8 7)

(defun AH:getval2 (title1 width1 limit1 title2 width2 limit2 / fo)
(setq fo (open (setq fn (vl-filename-mktemp "" "" ".dcl")) "w"))
(write-line "ddgetval2 : dialog {" fo)
(write-line " : column {" fo)
(write-line ": edit_box {" fo)
(write-line (strcat "    key = " (chr 34) "key1" (chr 34) ";") fo)
(write-line  (strcat " label = "  (chr 34) title1 (chr 34) ";" ) fo)
(write-line (strcat "     edit_width = " (rtos width1 2 0) ";" ) fo)
(write-line (strcat "     edit_limit = " (rtos limit1 2 0) ";" ) fo)
(write-line "   is_enabled = true ;" fo)
(write-line "    }" fo)
(write-line "spacer_1 ;" fo)
(write-line ": edit_box {" fo)
(write-line (strcat "    key = " (chr 34) "key2" (chr 34) ";") fo)
(write-line (strcat " label = "  (chr 34) title2 (chr 34) ";"  ) fo)
(write-line (strcat "     edit_width = " (rtos width2 2 0) ";" ) fo)
(write-line (strcat "     edit_limit = " (rtos limit2 2 0) ";" ) fo)
(write-line "   is_enabled = true ;" fo)
(write-line "    }" fo)
(write-line "    }" fo)
(write-line "spacer_1 ;" fo)
(write-line "ok_only;}" fo)
(close fo)

; code part
(setq dcl_id (load_dialog  fname))
(if (not (new_dialog "ddgetval2" dcl_id))
(exit))
(mode_tile "key1" 3)
(action_tile "key1" "(setq val1 $value)")
(mode_tile "key2" 3)
(action_tile "key2" "(setq val2 $value)")
(start_dialog)
(done_dialog)
(unload_dialog dcl_id)
; returns the value of val1 and val2 as strings
) ; defungetval2

; 3 line dcl
; sample code
;(if (not AH:getval3)(load "getvals.lsp"))
;(ah:getval3 "line 1" 5 4 "line2" 8 7 "line3" 6 4)

(defun AH:getval3 (title1 width1 limit1 title2 width2 limit2 title3 width3 limit3 / fo)
(setq fo (open (setq fn (vl-filename-mktemp "" "" ".dcl")) "w"))
(write-line "ddgetval3 : dialog {" fo)
(write-line " : column {" fo)
(write-line ": edit_box {" fo)
(write-line (strcat "    key = " (chr 34) "key1" (chr 34) ";") fo)
(write-line  (strcat " label = "  (chr 34) title1 (chr 34) ";" ) fo)
(write-line (strcat "     edit_width = " (rtos width1 2 0) ";" ) fo)
(write-line (strcat "     edit_limit = " (rtos limit1 2 0) ";" ) fo)
(write-line "   is_enabled = true ;" fo)
(write-line "    }" fo)
(write-line "spacer_1 ;" fo)
(write-line ": edit_box {" fo)
(write-line (strcat "    key = " (chr 34) "key2" (chr 34) ";") fo)
(write-line (strcat " label = "  (chr 34) title2 (chr 34) ";"  ) fo)
(write-line (strcat "     edit_width = " (rtos width2 2 0) ";" ) fo)
(write-line (strcat "     edit_limit = " (rtos limit2 2 0) ";" ) fo)
(write-line "   is_enabled = true ;" fo)
(write-line "    }" fo)
(write-line "spacer_1 ;" fo)
(write-line ": edit_box {" fo)
(write-line (strcat "    key = " (chr 34) "key3" (chr 34) ";") fo)
(write-line (strcat " label = "  (chr 34) title3 (chr 34) ";"  ) fo)
(write-line (strcat "     edit_width = " (rtos width3 2 0) ";" ) fo)
(write-line (strcat "     edit_limit = " (rtos limit3 2 0) ";" ) fo)
(write-line "   is_enabled = true ;" fo)
(write-line "    }" fo)
(write-line "    }" fo)
(write-line "spacer_1 ;" fo)
(write-line "ok_only;}" fo)
(close fo)

; code part
(setq dcl_id (load_dialog  fname))
(if (not (new_dialog "ddgetval3" dcl_id))
(exit))
(mode_tile "key1" 3)
(action_tile "key1" "(setq val1 $value)")
(mode_tile "key2" 3)
(action_tile "key2" "(setq val2 $value)")
(mode_tile "key3" 3)
(action_tile "key3" "(setq val3 $value)")
(start_dialog)
(done_dialog)
(unload_dialog dcl_id)
; returns the value of val1 and val2 val3 as strings
) ; defungetval3

Posted

BlackBox, I will try your function.

But now I'm struggling with creation of page-setups using VLA.

I kinda succeeded, then I realized that the pagesetups, created in modelspace are different than those in paperspace?! I don't get it!

Heres a part of the code I found and modified from internet (My guess its from Lee):

(defun VLD:A4-Landscape-VLD( / doc ss plotCfgs plotCfg)
   ;; Get the current drawing
   (setq doc (vla-get-ActiveDocument (vlax-get-acad-object)))

   ;; Get the PlotConfigurations collection
   (setq plotCfgs (vla-get-PlotConfigurations doc))

   ;; Check to see if the pagesetup already exists
   (setq plotCfg (vl-catch-all-apply 'vla-Item (list plotCfgs "A4-Landscape-VLD")))

   ;; If the page setup exists, the variable will be of type VLA-OBJECT
   (if (/= (type plotCfg) 'VLA-OBJECT)
       ;; Create a page setup for model or paper space accordingly
       (if (= (getvar "TILEMODE") 0)  
           (setq plotCfg (vla-Add plotCfgs "A4-Landscape-VLD" :vlax-false))
           (setq plotCfg (vla-Add plotCfgs "A4-Landscape-VLD" :vlax-true))
       )
   )

   ;;(vla-put-Name plotCfg "A4-Landscape-VLD")
   (vla-RefreshPlotDeviceInfo plotCfg)
 
   ;; Set the plot device
   (vla-put-ConfigName plotCfg "DWG To PDF.pc3")

   ;; Set the paper size
   (vla-put-CanonicalMediaName plotCfg "ISO_full_bleed_A4_(297.00_x_210.00_MM)")

   ;; Set the plot units (inches, millimeters, pixels)
   (vla-put-PaperUnits plotCfg acMillimeters)

   ;; Set what to plot
   ;; - If using acView, set the ViewToPlot property
   ;; - If using acWindow, call GetWindowToPlot
   (if (= (getvar "TILEMODE") 0)
       (progn
           (vla-put-PlotType plotCfg acLayout)

           ;; Set scale
           (vla-put-UseStandardScale plotCfg :vlax-true)
           (vla-put-StandardScale plotCfg ac1_1)          
       )
       (progn
           (vla-put-PlotType plotCfg acDisplay)

           ;; Set scale
           (vla-put-UseStandardScale plotCfg :vlax-true)
           (vla-put-StandardScale plotCfg acScaleToFit)

       )
   )

   ;; Hide paperspace objects
   (vla-put-PlotHidden plotCfg :vlax-false)

   ;; Set the plot origin
   (setq origin (vlax-make-safearray vlax-vbDouble '(0 . 1)))
   (vlax-safearray-fill origin (list 0.5 0.5))
   (vla-put-PlotOrigin plotCfg origin)

   ;; Set the plot rotation
   (vla-put-PlotRotation plotCfg ac0degrees)

   ;; Set viewport plot behavior
   (vla-put-PlotViewportBorders plotCfg :vlax-false)
   (vla-put-PlotViewportsFirst plotCfg :vlax-true)

   ;; Set lineweight behavior
   (vla-put-PlotWithLineweights plotCfg :vlax-true)
   (vla-put-ScaleLineweights plotCfg :vlax-true)

   ;; Set plot styles behavior
   (vla-put-PlotWithPlotStyles plotCfg :vlax-true)
   (vla-put-ShowPlotStyles plotCfg :vlax-true)

   (if (= (getvar "PSTYLEMODE") 0)
       (vla-put-StyleSheet plotCfg "BLACK-GRAY-WHITE.CTB")
       (vla-put-StyleSheet plotCfg "BLACK-GRAY-WHITE.CTB")
   )

   ;; Center the plot on the page
   (if
   (= :vlax-false (vla-get-CenterPlot plotCfg))
   (vla-put-CenterPlot plotCfg :vlax-true)
   )
   
   ;; Assign Shadeplot


   ;; Assign the page setup to the current layout
   ;(vla-CopyFrom (vla-get-ActiveLayout doc) plotCfg)
)

Doesn't work with TILEMODE 0, I get "Error: Automation Error. Invalid input"

But thats whole another thread!

 

 

BIGAL,

I tried your suggestion but doesn't it work for me. Could you elaborate how to use it? I'm sure I did something wrong.

 

Overall I overcomed my problems with manual vla manipulation of each created layout ( But I'm still willing to try the method with pagesetups).

Posted

... now I'm struggling with creation of page-setups using VLA.

 

Just (manually?) set up all of your named Page Setups within your Drawing Template(s), and then STEAL what you need, when you need it. :thumbsup:

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