/// <summary> /// 移除图纸 /// </summary> /// <param name="pdfConfig">pmp的解析</param> /// <param name="printerNames">要移除的纸张名称</param> static void RemovePrinters(this PlotterConfiguration pdfConfig, string[] printerNames) { //解压了打印机信息之后,遍历打印机节点 foreach (var nodeA in pdfConfig) { if (nodeA.NodeName == "udm") { foreach (var nodeB in nodeA) { if (nodeB.NodeName == "media") { //遍历是否有节点 foreach (PiaNode nodeC in nodeB) { switch (nodeC.NodeName) { case "size": case "description": { nodeC.RemoveChildNodes(printerNames); } break; } } break; } } break; } } }
/// <summary> /// 附着pmp路径到pc3内 /// </summary> /// <param name="plotDevice">当前调用的打印机</param> /// <param name="dwgtopdfpmp">pmp路径</param> public void ChangUserDefinedModel(string plotDevice, string dwgtopdfpmp) { //获取这个打印机的完整路径 string keyPath = @"Software\Autodesk\AutoCAD\R22.0\ACAD-1001:804"; string keyName = "RoamableRootFolder"; object FindPC3_Path = RegistryHelpers.GetRegistryValue(keyPath, keyName); string printerConfigDir = FindPC3_Path + "Plotters\\" + plotDevice; var ns = new string[] { printerConfigDir, dwgtopdfpmp }; foreach (var path in ns) { if (!File.Exists(path)) { continue; } var PdfConfig = new PlotterConfiguration(path); //解压了打印机信息之后,遍历打印机节点 foreach (var nodeA in PdfConfig) { if (nodeA.NodeName == "meta") { nodeA.ValueChang("user_defined_model_pathname" + "_str", dwgtopdfpmp); break; } } PdfConfig.Saves(); } }
/// <summary> /// 打开路径的文件,写到txtbox2上 /// </summary> /// <param name="pcfPath"></param> private void OpendPcf(string pcfPath) { textBox1.Text = pcfPath; PdfConfig = new PlotterConfiguration(pcfPath) { TruetypeAsText = true }; textBox2.Text = PdfConfig.InnerData.Replace("\n", Environment.NewLine); }
/// <summary> /// 移除图纸 /// </summary> /// <param name="pmp_FullPath">pmp名称</param> /// <param name="printerNames">要移除的纸张名称</param> public static void RemovePrinters(/*this Plot plot,*/ string pmp_FullPath, string[] printerNames /*, Database db, Transaction tr*/) { var pdfConfig = new PlotterConfiguration(pmp_FullPath) { TruetypeAsText = true }; pdfConfig.RemovePrinters(printerNames); sortNodes(pdfConfig); pdfConfig.Saves(); }
static void sortNodes(PlotterConfiguration pdfConfig) { foreach (var nodeA in pdfConfig) { if (nodeA.NodeName == "udm") { foreach (var nodeB in nodeA) { if (nodeB.NodeName == "media") { //遍历是否有节点 foreach (PiaNode nodeC in nodeB) { switch (nodeC.NodeName) { case "size": case "description": { int i = 0; // int num = nodeC.ChildNodes.Count; foreach (PiaNode nondD in nodeC) { nondD.NodeName = i.ToString(); i++; } } break; } } break; } } break; } } }
public PlotterConfiguration AddPrinter(string pmp_FullPath /*,double PaperX,double PaperY*/) { Name = userdef_name; //$"JBS_PDF_({PaperY.ToString("#0.00")}_x_{PaperX.ToString("#0.00")}_MM)";//纸张名称 // JoinBoxStandard 嘻嘻 // (5,_17)这个是默认偏移量 // media_description_name="ISO_A0_Portrait_841.00W_x_1189.00H_-_(5,_17)_x_(836,_1172)_=959805_MM //实际打印面积(虽然因为偏移值是0,等于长乘宽就可以,但是为了日后我忘记这里怎么算的,还是求一下吧) double area = (PaperY - (Offset_Left * 2)) * (PaperX - (Offset_Down * 2)); //如果没有小数点保留,可能cad闪退! StringBuilder description_name = new StringBuilder(); description_name.Append($"JBS_PDF_Portrait_{PaperY.ToString("#0.00")}W_x_{PaperX.ToString("#0.00")}H"); description_name.Append("_-_"); description_name.Append($"({Offset_Left.ToString("#0.00")},_{Offset_Down.ToString("#0.00")})");//偏移量 description_name.Append("_x_"); description_name.Append($"({(PaperY - Offset_Left).ToString("#0.00")},_{(PaperX - Offset_Down).ToString("#0.00")})_"); description_name.Append($"={area.ToString("#0.00")}_MM"); //Media_description_name = description_name.ToString(); Media_description_name = Name; PdfConfig = new PlotterConfiguration(pmp_FullPath) { TruetypeAsText = true }; //解压了打印机信息之后,遍历打印机节点 foreach (var nodeA in PdfConfig) { if (nodeA.NodeName == "udm") { foreach (var nodeB in nodeA) { if (nodeB.NodeName == "media") { PiaNode piaNode_size = null; PiaNode piaNode_description = null; //遍历是否有节点 foreach (PiaNode nodeC in nodeB) { string nden = nodeC.NodeName; switch (nden) { case str_size: piaNode_size = nodeC; break; case str_description: piaNode_description = nodeC; break; } } //找不到就添加节点 if (piaNode_size == null) { piaNode_size = nodeB.Add(str_size); } if (piaNode_description == null) { piaNode_description = nodeB.Add(str_description); } //在节点中添加/修改信息 AddPaperEnAndCn(piaNode_size); AddPaperDescription(piaNode_description); break; } } break; } } PdfConfig.Saves(); return(PdfConfig); }