• Industries
  • Products
  • Buy
  • Services & Support
  • Communities
  • Discussion Groups

    .NET

    Reply
    Distinguished Contributor
    Posts: 130
    Registered: ‎09-26-2008
    Accepted Solution

    eDeviceNotFound Error when validating PlotInfo

    149 Views, 6 Replies
    01-21-2013 11:34 AM

    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)

       

    Please use plain text.
    ADN Support Specialist
    Balaji_Ram
    Posts: 343
    Registered: ‎03-21-2011

    Re: eDeviceNotFound Error when validating PlotInfo

    01-24-2013 10:34 AM 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

    Please use plain text.
    Distinguished Contributor
    Posts: 130
    Registered: ‎09-26-2008

    Re: eDeviceNotFound Error when validating PlotInfo

    01-28-2013 08:51 PM 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? 

    Please use plain text.
    ADN Support Specialist
    Balaji_Ram
    Posts: 343
    Registered: ‎03-21-2011

    Re: eDeviceNotFound Error when validating PlotInfo

    01-29-2013 11:01 PM 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

    Please use plain text.
    Distinguished Contributor
    Posts: 130
    Registered: ‎09-26-2008

    Re: eDeviceNotFound Error when validating PlotInfo

    01-30-2013 09:59 PM 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.

     

     

     

    Please use plain text.
    ADN Support Specialist
    Balaji_Ram
    Posts: 343
    Registered: ‎03-21-2011

    Re: eDeviceNotFound Error when validating PlotInfo

    01-30-2013 10:30 PM 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

    Please use plain text.
    Distinguished Contributor
    Posts: 130
    Registered: ‎09-26-2008

    Re: eDeviceNotFound Error when validating PlotInfo

    02-04-2013 06:47 AM 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.

    Please use plain text.