.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

eDeviceNotFound Error when validating PlotInfo

6 REPLIES 6
SOLVED
Reply
Message 1 of 7
HJohn1
930 Views, 6 Replies

eDeviceNotFound Error when validating PlotInfo

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)

   

6 REPLIES 6
Message 2 of 7
Balaji_Ram
in reply to: HJohn1

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

Message 3 of 7
HJohn1
in reply to: Balaji_Ram

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? 

Message 4 of 7
Balaji_Ram
in reply to: HJohn1

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

Message 5 of 7
HJohn1
in reply to: Balaji_Ram

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.

 

 

 

Message 6 of 7
Balaji_Ram
in reply to: HJohn1

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

Message 7 of 7
HJohn1
in reply to: Balaji_Ram

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

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost