add views,but wrong direction
This commit is contained in:
parent
00282c60bf
commit
c07a80fe2f
@ -15,9 +15,6 @@ namespace PDF3D.Addin
|
||||
[Transaction(TransactionMode.Manual)]
|
||||
public class ExportCmd : IExternalCommand
|
||||
{
|
||||
public static string PDF = @"D:\OneDrive\Code\Private\PDFGenerator\PDF3D.Addin\bin" + @"\\Pdf3D.pdf";
|
||||
public static string U3D = Directory.GetParent(Assembly.GetExecutingAssembly().Location) + @"\\test.u3d";
|
||||
public static string IDTF = Directory.GetParent(Assembly.GetExecutingAssembly().Location) + @"\\test.IDTF";
|
||||
public static string PDFTool = Directory.GetParent(Assembly.GetExecutingAssembly().Location) + @"\\PDFGenerator.exe";
|
||||
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
|
||||
{
|
||||
@ -34,7 +31,6 @@ namespace PDF3D.Addin
|
||||
};
|
||||
if (fileDialog.ShowDialog() == true)
|
||||
{
|
||||
var idtf = Path.GetTempFileName();
|
||||
|
||||
IDTFBuilder iDTFBuilder = new IDTFBuilder(doc);
|
||||
|
||||
@ -58,9 +54,12 @@ namespace PDF3D.Addin
|
||||
}
|
||||
}
|
||||
|
||||
iDTFBuilder.Export(idtf);
|
||||
var idtf = Path.GetTempFileName();
|
||||
var view = Path.GetTempFileName();
|
||||
|
||||
GeneratePDF(idtf, fileDialog.FileName);
|
||||
iDTFBuilder.Export(idtf);
|
||||
iDTFBuilder.ExportView(view);
|
||||
GeneratePDF(idtf, view, fileDialog.FileName);
|
||||
}
|
||||
}
|
||||
catch
|
||||
@ -90,12 +89,12 @@ namespace PDF3D.Addin
|
||||
yield return null;
|
||||
}
|
||||
|
||||
public void GeneratePDF(string idtf, string pdf)
|
||||
public void GeneratePDF(string idtf, string view, string pdf)
|
||||
{
|
||||
System.Diagnostics.Process exep = new System.Diagnostics.Process();
|
||||
System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
|
||||
startInfo.FileName = PDFTool;
|
||||
startInfo.Arguments = $"\"{idtf}\" \"{pdf}\"";
|
||||
startInfo.Arguments = $"\"{idtf}\" \"{view}\" \"{pdf}\"";
|
||||
startInfo.CreateNoWindow = true;
|
||||
startInfo.UseShellExecute = false;
|
||||
exep.StartInfo = startInfo;
|
||||
|
@ -1,10 +1,12 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Autodesk.Revit.DB;
|
||||
using IDTF.Net;
|
||||
using Newtonsoft.Json;
|
||||
using Group = IDTF.Net.Group;
|
||||
|
||||
namespace PDF3D.Addin
|
||||
@ -305,7 +307,11 @@ namespace PDF3D.Addin
|
||||
Distinct();
|
||||
_scene.Export(path);
|
||||
}
|
||||
|
||||
public void ExportView(string path)
|
||||
{
|
||||
var viewStr = JsonConvert.SerializeObject(_scene.Views);
|
||||
File.WriteAllText(path, viewStr);
|
||||
}
|
||||
private void Distinct()
|
||||
{
|
||||
var comparer = new Point3Comparer();
|
||||
|
@ -5,9 +5,12 @@ using iText.Kernel.Pdf.Annot;
|
||||
using iText.Kernel.Pdf.Canvas;
|
||||
using iText.Layout;
|
||||
using iText.Layout.Element;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
|
||||
public class Program
|
||||
@ -16,7 +19,7 @@ public class Program
|
||||
|
||||
static void Main(string[] args)
|
||||
{
|
||||
GeneratePDF(args[0], args[1]);
|
||||
GeneratePDF(args[0], args[1], args[2]);
|
||||
}
|
||||
public static void GenerateU3D(string idtf, string u3d)
|
||||
{
|
||||
@ -31,7 +34,7 @@ public class Program
|
||||
exep.WaitForExit();
|
||||
}
|
||||
|
||||
public static void GeneratePDF(string idtf, string pdf)
|
||||
public static void GeneratePDF(string idtf, string view, string pdf)
|
||||
{
|
||||
var u3d = System.IO.Path.GetTempFileName();
|
||||
GenerateU3D(idtf, u3d);
|
||||
@ -44,41 +47,68 @@ public class Program
|
||||
Rectangle rect = new Rectangle(50, 50, size.GetWidth() - 100, size.GetHeight() - 100);
|
||||
|
||||
|
||||
PdfDictionary dict3D = new PdfDictionary();
|
||||
dict3D.Put(PdfName.Type, new PdfName("3DView"));
|
||||
dict3D.Put(new PdfName("XN"), new PdfString("SHITTTTTTT"));
|
||||
//dict3D.Put(new PdfName("IN"), new PdfString("Unnamed"));
|
||||
dict3D.Put(new PdfName("MS"), PdfName.M);
|
||||
dict3D.Put(new PdfName("C2W"),
|
||||
new PdfArray(new float[] { 1, 0, 0, 0, 0, -1, 0, 1, 0, 3, -235, 28 }));
|
||||
//dict3D.Put(PdfName.CO, new PdfNumber(235));
|
||||
var views = Generate3DView(view);
|
||||
|
||||
PdfStream stream3D = new PdfStream(pdfDoc, new FileStream(u3d, FileMode.Open));
|
||||
stream3D.Put(PdfName.Type, new PdfName("3D"));
|
||||
stream3D.Put(PdfName.Subtype, new PdfName("U3D"));
|
||||
stream3D.Put(new PdfName("VA"), new PdfArray(new PdfDictionary[] { dict3D }));
|
||||
stream3D.Put(new PdfName("VA"), new PdfArray(views.ToArray()));
|
||||
stream3D.SetCompressionLevel(CompressionConstants.DEFAULT_COMPRESSION);
|
||||
stream3D.Flush();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Pdf3DAnnotation annot = new Pdf3DAnnotation(rect, stream3D);
|
||||
annot.SetContents(new PdfString("3D Model"));
|
||||
annot.SetDefaultInitialView(dict3D);
|
||||
annot.SetContents(new PdfString("3D Model"));
|
||||
annot.SetDefaultInitialView(views.First());
|
||||
var page = pdfDoc.AddNewPage(size).SetRotation(90);
|
||||
page.AddAnnotation(annot);
|
||||
PdfCanvas canvas = new PdfCanvas(page);
|
||||
// PdfCanvas canvas = new PdfCanvas(page);
|
||||
|
||||
ImageData imageData = ImageDataFactory.Create(System.IO.Directory.GetParent(Assembly.GetExecutingAssembly().Location) + "\\logo.png");
|
||||
Image image = new Image(imageData);
|
||||
image.SetHeight(25);
|
||||
image.SetMarginLeft(-20);
|
||||
image.SetMarginTop(-20);
|
||||
image.SetRotationAngle(Math.PI/2);
|
||||
image.SetRotationAngle(Math.PI / 2);
|
||||
doc.Add(image);
|
||||
|
||||
// 关闭文档
|
||||
pdfDoc.Close();
|
||||
doc.Close();
|
||||
}
|
||||
|
||||
private static List<PdfDictionary> Generate3DView(string view)
|
||||
{
|
||||
List<PdfDictionary> list = new List<PdfDictionary>();
|
||||
string viewStr = File.ReadAllText(view);
|
||||
var views = JsonConvert.DeserializeObject<List<IDTF.Net.View>>(viewStr);
|
||||
foreach (var item in views)
|
||||
{
|
||||
if (item.Parents.Any())
|
||||
{
|
||||
|
||||
PdfDictionary dict3D = new PdfDictionary();
|
||||
dict3D.Put(PdfName.Type, new PdfName("3DView"));
|
||||
dict3D.Put(new PdfName("XN"), new PdfString(item.Name));
|
||||
|
||||
//dict3D.Put(new PdfName("IN"), new PdfString("Unnamed"));
|
||||
dict3D.Put(new PdfName("MS"), PdfName.M);
|
||||
//dict3D.Put(new PdfName("C2W"),
|
||||
// new PdfArray(new double[] { item.Parents[0].Transform.c0r0, item.Parents[0].Transform.c0r1, item.Parents[0].Transform.c0r2,
|
||||
// item.Parents[0].Transform.c1r0, item.Parents[0].Transform.c1r1, item.Parents[0].Transform.c1r2,
|
||||
// item.Parents[0].Transform.c2r0, item.Parents[0].Transform.c2r1, item.Parents[0].Transform.c2r2,
|
||||
// item.Parents[0].Transform.c3r0, item.Parents[0].Transform.c3r1, item.Parents[0].Transform.c3r2 }));
|
||||
dict3D.Put(new PdfName("C2W"),
|
||||
new PdfArray(new double[] { item.Parents[0].Transform.c0r0, item.Parents[0].Transform.c1r0, item.Parents[0].Transform.c2r0,
|
||||
item.Parents[0].Transform.c0r1, item.Parents[0].Transform.c1r1, item.Parents[0].Transform.c2r1,
|
||||
item.Parents[0].Transform.c0r2, item.Parents[0].Transform.c1r2, item.Parents[0].Transform.c2r2,
|
||||
item.Parents[0].Transform.c3r0, item.Parents[0].Transform.c3r1, item.Parents[0].Transform.c3r2 }));
|
||||
//dict3D.Put(PdfName.CO, new PdfNumber(235));
|
||||
list.Add(dict3D);
|
||||
}
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user