PlotSettingsValidator.SetClosestMediaName

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I'm trying to solve the problem of using an Access Database with my Pagesetups stored there, then loading these programatically into Acad. I need to input media names but would rather input the height & width. As each time our printers are updated or traded for new ones the papermedia names change depending on the drivers. I'd like this to be as dynamic as possible without relying on the variable my print drivers introduce to the equation.
Referencing Kean's blog: http://through-the-interface.typepad.com/through_the_interface/2007/10/allowing-select.html
Another approach for setting the media name is to use PlotSettingsValidator.SetClosestMediaName() to choose the media name that most closely matches the paper size you desire.
Anyone ever used the .SetClosestMediaName function?
I'm thinking this method would solve my problem. Any experience on this ?
Once I set the MediaName I still need that name for adding a new plotconfigurationname
If it changes or it slightly off... then what?
- psv.SetPlotConfigurationName(pl, sPlotDeviceName, sCanonicalMediaName)
My AddPlotConfig Method
Public Sub AddPlotSetting_ToCurrentLayout_VBNET( _ ByVal sPageSetupName As String, _ ByVal sPlotDeviceName As String, _ ByVal sCanonicalMediaName As String, _ ByVal dPaperHeight As Double, _ ByVal dPaperWidth As Double, _ ByVal iPlotType As Autodesk.AutoCAD.DatabaseServices.PlotType, _ ByVal isPlotCentered As Boolean, _ ByVal iFitToPaper As StdScaleType, _ ByVal isStandardScale As Boolean, _ ByVal sStyleSheetName As String, _ ByVal isPlotStylesOn As Boolean, _ ByVal iPlotRotation As PlotRotation, _ ByVal xOffset As Double, _ ByVal yOffset As Double, _ ByVal isPlotDefault As Boolean) ed.WriteMessage("SetupName: " & sPageSetupName & Environment.NewLine) ed.WriteMessage("DeviceName: " & sPlotDeviceName & Environment.NewLine) ed.WriteMessage("MediaName: " & sCanonicalMediaName & Environment.NewLine) ed.WriteMessage("CTB: " & sStyleSheetName & Environment.NewLine) Try 'STEP 1. Open Drawing Transaction 'Use Current Active Drawing Dim CurrentDatabase As Database = Application.DocumentManager.MdiActiveDocument.Database 'Open Transaction Using currentTransaction As Transaction = CurrentDatabase.TransactionManager.StartTransaction '2. Get (Active/Current) Layout ID (Model/Paper Space) Dim layoutId As ObjectId = LayoutManager.Current.GetLayoutId(LayoutManager.Current.CurrentLayout) Dim activeLyt As Layout = currentTransaction.GetObject(layoutId, OpenMode.ForRead) '3. Create New PlotSetting with 'Create PlotSetting in LayoutObject (Write Mode) Dim pl As PlotSettings = New PlotSettings(True) '4. Use CopyFrom property of the plotsetting to intialize it on the Layout pl.CopyFrom(activeLyt) '4.B Use Plot Settings Validator 'Create PlotSettingsValidator & Populate PlotSettings Dim psv As PlotSettingsValidator = PlotSettingsValidator.Current 'Refresh Lists psv.RefreshLists(pl) '[1][PageSetup Name] pl.PlotSettingsName = sPageSetupName '[2-3][Printer/CanonicalMediaName] & [PaperSize] '[3] Set CanonicalMediaName Dim CanonicalList As StringCollection = psv.GetCanonicalMediaNameList(pl) 'Test if CanonicalInputName is Valid If CanonicalList.Contains(sCanonicalMediaName) = True Then psv.SetPlotConfigurationName(pl, sPlotDeviceName, sCanonicalMediaName) Else MsgBox("Problem with " & sCanonicalMediaName) 'If Not Find Closest Media Name Match psv.SetClosestMediaName(pl, dPaperWidth, dPaperHeight, PlotPaperUnit.Inches, True) End If '[2] Set the plot device to use 'Validates if Printer Name exists in Windows Dim PrinterList As StringCollection = psv.GetPlotDeviceList If PrinterList.Contains(sPlotDeviceName) Then '[2] Add Print Device psv.SetPlotConfigurationName(pl, sPlotDeviceName, sCanonicalMediaName) Else 'Add Missing Printer to Computer Func.AddPrinterToComputer(Trim(sPlotDeviceName)) 'Refresh (Rebuilds the plot, canonical media, and plot style table arrays to reflect the current system state) psv.RefreshLists(pl) 'Error Message If PrinterList.Contains(sPlotDeviceName) = False Then MsgBox("Can't Find Printer Named: " & sPlotDeviceName & vbCrLf & _ "This Page Setup Will Not Load Properly") Exit Sub End If '[2] Add Print Device psv.SetPlotConfigurationName(pl, sPlotDeviceName, sCanonicalMediaName) End If '[4][Plot Area] psv.SetPlotType(pl, iPlotType) '[5][Plot Offset] psv.SetPlotOrigin(pl, GetOffsetPoint(xOffset, yOffset)) '[6][Center the Plot] 'Center the plot psv.SetPlotCentered(pl, isPlotCentered) '[7][Plot Fit To Paper] psv.SetStdScaleType(pl, iFitToPaper) '[8][Plot Scale] psv.SetUseStandardScale(pl, isStandardScale) '[10][Plot Style Table] (Pen Assignments) Dim StyleList As StringCollection = psv.GetPlotStyleSheetList If StyleList.Contains(sStyleSheetName) Then psv.SetCurrentStyleSheet(pl, sStyleSheetName) Else MsgBox("Can't Find PenTable Name: " & sStyleSheetName & vbCrLf & _ "This Page Setup Will Not Load Properly") Exit Sub End If '[Shaded viewport Options] '[11][Plot Options] pl.PlotPlotStyles = isPlotStylesOn 'pl.PrintLineweights = isPlotLineWeightsOn '[12][Drawing Orientation] psv.SetPlotRotation(pl, iPlotRotation) If isPlotDefault Then 'Make Default PageSetup Yes/No? psv.SetDefaultPlotConfig(pl) End If '5. Add to the PlotSettings Dictionary (Adds to the Drawing Database) 'Add to Plot Settings to Drawing Database pl.AddToPlotSettingsDictionary(CurrentDatabase) '6. AddNewlyCreatedDBOject to the Transaction (Adds it to the Transaction) 'This Line of Code is essential currentTransaction.AddNewlyCreatedDBObject(pl, True) '7. Refresh the The Plotsettings with Plotsettings Validator psv.RefreshLists(pl) '8. Commit Current Transaction 'Commit Transaction & Save to Database currentTransaction.Commit() End Using Catch ex As Exception MsgBox(ex.Message) End Try End Sub