mchernecki Posted January 4, 2016 Share Posted January 4, 2016 I am building a standalone application in VB.Net to create drawing in AutoCAD 2012 using the COM ActiveX API. I am copying page setups from a template drawing to the drawing I create that has multiple layouts. In my code I plot each layout by calling Document.Plot.SetLayoutsToPlot(obj) Document.Plot.PlotToDevice() This works fine using the page setups I copied. However, after the drawing is saved and the drawing is later opened directly in AutoCAD (not using my application). When you try to use the Publish command, it fails to plot with the error Page Setup not found. So basically works with Plot, but fails with Publish. Any ideas why it fails for Publish, is there something further I need to do for Publish to work correctly? Here is the code I use to Copy Page Setups. For Each oPage As clsMDA_Page In colPages If oPage.LayoutName = PageType.Assembly Then Dim PlotConfigDeleted As Boolean = DeletePlotConfigurations(AutoCAD_Document) Dim PageSetupsCopied As Boolean = CopyPageSetups(AutoCAD_Application, AutoCAD_Document, MDA_PageSetupLibrary, "A Size") PageSetupsCopied = CopyPageSetups(AutoCAD_Application, AutoCAD_Document, MDA_PageSetupLibrary, "B Size") End If Dim LayoutSet As Boolean Select Case oPage.PageSize Case PageSize.SizeA LayoutSet = SetLayoutPlotConfiguration(AutoCAD_Document, AutoCAD_Document.ActiveLayout, conPageSetupCopyRoomBlackASizeLandscape) Case PageSize.SizeB LayoutSet = SetLayoutPlotConfiguration(AutoCAD_Document, AutoCAD_Document.ActiveLayout, conPageSetupCopyRoomBlackBSizeLandscape) End Select Private Function DeletePlotConfigurations(ByVal Document As AcadDocument) As Boolean Try For Each plot As AcadPlotConfiguration In Document.PlotConfigurations plot.Delete() Next DeletePlotConfigurations = True Catch ex As Exception DeletePlotConfigurations = False End Try End Function Private Function CopyPageSetups(ByVal AutoCAD_Application As AcadApplication, ByVal Document As AcadDocument, ByVal PageSetupFile As String, ByVal PageSize As String) As Boolean Try Dim ACDbx As AxDbDocument Dim colConfig As AcadPlotConfigurations ACDbx = AutoCAD_Application.GetInterfaceObject("ObjectDBX.AxDbDocument.18") ACDbx.Open(PageSetupFile) colConfig = ACDbx.PlotConfigurations Dim i As Integer = 0 For Each PlotConfig As AcadPlotConfiguration In colConfig If PlotConfig.Name.Contains(PageSize) Then i += 1 End If Next If (i <= 0) Then CopyPageSetups = True Exit Function End If Dim objArray(0 To i - 1) As AcadObject i = 0 For Each PlotConfig As AcadPlotConfiguration In colConfig If PlotConfig.Name.Contains(PageSize) Then objArray(i) = PlotConfig i += 1 End If Next ACDbx.CopyObjects(objArray, Document.PlotConfigurations) CopyPageSetups = True Catch ex As Exception CopyPageSetups = False End Try End Function Private Function SetLayoutPlotConfiguration(ByVal Document As AcadDocument, ByVal Layout As AcadLayout, ByVal ConfigName As String) As Boolean Try Dim PlotConfiguration As AcadPlotConfiguration Dim colPlotConfigurations As New Collection ' Get a collection of the Plot configs with the same space type ' as the layout, using the name as the key. For Each PlotConfiguration In Document.PlotConfigurations If PlotConfiguration.ModelType = Document.ActiveLayout.ModelType Then 'ModelType = False for all PaperSpace layouts colPlotConfigurations.Add(PlotConfiguration, PlotConfiguration.Name) End If Next PlotConfiguration Document.PaperSpace.Layout.RefreshPlotDeviceInfo() Layout.CopyFrom(colPlotConfigurations.Item(ConfigName)) SetLayoutPlotConfiguration = True Catch ex As Exception SetLayoutPlotConfiguration = False End Try End Function Quote Link to comment Share on other sites More sharing options...
BlackBox Posted January 4, 2016 Share Posted January 4, 2016 Welcome to CADTutor. You may be able to cull what you need from this old .NET app: http://forums.augi.com/showthread.php?80461-Page-Setup-Manager&p=1219546&viewfull=1#post1219546 Cheers Quote Link to comment Share on other sites More sharing options...
BlackBox Posted January 4, 2016 Share Posted January 4, 2016 Also, you might consider opening drawings as side Database via ReadDwgFile() in lieu of DBX. Quote Link to comment Share on other sites More sharing options...
mchernecki Posted January 4, 2016 Author Share Posted January 4, 2016 Welcome to CADTutor. You may be able to cull what you need from this old .NET app: http://forums.augi.com/showthread.php?80461-Page-Setup-Manager&p=1219546&viewfull=1#post1219546 Cheers Unless I am missing something, I am doing similar to what you are doing Copying a Plot Configuration to a layout. You are just doing it with Database Dictionary Objects. The .Net libraries you are using are not available outside of AutoCAD, a Stand-alone app can only use the COM Api which has some limitations. The ReadDwgFile is also not available, that is why I use the AxDB implementation. Is there a difference between Plot vs Publish? Plot works... but Publish can't find my page setups. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.