|
|
|
|
|
/************************************************************************************
|
|
|
|
|
|
* Copyright (c) 2018 All Rights Reserved.
|
|
|
|
|
|
* CLR版本: 4.0.30319.36399
|
|
|
|
|
|
*机器名称:HUBING
|
|
|
|
|
|
*公司名称:杭州康勒科技有限公司
|
|
|
|
|
|
*命名空间:HelloTeamcenter.hello
|
|
|
|
|
|
*文件名: PrintDwg2
|
|
|
|
|
|
*版本号: V1.0.0.0
|
|
|
|
|
|
*唯一标识:fd6d1fc7-779a-4ab6-8136-3c5bc87fbd75
|
|
|
|
|
|
*当前的用户域:HUBING
|
|
|
|
|
|
*创建人: hub
|
|
|
|
|
|
*电子邮箱:hub@connor.net.cn
|
|
|
|
|
|
*创建时间:2018/6/29 14:25:02
|
|
|
|
|
|
*描述:
|
|
|
|
|
|
*
|
|
|
|
|
|
*=====================================================================
|
|
|
|
|
|
*修改标记
|
|
|
|
|
|
*修改时间:2018/6/29 14:25:02
|
|
|
|
|
|
*修改人: hub
|
|
|
|
|
|
*版本号: V1.0.0.0
|
|
|
|
|
|
*描述:
|
|
|
|
|
|
*
|
|
|
|
|
|
/************************************************************************************/
|
|
|
|
|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
using System.Linq;
|
|
|
using System.Text;
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
//*******************************************//
|
|
|
// Type Library //
|
|
|
//*******************************************//
|
|
|
//using ZwSoft.ZwCAD.Customization; //accui.dll
|
|
|
|
|
|
//*******************************************//
|
|
|
// acdbmgd.dll //
|
|
|
//*******************************************//
|
|
|
|
|
|
using ZwSoft.ZwCAD.Runtime;
|
|
|
using ZwSoft.ZwCAD.LayerManager;
|
|
|
using ZwSoft.ZwCAD.GraphicsSystem;
|
|
|
using ZwSoft.ZwCAD.GraphicsInterface;
|
|
|
using ZwSoft.ZwCAD.Geometry;
|
|
|
using ZwSoft.ZwCAD.DatabaseServices.Filters;
|
|
|
using ZwSoft.ZwCAD.DatabaseServices;
|
|
|
using ZwSoft.ZwCAD.Colors;
|
|
|
//******************************************//
|
|
|
|
|
|
//--------------------------------------------//
|
|
|
|
|
|
// acmgd.dll //
|
|
|
|
|
|
//------------------------------------------*//
|
|
|
//using ZwSoft.ZwCAD.Windows.ToolPalette;
|
|
|
using ZwSoft.ZwCAD.Windows;
|
|
|
using ZwSoft.ZwCAD.Publishing;
|
|
|
using ZwSoft.ZwCAD.PlottingServices;
|
|
|
using ZwSoft.ZwCAD.EditorInput;
|
|
|
using ZwSoft.ZwCAD.ApplicationServices;
|
|
|
using AcAp = ZwSoft.ZwCAD.ApplicationServices.Application;
|
|
|
using DataSvr = ZwSoft.ZwCAD.DatabaseServices;
|
|
|
using System.Collections;
|
|
|
using System.Threading;
|
|
|
using System.Collections.Specialized;
|
|
|
namespace KCad2
|
|
|
{
|
|
|
|
|
|
public class FrameCompare : IComparer
|
|
|
{
|
|
|
// Calls CaseInsensitiveComparer.Compare with the parameters reversed.
|
|
|
int IComparer.Compare(Object x, Object y)
|
|
|
{
|
|
|
if (string.Compare((x as PrintFrame).BKName, (y as PrintFrame).BKName, true) == 0)
|
|
|
{
|
|
|
return 0;
|
|
|
}
|
|
|
return -1;
|
|
|
}
|
|
|
}
|
|
|
public class PrintFrame
|
|
|
{
|
|
|
public string BKName
|
|
|
{
|
|
|
get;
|
|
|
set;
|
|
|
}
|
|
|
public string MediaName
|
|
|
{
|
|
|
get;
|
|
|
set;
|
|
|
}
|
|
|
public Extents2d PrintBound
|
|
|
{
|
|
|
get;
|
|
|
set;
|
|
|
|
|
|
}
|
|
|
public DataSvr.PlotRotation Rotation
|
|
|
{
|
|
|
get;
|
|
|
set;
|
|
|
}
|
|
|
public void Clone(PrintFrame obj)
|
|
|
{
|
|
|
BKName = obj.BKName;
|
|
|
MediaName = obj.MediaName;
|
|
|
PrintBound = obj.PrintBound;
|
|
|
Rotation = obj.Rotation;
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
public class PrintDwg
|
|
|
{
|
|
|
|
|
|
private ArrayList m_Frame = null;
|
|
|
public PrintDwg(Document doc)
|
|
|
{
|
|
|
m_Frame = new ArrayList();
|
|
|
m_Frame.Add(new PrintFrame() { BKName = "KHGY-TH", MediaName = "ISO_expand_A4_(297.00_x_210.00_MM)", Rotation = DataSvr.PlotRotation.Degrees000 });
|
|
|
m_Frame.Add(new PrintFrame() { BKName = "KHGY-TK", MediaName = "ISO_expand_A4_(297.00_x_210.00_MM)", Rotation = DataSvr.PlotRotation.Degrees000 });
|
|
|
m_Frame.Add(new PrintFrame() { BKName = "KHTH-H", MediaName = "ISO_expand_A4_(297.00_x_210.00_MM)", Rotation = DataSvr.PlotRotation.Degrees000 });
|
|
|
m_Frame.Add(new PrintFrame() { BKName = "KHTH-H-A3", MediaName = "ISO_expand_A3_(420.00_x_297.00_MM)", Rotation = DataSvr.PlotRotation.Degrees000 });
|
|
|
m_Frame.Add(new PrintFrame() { BKName = "KHTH-Z", MediaName = "ISO_expand_A4_(297.00_x_210.00_MM)", Rotation = DataSvr.PlotRotation.Degrees090 });
|
|
|
m_Frame.Add(new PrintFrame() { BKName = "KHTH-Z-A3", MediaName = "ISO_expand_A3_(420.00_x_297.00_MM)", Rotation = DataSvr.PlotRotation.Degrees090 });
|
|
|
PrintDoc = doc;
|
|
|
}
|
|
|
|
|
|
public string MultiSheetPlot()
|
|
|
{
|
|
|
// DocumentLock m_DocumentLock = ZwSoft.ZwCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.LockDocument();
|
|
|
string path = "";
|
|
|
Database db = PrintDoc.Database;
|
|
|
//;
|
|
|
|
|
|
using (Transaction tr = db.TransactionManager.StartTransaction())
|
|
|
{
|
|
|
short bgPlot = (short)Application.GetSystemVariable("BACKGROUNDPLOT");
|
|
|
Application.SetSystemVariable("BACKGROUNDPLOT", 0);
|
|
|
|
|
|
BlockTable bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead);
|
|
|
PlotInfo pi = new PlotInfo();
|
|
|
PlotInfoValidator piv = new PlotInfoValidator();
|
|
|
|
|
|
piv.MediaMatchingPolicy = MatchingPolicy.MatchEnabled;
|
|
|
|
|
|
// A PlotEngine does the actual plotting
|
|
|
// (can also create one for Preview)
|
|
|
|
|
|
if (PlotFactory.ProcessPlotState == ProcessPlotState.NotPlotting)
|
|
|
{
|
|
|
|
|
|
|
|
|
using (PlotEngine pe = PlotFactory.CreatePublishEngine())
|
|
|
{
|
|
|
PrintFrame[] frames = CheckModelSpaceTitle();
|
|
|
// Create a Progrel.ass Dialog to provide info
|
|
|
// and allow thej user to cancel
|
|
|
|
|
|
using (PlotProgressDialog ppd = new PlotProgressDialog(false, frames.Length, true))
|
|
|
{
|
|
|
|
|
|
int numSheet = 1;
|
|
|
|
|
|
if (frames.Length < 1)
|
|
|
return "";
|
|
|
|
|
|
foreach (PrintFrame frame in frames)
|
|
|
{
|
|
|
BlockTableRecord acBlkTblRec = tr.GetObject(bt[BlockTableRecord.ModelSpace],
|
|
|
OpenMode.ForWrite) as BlockTableRecord;
|
|
|
|
|
|
Layout lo = (Layout)tr.GetObject(acBlkTblRec.LayoutId, OpenMode.ForRead);
|
|
|
|
|
|
// We need a PlotSettings object
|
|
|
// based on the layout settings
|
|
|
// which we then customize
|
|
|
PlotSettings ps = new PlotSettings(lo.ModelType);
|
|
|
ps.CopyFrom(lo);
|
|
|
|
|
|
// The PlotSettingsValidator helps
|
|
|
// create a valid PlotSettings object
|
|
|
PlotSettingsValidator psv = PlotSettingsValidator.Current;
|
|
|
|
|
|
// We'll plot the extents, centered and
|
|
|
// scaled to fit
|
|
|
StringCollection cols = psv.GetPlotStyleSheetList();
|
|
|
bool StyleSheetCheck = false;
|
|
|
foreach (string s in cols)
|
|
|
{
|
|
|
if (string.Compare(s, "monochrome.ctb", true) == 0)
|
|
|
{
|
|
|
StyleSheetCheck = true;
|
|
|
}
|
|
|
}
|
|
|
psv.SetPlotConfigurationName(ps, "DWG To PDF.pc3", frame.MediaName);
|
|
|
psv.SetPlotWindowArea(ps, frame.PrintBound);
|
|
|
psv.SetPlotType(ps, ZwSoft.ZwCAD.DatabaseServices.PlotType.Window);
|
|
|
if (!StyleSheetCheck)
|
|
|
psv.SetCurrentStyleSheet(ps, "monochrome.stb");
|
|
|
else
|
|
|
psv.SetCurrentStyleSheet(ps, "monochrome.ctb");
|
|
|
psv.SetPlotCentered(ps, true);
|
|
|
psv.SetUseStandardScale(ps, true);
|
|
|
psv.SetStdScaleType(ps, StdScaleType.ScaleToFit);
|
|
|
psv.SetPlotRotation(ps, frame.Rotation);
|
|
|
|
|
|
// We need a PlotInfo object
|
|
|
// linked to the layout
|
|
|
pi.Layout = acBlkTblRec.LayoutId;
|
|
|
|
|
|
// Make the layout we're plotting current
|
|
|
LayoutManager.Current.CurrentLayout = lo.LayoutName;
|
|
|
// We need to link the PlotInfo to the
|
|
|
// PlotSettings and then validate it
|
|
|
|
|
|
pi.OverrideSettings = ps;
|
|
|
|
|
|
piv.Validate(pi);
|
|
|
|
|
|
if (numSheet == 1)
|
|
|
{
|
|
|
ppd.set_PlotMsgString(PlotMessageIndex.DialogTitle, "Custom Plot Progress");
|
|
|
ppd.set_PlotMsgString(PlotMessageIndex.CancelJobButtonMessage, "Cancel Job");
|
|
|
ppd.set_PlotMsgString(PlotMessageIndex.CancelSheetButtonMessage, "Cancel Sheet");
|
|
|
ppd.set_PlotMsgString(PlotMessageIndex.SheetSetProgressCaption, "Sheet Set Progress");
|
|
|
ppd.set_PlotMsgString(PlotMessageIndex.SheetProgressCaption, "Sheet Progress");
|
|
|
|
|
|
ppd.LowerPlotProgressRange = 0;
|
|
|
ppd.UpperPlotProgressRange = 100;
|
|
|
ppd.PlotProgressPos = 0;
|
|
|
|
|
|
// Let's start the plot, at last
|
|
|
ppd.OnBeginPlot();
|
|
|
ppd.IsVisible = true;
|
|
|
pe.BeginPlot(ppd, null);
|
|
|
// We'll be plotting a single document // Let's plot to file
|
|
|
path = PrintDoc.Name.ToUpper().Replace(".DWG", string.Format("{0}{1}", frame.BKName, ".PDF"));
|
|
|
pe.BeginDocument(pi, PrintDoc.Name, null, 1, true, path);
|
|
|
}
|
|
|
|
|
|
// Which may contain multiple sheets
|
|
|
ppd.StatusMsgString = "Plotting " + PrintDoc.Name.Substring(PrintDoc.Name.LastIndexOf("\\") + 1) +
|
|
|
" - sheet " + numSheet.ToString() +
|
|
|
" of " + frames.Length.ToString();
|
|
|
|
|
|
ppd.OnBeginSheet();
|
|
|
ppd.LowerSheetProgressRange = 0;
|
|
|
ppd.UpperSheetProgressRange = 100;
|
|
|
ppd.SheetProgressPos = 0;
|
|
|
PlotPageInfo ppi = new PlotPageInfo();
|
|
|
|
|
|
pe.BeginPage(ppi, pi, frames.Length == numSheet, null);
|
|
|
pe.BeginGenerateGraphics(null);
|
|
|
ppd.SheetProgressPos = 50;
|
|
|
pe.EndGenerateGraphics(null);
|
|
|
|
|
|
// Finish the sheet
|
|
|
pe.EndPage(null);
|
|
|
ppd.SheetProgressPos = 100;
|
|
|
|
|
|
|
|
|
ppd.OnEndSheet();
|
|
|
numSheet++;
|
|
|
}
|
|
|
|
|
|
// Finish the document
|
|
|
pe.EndDocument(null);
|
|
|
// And finish the plot
|
|
|
ppd.PlotProgressPos = 100;
|
|
|
ppd.OnEndPlot();
|
|
|
|
|
|
pe.EndPlot(null);
|
|
|
ppd.Dispose();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
PrintDoc.Editor.WriteMessage("\nAnother plot is in progress.");
|
|
|
}
|
|
|
// Thread.Sleep(30000);
|
|
|
Application.SetSystemVariable("BACKGROUNDPLOT", bgPlot);
|
|
|
tr.Commit();
|
|
|
|
|
|
|
|
|
}
|
|
|
//m_DocumentLock.Dispose();
|
|
|
return path;
|
|
|
}
|
|
|
|
|
|
// 检查是否存在边框
|
|
|
private PrintFrame[] CheckModelSpaceTitle()
|
|
|
{
|
|
|
//DocumentLock m_DocumentLock = ZwSoft.ZwCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.LockDocument();
|
|
|
Database acCurDb = PrintDoc.Database;
|
|
|
List<PrintFrame> lstFrame = new List<PrintFrame>();
|
|
|
using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
|
|
|
{
|
|
|
BlockTable acBlkTbl;
|
|
|
acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId,
|
|
|
OpenMode.ForRead) as BlockTable;
|
|
|
|
|
|
// Open the Block table record for read
|
|
|
BlockTableRecord acBlkTblRec;
|
|
|
|
|
|
acBlkTblRec = acTrans.GetObject(acBlkTbl[BlockTableRecord.ModelSpace],
|
|
|
OpenMode.ForRead) as BlockTableRecord;
|
|
|
BlockReference reference;
|
|
|
BlockTableRecordEnumerator enumbtr = acBlkTblRec.GetEnumerator();
|
|
|
while (enumbtr.MoveNext())
|
|
|
{
|
|
|
Entity entity = acTrans.GetObject(enumbtr.Current, OpenMode.ForRead) as Entity;
|
|
|
|
|
|
if (entity is BlockReference)
|
|
|
{
|
|
|
|
|
|
reference = entity as BlockReference;
|
|
|
//int i = m_Frame.BinarySearch(new PrintFrame() { BKName = reference.Name }, new FrameCompare());
|
|
|
int i = -1;
|
|
|
for (int j = 0; j < m_Frame.Count; j++)
|
|
|
{
|
|
|
if (string.Compare((m_Frame[j] as PrintFrame).BKName, reference.Name, true) == 0)
|
|
|
{
|
|
|
i = j;
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
if (i > -1)
|
|
|
{
|
|
|
Extents2d e2dBound = new Extents2d(reference.Bounds.Value.MinPoint.X, reference.Bounds.Value.MinPoint.Y, reference.Bounds.Value.MaxPoint.X, reference.Bounds.Value.MaxPoint.Y);
|
|
|
(m_Frame[i] as PrintFrame).PrintBound = e2dBound;
|
|
|
PrintFrame frm = new PrintFrame();
|
|
|
frm.Clone((m_Frame[i] as PrintFrame));
|
|
|
lstFrame.Add(frm);
|
|
|
}
|
|
|
|
|
|
}
|
|
|
}
|
|
|
|
|
|
acTrans.Commit();
|
|
|
}
|
|
|
//m_DocumentLock.Dispose();
|
|
|
return lstFrame.ToArray();
|
|
|
}
|
|
|
|
|
|
public Document PrintDoc
|
|
|
{
|
|
|
get;
|
|
|
set;
|
|
|
}
|
|
|
|
|
|
|
|
|
}
|
|
|
}
|