Aller au contenu

Problème de tracé en PDF


Messages recommandés

Bonjour à tous,

 

J'utilise ce code pour effectuer mon tracé en PDF.

 

// (C) Copyright 2013 by  
//
using System;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.PlottingServices;
using System.IO;

// This line is not mandatory, but improves loading performances
[assembly: CommandClass(typeof(TestPlot.MyCommands))]

namespace TestPlot
{

   // This class is instantiated by AutoCAD for each document when
   // a command is called by the user the first time in the context
   // of a given document. In other words, non static data in this class
   // is implicitly per-document!
   public class MyCommands
   {
       [CommandMethod("PlotEx")]
       public void PlotEx()
       {
           Application.SetSystemVariable("BACKGROUNDPLOT", 0);
           using (Transaction tr = Application.DocumentManager.MdiActiveDocument.TransactionManager.StartTransaction())
           {
               try
               {
                   LayoutManager layMgr = LayoutManager.Current;
                   ObjectId loObjId = layMgr.GetLayoutId(layMgr.CurrentLayout);
                   Layout lo = (Layout)tr.GetObject(loObjId, OpenMode.ForRead);
                   PlotSettings ps = new PlotSettings(lo.ModelType);
                   ps.CopyFrom(lo);
                   PlotInfo pi = new PlotInfo();
                   pi.Layout = loObjId;
                   PlotSettingsValidator psv = Autodesk.AutoCAD.DatabaseServices.PlotSettingsValidator.Current;
                   psv.SetPlotConfigurationName(ps, "DWG To PDF.pc3", "ANSI_B_(11.00_x_17.00_Inches)");
                   psv.RefreshLists(ps);
                   psv.SetPlotType(ps, Autodesk.AutoCAD.DatabaseServices.PlotType.Extents);
                   psv.SetUseStandardScale(ps, true);
                   psv.SetStdScaleType(ps, StdScaleType.ScaleToFit);
                   pi.OverrideSettings = ps;
                   PlotEngine pe = PlotFactory.CreatePublishEngine();
                   try
                   {
                       pe.BeginPlot(null, null);
                       PlotInfoValidator validator = new PlotInfoValidator();
                       validator.MediaMatchingPolicy = Autodesk.AutoCAD.PlottingServices.MatchingPolicy.MatchEnabled;
                       validator.Validate(pi);
                       string plotFile = Path.GetFullPath(Application.DocumentManager.MdiActiveDocument.Database.Filename);
                       plotFile = plotFile.Remove(plotFile.Length - 4);
                       pe.BeginDocument(pi, Application.DocumentManager.MdiActiveDocument.Database.Filename, null, 1, true, plotFile + ".pdf");
                       PlotPageInfo pageInfo = new PlotPageInfo();
                       pe.BeginPage(pageInfo, pi, true, null);
                       pe.BeginGenerateGraphics(null);
                       pe.EndGenerateGraphics(null);
                       pe.EndPage(null);
                       pe.EndDocument(null);
                       pe.EndPlot(null);
                   }
                   catch (System.Exception ex)
                   {
                       System.Windows.Forms.MessageBox.Show(ex.Message);
                   }
                   pe.Destroy();
                   tr.Commit();
               }
               catch (System.Exception ex)
               {
                   System.Windows.Forms.MessageBox.Show(ex.Message);
               }
           }
       }
   }

}

 

Tel quel il fontionne correctement.

 

Le problème survient quand je veux utiliser un format de papier personalisé.

 

J'obtient un message d'erreur m'indiquant que j'ai fournis une valeur invalide.

 

Quelqu'un à t'il déja rencontré ce problème ?

 

Merci d'avance.

http://www.carpetdiem.net

Plugins pour AutoCAD

Lien vers le commentaire
Partager sur d’autres sites

Salut,

 

Tu trouveras sur TheSwamp un exemple qui utilise un fichier DSD temporaire (équivalent à la commande publier) et prend en compte le format de papier spécifié dans le gestionnaire du tracé de la (ou des) présentation(s).

 

Cet exemple permet de créer un fichier PDF multi-feuilles, mais peut très bien ne tracer qu'une seule présentation.

Gilles Chanteau - gileCAD - GitHub
Développements sur mesure pour AutoCAD

Lien vers le commentaire
Partager sur d’autres sites

Créer un compte ou se connecter pour commenter

Vous devez être membre afin de pouvoir déposer un commentaire

Créer un compte

Créez un compte sur notre communauté. C’est facile !

Créer un nouveau compte

Se connecter

Vous avez déjà un compte ? Connectez-vous ici.

Connectez-vous maintenant
×
×
  • Créer...

Information importante

Nous avons placé des cookies sur votre appareil pour aider à améliorer ce site. Vous pouvez choisir d’ajuster vos paramètres de cookie, sinon nous supposerons que vous êtes d’accord pour continuer. Politique de confidentialité