Friday, May 20, 2011

Use iLogic to Change Sheet Orientation from Landscape to Portrait


Issue:
You have some iLogic code to help you setup your drawing sheets. But you need one last bit of code to change the orientation of the sheet (see this link from Jonathan Landeros for a great example of using iLogic to configure title block and borders).


Solution:
You can use Page Orientation Type Enumeration to handle this. Here are two example rules that change the orientation of the active sheet. One prompts the user to choose the orientation, and the other asks the user if they want to flip the orientation. You can use the orientation enumeration portions of these rules in your own iLogic code to flip the sheet orientation as you see fit.

This first rule prompts the user to choose the orientation.





'-----------------Start of iLogic Code---------------------------------------
'PageOrientationTypeEnum Enumeration
kLandscapePageOrientation = 10242
kPortraitPageOrientation = 10243

'prompt user to select orientation
booleanParam = InputRadioBox("Select Sheet Orientation", "Landscape", "Portrait", True, Title := "iLogic Sheet Orientation")

'set orientation based on user input
If booleanParam = True then
ThisApplication.ActiveDocument.ActiveSheet.Orientation  = kLandscapePageOrientation
Else
ThisApplication.ActiveDocument.ActiveSheet.Orientation  = kPortraitPageOrientation
End if

'zoom all
ThisApplication.ActiveView.Fit
'-----------------End of iLogic Code---------------------------------------


Here is a second rule that looks at the current orientation and then asks the user if they want to flip it.


 
'-----------------Start of iLogic Code---------------------------------------
'PageOrientationTypeEnum Enumeration
kLandscapePageOrientation = 10242
kPortraitPageOrientation = 10243

CurrentOrientation = ThisApplication.ActiveDocument.ActiveSheet.Orientation

'prompt user to select orientation
OientationQuestion  = MessageBox.Show("Do you want to Flip the Sheet Orientation?", "iLogic Flip Sheet",MessageBoxButtons.YesNo)

'set orientation based on user input
'if user chooses yes and current orientatation is Portrait
If OientationQuestion = vbYes and CurrentOrientation  = 10243 then
'flip to landscape
ThisApplication.ActiveDocument.ActiveSheet.Orientation  = kLandscapePageOrientation
'if user chooses yes and current orientatation is Landscape
Else if OientationQuestion = vbYes and CurrentOrientation  = 10242 then
'flip to portrait
ThisApplication.ActiveDocument.ActiveSheet.Orientation  = kPortraitPageOrientation
'dont flip
else if OientationQuestion = vbNo then
End if

'zoom all
ThisApplication.ActiveView.Fit
'-----------------End of iLogic Code---------------------------------------