Detect layout orientation

Detect layout orientation

anieves228
Enthusiast Enthusiast
1,241 Views
7 Replies
Message 1 of 8

Detect layout orientation

anieves228
Enthusiast
Enthusiast

Hi all!

 

I'm trying to detect the page orientation and add it in my print command, but it's not working for me. Am I using setq correctly?

 

Thanks!

 

 

;----------------------------------------------------------------------------------------
;Detect page orientation

(defun c:porien()

		(setq l1 (vla-get-activelayout (vla-get-activedocument (vlax-get-acad-object))))
		(vla-getpapersize l1 'width 'height)
		
		(if (< width height)
			(princ "Portrait")
			(princ "Landscape")
		);if
		(princ)
	)

;----------------------------------------------------------------------------------------
PDF command
(DEFUN C:APDF ()
		(C:ZE)	;ZOOM EXTENTS
		(C:PDFFOLDER)	;CREATES 01 PDF FOLDER IF IT DOES NOT EXIST		
		(C:AGSGPSTAMP)	;TURNS ON PLOT STAMP
		(SETVAR "CMDECHO" 1)
		
						
		(SETQ B
			(C:porien)
		)
		
				(SETQ FILE 
					(STRCAT 
						(GETVAR 'DWGPREFIX) "01 PDF\\"
						(SUBSTR 
							(SETQ DWG (GETVAR 'DWGNAME)) 1
							(- (STRLEN DWG) 4)
						) "_"
						(GETVAR 'CTAB) ".PDF"
					)
				) ;;THE ABOVE LINE CREATING THE PDF FILE NAME, ACCORDING TO "LAYOUT" NAME
					(COMMAND
						"-PLOT" ;START PLOT COMMAND
						"YES" ;DETAILED PLOT CONFIGURATION?
						"" ;GET A LAYOUT NAME
						"DWG TO PDF.PC3" ;ENTER AN OUTPUT DEVICE NAME
						"ANSI FULL BLEED A (11.00 X 8.50 INCHES)" ;ENTER PAPER SIZE
						"INCHES" ;ENTER PAPER UNITS
						B ;ENTER DRAWING ORIENTATION
						"NO" ;PLOT UPSIDE DOWN?
						"LAYOUT" ;ENTER PLOT AREA
						"FIT" ;ENTER PLOT SCALE
						"0.00,0.00" ;ENTER PLOT OFFSET (X,Y)
						"YES" ;PLOT WITH PLOT STYLES?
						"MONOCHROME.CTB" ;ENTER PLOT STYLE TABLE NAME OR
						"YES" ;PLOT WITH LINEWEIGHTS?
						"NO" ;SCALE LINEWEIGHTS WITH PLOT SCALE?
						"NO" ;PLOT PAPER SPACE FIRST?
						"NO" ;HIDE PAPERSPACE OBJECTS?
						FILE;"" ;NAME OF FILE
						"NO" ;SAVE CHANGES TO PAGE SETUP
						"Y" ;PROCEED WITH PLOT
					)
		(SETVAR "CMDECHO" 1)
		(PROMPT "\n LAYOUT PDF COMPLETE \n")
		(COMMAND "_QSAVE")
		(PRINC)
	)

 

0 Likes
1,242 Views
7 Replies
Replies (7)
Message 2 of 8

dbroad
Mentor
Mentor

This doesn't answer your question but give you another way to determine if the layout is set to portrait or landscape.  

(defun isportrait ()
  (zerop
    (vla-get-PlotRotation
      (vla-get-ActiveLayout
	(vla-get-ActiveDocument
	  (vlax-get-acad-object))))))
Architect, Registered NC, VA, SC, & GA.
0 Likes
Message 3 of 8

anieves228
Enthusiast
Enthusiast

For some reason, this is not working for me.

0 Likes
Message 4 of 8

dlanorh
Advisor
Advisor
(defun isportrait ()
(vl-load-com) (zerop (vla-get-PlotRotation (vla-get-ActiveLayout (vla-get-ActiveDocument (vlax-get-acad-object))))) )

Usage

 

(setq portrait (isportrait))

 

The (isportrait) defun returns T or nil. True (T) if the orientation is portait and nil if it is Landscape

I am not one of the robots you're looking for

0 Likes
Message 5 of 8

dbroad
Mentor
Mentor

If the (vl-load-com) affects wheter it works or not, the (vl-load-com) statement should be in your acaddoc.lsp.  It's a needless addition to every function that uses activex IMO.  If it is still not working, you'll have to talk me through what's going on. The function returns T if the activelayout is portrait. Otherwise it returns nil.  You can use the return value to branch however you want. Call it with

(isportrait)

 

Architect, Registered NC, VA, SC, & GA.
0 Likes
Message 6 of 8

Anieves114
Explorer
Explorer

Ah ok. I'm still new to lisps. How do I load (vl-load-com) ? Just put it in the acaddoc.lsp as is or...?

0 Likes
Message 7 of 8

anieves228
Enthusiast
Enthusiast

Ah ok. I'm still new to lisps. How do I load (vl-load-com) ? Just put it in the acaddoc.lsp as is or...?

 

sorry replied with my personal account and not my work account (my way of keeping track of thigs)

0 Likes
Message 8 of 8

dbroad
Mentor
Mentor

Just put it in acaddoc.lsp as entered

(vl-load-com)

Chances are that its loaded anyway though.

The function (isportrait) returns T if the activelayout is portrait so you can test or branch based on the return value as

(if (isportrait) (progn ;|do portrait stuff|;)(progn ;|do layout stuff|;))

Architect, Registered NC, VA, SC, & GA.
0 Likes