1500字范文,内容丰富有趣,写作好帮手!
1500字范文 > 关于cad生成dwf文件和插入dwf快

关于cad生成dwf文件和插入dwf快

时间:2018-09-05 02:37:00

相关推荐

关于cad生成dwf文件和插入dwf快

打印当前的dwg文件,生成dwf文件。传入你要存入的filename(dwf文件位置具体到.dwf)

public static bool ExportMapToFileCAD(string fileName){try{Document doc = acDoc;Editor ed = doc.Editor;Database db = doc.Database;if (fileName.Trim().Equals("")) return false;using (doc.LockDocument()){using (Transaction tr = db.TransactionManager.StartTransaction()){// 将打印当前布局 BlockTableRecord btr = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);Layout lo = (Layout)tr.GetObject(btr.LayoutId, OpenMode.ForWrite);// lo.PlotRotation// 需要一个与布局有关的PlotInfo对象 PlotInfo pi = new PlotInfo();pi.Layout = btr.LayoutId;// 需要一个基于布局设置的PlotSettings对象,这样我们就可以进行自定义设置 PlotSettings ps = new PlotSettings(lo.ModelType);ps.CopyFrom(lo);// PlotSettingsValidator对象帮助我们创建一个有效的PlotSettings对象PlotSettingsValidator psv = PlotSettingsValidator.Current;//进行范围打印、中心打印和按比例打印 psv.SetPlotType(ps, Autodesk.AutoCAD.DatabaseServices.PlotType.Extents);psv.SetPlotRotation(ps, PlotRotation.Degrees000);psv.SetStdScaleType(ps, StdScaleType.ScaleToFit);// psv.SetUseStandardScale(ps, true);//标准打印比例// psv.SetStdScaleType(ps, StdScaleType.ScaleToFit);psv.SetPlotCentered(ps, true);//居中打印//psv.SetPlotOrigin(ps,new Point2d(1.5,0));//打印到文件psv.SetPlotConfigurationName(ps, "DWF6 ePlot.pc3", "ISO_A2_(594.00_x_420.00_MM)");psv.SetUseStandardScale(ps, true);// 把PlotInfo链接到PlotSettings并验证它的有效性 pi.OverrideSettings = ps;PlotInfoValidator piv = new PlotInfoValidator();piv.MediaMatchingPolicy = MatchingPolicy.MatchEnabled;piv.Validate(pi);// PlotEngine对象执行真正的打印工作if (PlotFactory.ProcessPlotState == ProcessPlotState.NotPlotting){PlotEngine pe = PlotFactory.CreatePublishEngine();using (pe){//创建一个打印对话框,用于提供打印信息和允许用户取消打印 PlotProgressDialog ppd = new PlotProgressDialog(false, 1, true);using (ppd){ppd.set_PlotMsgString(PlotMessageIndex.DialogTitle, "CAD切图");ppd.set_PlotMsgString(PlotMessageIndex.CancelJobButtonMessage, "取消切图");ppd.set_PlotMsgString(PlotMessageIndex.CancelSheetButtonMessage, "取消切图");ppd.set_PlotMsgString(PlotMessageIndex.SheetSetProgressCaption, "切图");ppd.set_PlotMsgString(PlotMessageIndex.SheetProgressCaption, "正在切图");ppd.LowerPlotProgressRange = 0;ppd.UpperPlotProgressRange = 100;ppd.PlotProgressPos = 0;//启动打印 ppd.OnBeginPlot();ppd.IsVisible = true;pe.BeginPlot(ppd, null);// 打印一个单文档pe.BeginDocument(pi, fileName, null, 1, true, fileName);//int count = doc.Name.ToString().LastIndexOf('\\', doc.Name.Length);//string fileName = doc.Name.ToString().Substring(count, doc.Name.ToString().Length - count);//只包含一个图纸ppd.OnBeginSheet();ppd.LowerSheetProgressRange = 0;ppd.UpperSheetProgressRange = 100;ppd.SheetProgressPos = 0;PlotPageInfo ppi = new PlotPageInfo();pe.BeginPage(ppi, pi, true, null);pe.BeginGenerateGraphics(null); pe.EndGenerateGraphics(null);// 结束图纸pe.EndPage(null);ppd.SheetProgressPos = 100;ppd.OnEndSheet();// 结束文档pe.EndDocument(null);// 结束打印ppd.PlotProgressPos = 100;ppd.OnEndPlot();pe.EndPlot(null);}}}else{ed.WriteMessage("\n另外一个程序正在运行中。。。");}}}return true;}catch (Exception ex){throw ex;}}将dwf插入dwg<pre name="code" class="csharp"> /// <summary>加载dwf文件/// </summary>/// <param name="fileName">dwf路径</param>/// <param name="dwfName">dwf名称</param>public static void CommandInsertDWF(string fileName, string dwfName){try{// acess the databaseDatabase db = CurrentDB;// start the transactionusing (Transaction trans = db.TransactionManager.StartTransaction()){// get the NODDBDictionary nod = trans.GetObject(db.NamedObjectsDictionaryId, OpenMode.ForWrite) as DBDictionary;// get the key for DWF Definitionstring defDictKey = UnderlayDefinition.GetDictionaryKey(typeof(DwfDefinition));// if the dictionary is not there, createif (!nod.Contains(defDictKey)){using (DBDictionary dict = new DBDictionary()){nod.SetAt(defDictKey, dict);trans.AddNewlyCreatedDBObject(dict, true);}}// open the dictionaryObjectId idDwfDef;DBDictionary dwfDict = trans.GetObject(nod.GetAt(defDictKey), OpenMode.ForWrite) as DBDictionary;// create a new definitionusing (DwfDefinition dwfDef = new DwfDefinition()){dwfDef.SourceFileName = fileName;idDwfDef = dwfDict.SetAt(dwfName, dwfDef);trans.AddNewlyCreatedDBObject(dwfDef, true);}// append to the model spaceBlockTable bt = trans.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;BlockTableRecord btr = trans.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;using (DwfReference dwf = new DwfReference()){dwf.DefinitionId = idDwfDef;btr.AppendEntity(dwf);trans.AddNewlyCreatedDBObject(dwf, true);}// create reference for Model space 将淡入度设为零,保证每次打印的时候图片颜色不会变浅using (UnderlayReference ur = new DwfReference()){ur.DefinitionId = idDwfDef;//设置淡入度ur.Fade = 0;//设置对比度ur.Contrast = 100;btr.AppendEntity((Entity)ur);trans.AddNewlyCreatedDBObject((DBObject)ur, true);}mit();}}catch (System.Exception ex){ }}

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。