Author Topic: Programmatically setup PS layouts  (Read 3223 times)

0 Members and 1 Guest are viewing this topic.

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Programmatically setup PS layouts
« on: June 21, 2006, 08:09:55 PM »
I have a need where I would like to programmatically setup all of the plotting parameters. I don't want any viewports to show on my new sheet. Essentially I want to create a new layout by adding a layout to the layouts collection, set the plotter, paper size, etc. and when the user selects it from the tab, it should not display the new setup window which places a viewport by default, but I want the page setup to show if the user creates a new layout outside of the program. Does this make sense. ... in short how do I turn off that feature for my programmatically created layouts?
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

Chuck Gabriel

  • Guest
Re: Programmatically setup PS layouts
« Reply #1 on: June 21, 2006, 10:36:16 PM »
You could attach an xrecord to the new layout when you create it.  Then do something like this in the LayoutSwitched event:

Code: [Select]
Private Sub AcadDocument_LayoutSwitched(ByVal LayoutName As String)
  If ThisDrawing.Layouts(LayoutName).HasExtensionDictionary Then
    ' Perhaps add a check here for the presence of a specific xrecord
    Application.Preferences.Display.LayoutCreateViewport = False
    Application.Preferences.Display.LayoutShowPlotSetup = False
  Else
    Application.Preferences.Display.LayoutCreateViewport = True
    Application.Preferences.Display.LayoutShowPlotSetup = True
  End If
End Sub
« Last Edit: June 22, 2006, 12:04:37 PM by Chuck Gabriel »

Jeff_M

  • King Gator
  • Posts: 4087
  • C3D user & customizer
Re: Programmatically setup PS layouts
« Reply #2 on: June 22, 2006, 12:09:28 PM »
Or, using an idea gained by seeing Chuck's code, just set those 2 variables to false before creating the layout and return them to their previous settings when done.

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Re: Programmatically setup PS layouts
« Reply #3 on: June 22, 2006, 04:53:15 PM »
Is there a specific tag, setting, xrecord etc. that you are aware of that causes the page setup window to pop up when a new layout is accessed for the first time? The reason I ask is because if you reset the variables prior to clicking on the layout, the new page setup window is still displayed. I cannot utilize (well not easily anyway) an event reactor because the programming will be compiled into a dll.

I have went as far as to dump a DXF of a drawing with 2 layouts, one selected and one not, then compare the ooutput, but I still have not found the slightest hint how to resolve this issue.
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

Bob Wahr

  • Guest
Re: Programmatically setup PS layouts
« Reply #4 on: June 22, 2006, 05:30:22 PM »
Just so I'm clear, you want to programatically do this

Jeff_M

  • King Gator
  • Posts: 4087
  • C3D user & customizer
Re: Programmatically setup PS layouts
« Reply #5 on: June 22, 2006, 05:32:04 PM »
This worked for me, Keith.
Code: [Select]
Sub LayoutTest()
Dim oLayout As AcadLayout
Dim oOrigLayout As AcadLayout
Dim bVP As Boolean
Dim bDialg As Boolean

    bVP = Application.Preferences.Display.LayoutCreateViewport
    bDialg = Application.Preferences.Display.LayoutShowPlotSetup
    Set oOrigLayout = ThisDrawing.ActiveLayout
   
    Application.Preferences.Display.LayoutCreateViewport = False
    Application.Preferences.Display.LayoutShowPlotSetup = False
   
    Set oLayout = ThisDrawing.Layouts.Add("NewLayout")
    'With oLayout
    oLayout.CopyFrom ThisDrawing.Layouts.Item(0) 'gets the plot data from the first layout....probably would want to change this.
    ThisDrawing.ActiveLayout = oLayout
    Application.Preferences.Display.LayoutCreateViewport = bVP
    Application.Preferences.Display.LayoutShowPlotSetup = bDialg
    ThisDrawing.ActiveLayout = oOrigLayout
   
End Sub

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Re: Programmatically setup PS layouts
« Reply #6 on: June 22, 2006, 06:24:48 PM »
Just so I'm clear, you want to programatically do this
No Bob .. I can do that easily enough. The issue is, that I do not want to turn off those settings, rather I want AutoCAD to ignore these settings when I programmatically create a layout. The reason is that if a user expects that to be set and I turn it off, they will simply turn it back on. This is not good from a programming point of view, for if they turn it back on, it will prompt for the page setup, which I have already setup with my programming.

Jeff I will try that and see if it resolves my issues.
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

Chuck Gabriel

  • Guest
Re: Programmatically setup PS layouts
« Reply #7 on: June 22, 2006, 07:25:57 PM »
This probably isn't the most elegant way to sink document level events in a DLL, but you don't get much simpler.

Code: [Select]
' EventSink.cls

Private WithEvents m_acadApp As AcadApplication
Private WithEvents m_currentDoc As AcadDocument

Private Sub m_acadApp_BeginCommand(ByVal CommandName As String)
  Set m_currentDoc = m_acadApp.ActiveDocument
End Sub

Private Sub m_currentDoc_LayoutSwitched(ByVal LayoutName As String)
  m_currentDoc.Utility.Prompt "Switched to layout: " & LayoutName
End Sub

Public Property Set Application(ByRef app As AcadApplication)
  Set m_acadApp = app
  Set m_currentDoc = m_acadApp.ActiveDocument
End Property