乐筑天下

搜索
欢迎各位开发者和用户入驻本平台 尊重版权,从我做起,拒绝盗版,拒绝倒卖 签到、发布资源、邀请好友注册,可以获得银币 请注意保管好自己的密码,避免账户资金被盗
查看: 23|回复: 1

简单的 dwg 到 pdf 绘图

[复制链接]

1

主题

1

帖子

1

银币

初来乍到

Rank: 1

铜币
5
发表于 2011-5-27 11:33:50 | 显示全部楼层 |阅读模式
大家好,
我只是想在不打开AutoCAD或任何其他外部dwg查看器的情况下将dwg文件转换为pdf格式。我遵循了.NET开发指南中的概要(http://docs.autodesk.com/ACD/2010/ENU/AutoCAD%20.NET%20Developer这是%20Guide/index.html吗?url=WS1a9193826455f5ff2566ffd511ff6f8c7ca-33b0.htm,topicNumber=d0e50852)以及其他开发人员的帮助(
http://through-the-interface.typepad.com/through_the_interface/2007/10/previewing-and-.html
)但我已经被无数的错误所困扰
首先,打开外部文件的最佳格式是什么?文档管理员。Open()命令或数据库。readDWGFile()
其次,DocumentManager也会这样做。MdiActiveDocument=以前打开的文件,是否建立“当前”文件?每个解决方案都需要访问“当前”文档,这是否可行?
那么[CommandMethod(“XXXX”)]有什么意义吗?如果是这样,我将使用什么来打印/转换单个DWG文件?‘Simplot?
最后,表单“Autodesk.AutoCAD.ApplicationServices”出现错误的原因是什么。XXXXX是否没有实施?我确保所有引用的“复制本地”功能设置为False
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using System.Reflection;
  5. using System.ComponentModel;
  6. using Autodesk.AutoCAD.EditorInput;
  7. using Autodesk.AutoCAD.Runtime;
  8. using Autodesk.AutoCAD.DatabaseServices;
  9. using Autodesk.AutoCAD.PlottingServices;
  10. //using Autodesk.AutoCAD.ApplicationServices;
  11. using Autodesk.AutoCAD.Geometry;
  12. using CAD_AS = Autodesk.AutoCAD.ApplicationServices;
  13. namespace ......(ommitted)
  14. {
  15.     class AutoCADToPDF : (abstract class ommitted)
  16.     {
  17.         
  18.         public AutoCADToPDF()
  19.         { }
  20.         [CommandMethod("simplot")]
  21.         public override string Convert(string filein)
  22.         {
  23.          
  24.            //**FILE IN STRING ERROR CHECK HERE
  25.            //**Make a try/catch statement
  26.            //Open the drawing; read-only
  27.             Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.Open(filein, true);
  28.             
  29.            //Establish as current, active document
  30.            CAD_AS.Application.DocumentManager.MdiActiveDocument = dwg;
  31.            //**Probably unecessary, but setting document to Active
  32.            CAD_AS.Document doc = CAD_AS.Application.DocumentManager.MdiActiveDocument;
  33.            
  34.            //Initalize the editor
  35.            Editor edit = doc.Editor;
  36.            //Initalize the database by loading the drawing into it
  37.            Database db = doc.Database;
  38.             
  39.             //Start a new transaction against the open drawing
  40.             using (Transaction tr = db.TransactionManager.StartTransaction())
  41.             {
  42.                 //Reference the Layout Manager
  43.                 LayoutManager layman = LayoutManager.Current;
  44.                
  45.                 //Open layout as read-only
  46.                 Layout layout  = (Layout)tr.GetObject(layman.GetLayoutId(layman.CurrentLayout),OpenMode.ForRead);
  47.                 //Create plot info for layout
  48.                 PlotInfo plotInfo = new PlotInfo();
  49.                 plotInfo.Layout = layout.ObjectId;
  50.                 //Copy plot settings from layout
  51.                 PlotSettings settings = new PlotSettings(layout.ModelType);
  52.                 settings.CopyFrom(layout);
  53.                 //Retrieve the current plot settings validator
  54.                 PlotSettingsValidator setValidator = PlotSettingsValidator.Current;
  55.                 //Set Plot type
  56.                 setValidator.SetPlotType(settings, Autodesk.AutoCAD.DatabaseServices.PlotType.Extents);
  57.                
  58.                 //Set the Plot Scale and center the plot
  59.                 setValidator.SetUseStandardScale(settings, true);
  60.                 setValidator.SetStdScaleType(settings, StdScaleType.ScaleToFit);
  61.                 setValidator.SetPlotCentered(settings, true);
  62.                 //Set the plotter and media
  63.                 setValidator.SetPlotConfigurationName(settings, "DWG to PDF.pc3", "ANSI_A_(8.50 x 11.00 Inches)");
  64.                 //Link plot settings to plot info
  65.                 //**Override not needed?
  66.                 plotInfo.OverrideSettings = settings;
  67.                 PlotInfoValidator infoValidator = new PlotInfoValidator();
  68.                 infoValidator.MediaMatchingPolicy = MatchingPolicy.MatchEnabled;
  69.                 infoValidator.Validate(plotInfo);
  70.                 //Check to see if a plot is already in progress
  71.                 if(PlotFactory.ProcessPlotState != ProcessPlotState.NotPlotting)
  72.                 {
  73.                     throw new ConvertException("Cannot proceed, another plot is in progress !");
  74.                 }
  75.                 //Plot the document
  76.                 using (PlotEngine engine = PlotFactory.CreatePublishEngine())
  77.                 {
  78.                     //Silence the plot dialogue
  79.                     PlotProgressDialog dlg = new PlotProgressDialog(false, 1, true);
  80.                     dlg.OnBeginPlot();
  81.                     dlg.IsVisible = false;
  82.                     
  83.                     //SPecify plot destination
  84.                     engine.BeginPlot(dlg, null);
  85.                     engine.BeginDocument(plotInfo, filein, null, 1, true, @"D:");
  86.                     //Plot the first sheet
  87.                     PlotPageInfo pageInfo = new PlotPageInfo();
  88.                     engine.BeginPage(pageInfo, plotInfo, true, null);
  89.                     engine.BeginGenerateGraphics(null);
  90.                     engine.EndGenerateGraphics(null);
  91.                     //End plotting sheet
  92.                     engine.EndPage(null);
  93.                     engine.EndDocument(null);
  94.                     //Finish plot
  95.                     dlg.OnEndPlot();
  96.                     engine.EndPlot(null);
  97.                 }
  98.             }
  99.             return @"D:";
  100.             return null;
  101.         } //End Convert
  102.     }
  103. }

本帖以下内容被隐藏保护;需要你回复后,才能看到!

游客,如果您要查看本帖隐藏内容请回复
回复

使用道具 举报

15

主题

190

帖子

5

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
250
发表于 2011-5-27 16:45:16 | 显示全部楼层
。NET API将无法在正在运行的AutoCAD实例之外工作。您需要许可AutoCAD OEM,以便您可以构建自己的主机应用程序,或使用许多其他DWG库之一来读取和处理DWG文件。
回复

使用道具 举报

发表回复

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

QQ|关于我们|小黑屋|乐筑天下 繁体中文

GMT+8, 2025-2-5 16:53 , Processed in 0.206417 second(s), 56 queries .

© 2020-2025 乐筑天下

联系客服 关注微信 帮助中心 下载APP 返回顶部 返回列表