Copy page setup from another file
Does anyone have any idea why this doesn't work? The important/significant lines are in a small for . . . each loop towards the end.
Code:
Private Sub subCopyPageSetupFromFile()
Dim strDrvPathFileExt As String
Dim objSrcDB As New Database
Dim objTransactionManager As Autodesk.AutoCAD.DatabaseServices.TransactionManager
Dim objTransaction As Transaction
Dim objSrcPlotSettingsDictionary As DBDictionary
Dim objDictionaryEntry As DictionaryEntry
Dim objPlotSettings As PlotSettings
strDrvPathFileExt = "C:\ProgramData\Autodesk\ApplicationPlugins\Acad.dwt"
objSrcDB.ReadDwgFile(strDrvPathFileExt, FileOpenMode.OpenForReadAndReadShare, True, "")
objTransactionManager = objSrcDB.TransactionManager
objTransaction = objTransactionManager.StartTransaction
objSrcPlotSettingsDictionary = objTransaction.GetObject(objSrcDB.PlotSettingsDictionaryId, OpenMode.ForRead)
For Each objDictionaryEntry In objSrcPlotSettingsDictionary
objPlotSettings = objTransaction.GetObject(objDictionaryEntry.Value, OpenMode.ForRead)
MsgBox(objDictionaryEntry.Key.ToString.ToUpper)
Next
objTransaction.Dispose()
objTransactionManager.Dispose()
End Sub
Re: Copy page setup from another file
Norman's C# code here should help (convert to VB as desired):
https://forums.autodesk.com/t5/net/i...2698926#M19537
There's also a good description of how a Layout is a PlotSettings Object; don't be misled by the VB code in that thread. :beer:
Cheers
Re: Copy page setup from another file
Also, your code doesn't check for the existence of page setups in the destination dwg. If they already exist, copying them from a source db will not overwrite them. I delete them from the destination db before I start to import them.
3 Attachment(s)
Re: Copy page setup from another file
Here is my solution. ImportPageSetups.zip contains two commands. PageSetups.zip contains a form and Active.zip contains a class of objects by Scott McFarlane. Add them to your project and rename the namespaces to match your project.
Re: Copy page setup from another file