eDeviceNotFound Error when validating PlotInfo

eDeviceNotFound Error when validating PlotInfo

HJohn1
Advocate Advocate
1,678 Views
6 Replies
Message 1 of 7

eDeviceNotFound Error when validating PlotInfo

HJohn1
Advocate
Advocate

I am having problems when trying to modify Layouts plot settings.  I am using the same approach to plot the layouts and it works fine.  Also, it works well when modifying the plot settings for the ModelSpace layout.  I don't know what the problem is.  The ConfigurationName is correct, so is the CanonicalMediaName and the Scale.  I am not very clear about this process. Can someone take a look at my code and help me to figure out what is the problem. 

 

Try

                Trans = db.TransactionManager.StartTransaction

                TableRec = CType(Trans.GetObject(db.CurrentSpaceId, OpenMode.ForWrite), BlockTableRecord)

                Layout = CType(Trans.GetObject(TableRec.LayoutId, OpenMode.ForWrite), Layout)

                PltSettings = New PlotSettings(Layout.ModelType)

                PltSettings.CopyFrom(Layout)

                PSValidator = PlotSettingsValidator.Current

                PSValidator.SetPlotConfigurationName(PltSettings, PlotInformation.PrinterName, PlotInformation.PaperSize)

                PSValidator.SetUseStandardScale(PltSettings, True)

                PSValidator.SetStdScaleType(PltSettings, PlotInformation.PlotScale)

                PSValidator.SetPlotType(PltSettings, PlotInformation.PlotExtents)

                PSValidator.SetPlotCentered(PltSettings, False)

                PSValidator.RefreshLists(PltSettings)

                PltInfo = New PlotInfo

                PltInfo.Layout = TableRec.LayoutId

                PltInfo.ValidatedSettings = PltSettings

                PltInfoValidator = New PlotInfoValidator

                PltInfoValidator.MediaMatchingPolicy = MatchingPolicy.MatchEnabled

                PltInfoValidator.Validate(PltInfo)

                Layout.CopyFrom(PltSettings)

                Trans.Commit()

                Return True

            Catch ex As Exception

                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)

                Return False

            End Try

 I am getting the error message "eDeviceNotFound" on the line

 

PltInfoValidator.Validate(PltInfo)

   

0 Likes
Accepted solutions (1)
1,679 Views
6 Replies
Replies (6)
Message 2 of 7

Balaji_Ram
Alumni
Alumni

Hi John,

 

Here is a blog post that explains a way to list all the available media names and to choose one of them.

 

http://through-the-interface.typepad.com/through_the_interface/2007/10/allowing-select.html

 

From the sample code in the blog post, you can make use of the “ChooseDeviceAndMedia” as :

 

<code>

String[] deviceAndMedia = new String[2];

deviceAndMedia = ChooseDeviceAndMedia();

String device = deviceAndMedia[0];

String media = deviceAndMedia[1];

</code>

 

This will help rule out any issues with incorrect device / media names.

 

If you still have the issue, can you please share the full code for me to reproduce the error ?

 

 



Balaji
Developer Technical Services
Autodesk Developer Network

0 Likes
Message 3 of 7

HJohn1
Advocate
Advocate

Balaji, thank you for your suggestion.  I get the canonicalmedialist to populate a dropdown to allow the user to select the desired media name.  The program works fine when updating the plotsetting of the model space layout.  I only get the error message when I try to update a paper space layout.  Is there any difference between updating the model and paper space layouts? 

0 Likes
Message 4 of 7

Balaji_Ram
Alumni
Alumni

Hi John,

 

Are you passing "false" as the parameter to the "PlotSettings" constructor. For modelspace layout, it is "true" and for paperspace layouts it is "false". The convenient way is to use the "Layout.ModelType" to get this parameter right.

 

Here is a sample code that set the plot settings for a paperspace layout.

 

Hope this helps in identifying the issue with your code. If this does not help, can you please share a code snippet for me to reproduce the error ?

 

[CommandMethod("SetPS")]
public void SetPSMethod()
{
    Document doc = Application.DocumentManager.MdiActiveDocument;
    Editor ed = doc.Editor;
    Database db = doc.Database;

    Transaction tr = db.TransactionManager.StartTransaction();
    using (tr)
    {
        BlockTableRecord btr = tr.GetObject(db.CurrentSpaceId, OpenMode.ForRead) as BlockTableRecord;
        Layout lo = tr.GetObject(btr.LayoutId, OpenMode.ForRead) as Layout;

        PlotInfo pi = new PlotInfo();
        pi.Layout = btr.LayoutId;

        PlotSettings ps = new PlotSettings(lo.ModelType);
        ps.CopyFrom(lo);

        PlotSettingsValidator psv = PlotSettingsValidator.Current;

        psv.SetPlotType(ps, Autodesk.AutoCAD.DatabaseServices.PlotType.Extents);
        psv.SetUseStandardScale(ps, true);
        psv.SetStdScaleType(ps, StdScaleType.ScaleToFit);
        psv.SetPlotCentered(ps, true);

        psv.SetPlotConfigurationName(ps, "DWG To PDF.pc3", "ANSI_A_(8.50_x_11.00_Inches)");

        pi.OverrideSettings = ps;
        PlotInfoValidator piv = new PlotInfoValidator();
        piv.MediaMatchingPolicy = MatchingPolicy.MatchEnabled;
        piv.Validate(pi);

        lo.UpgradeOpen();
        lo.CopyFrom(ps);
        tr.Commit();
    }
}

 

 

 

 

 

 

 



Balaji
Developer Technical Services
Autodesk Developer Network

0 Likes
Message 5 of 7

HJohn1
Advocate
Advocate

Yes, I am.  if you look at the fourth code line [ PltSettings = New PlotSettings(Layout.ModelType) ] you can see it.  Now, one thing I am not clear about, what is the difference of [ PltInfo.ValidatedSettings = PltSettings ] as in my code or in your example [ pi.OverrideSettings = ps; ] apart from VB and C#? I would like to save the settings back to the Layout, simillar to Applaying the settings in the plot dialog box.  Thanks for your help.

 

 

 

0 Likes
Message 6 of 7

Balaji_Ram
Alumni
Alumni
Accepted solution

Hi John,

 

To include proper error checking it is necessary to check if the plotInfo is validated and if so, access the ValidatedSettings. This is set after the validation is done by the Validate method. So it is not necessary for us to set it.

 

Here is the change to include such error checking

 

pi.OverrideSettings = ps;
PlotInfoValidator piv = new PlotInfoValidator();
piv.MediaMatchingPolicy = MatchingPolicy.MatchEnabled;
piv.Validate(pi);

if (pi.IsValidated)
{
    lo.UpgradeOpen();
    lo.CopyFrom(pi.ValidatedSettings);
}

Have you tried the sample code from my previous reply.

It does save the plot settings to the layout.



Balaji
Developer Technical Services
Autodesk Developer Network

0 Likes
Message 7 of 7

HJohn1
Advocate
Advocate

Balaji thank you very much for your help.  I made the change you suggested and I am not getting the error message any more.

0 Likes