fix bug
This commit is contained in:
parent
ddb95480ad
commit
6e8ba1b7ed
@ -3,79 +3,84 @@
|
||||
namespace IDTF.Net
|
||||
{
|
||||
public class Point3
|
||||
{
|
||||
public Point3(float x, float y, float z)
|
||||
{
|
||||
this.X = x;
|
||||
this.Y = y;
|
||||
this.Z = z;
|
||||
{
|
||||
public Point3(float x, float y, float z)
|
||||
{
|
||||
this.X = x;
|
||||
this.Y = y;
|
||||
this.Z = z;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public float X { get; set; }
|
||||
public float Y { get; set; }
|
||||
public float Z { get; set; }
|
||||
public float X { get; set; }
|
||||
public float Y { get; set; }
|
||||
public float Z { get; set; }
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return String.Format("{0} {1} {2}",
|
||||
this.X.ToString(Format.SixDecPlFormat),
|
||||
this.Y.ToString(Format.SixDecPlFormat),
|
||||
this.Z.ToString(Format.SixDecPlFormat));
|
||||
}
|
||||
}
|
||||
public bool Equals(Point3 other)
|
||||
{
|
||||
return this.X == other.X && this.Y == other.Y && this.Z == other.Z;
|
||||
}
|
||||
|
||||
public class Vector4 : Point3
|
||||
{
|
||||
public override string ToString()
|
||||
{
|
||||
return String.Format("{0} {1} {2}",
|
||||
this.X.ToString(Format.SixDecPlFormat),
|
||||
this.Y.ToString(Format.SixDecPlFormat),
|
||||
this.Z.ToString(Format.SixDecPlFormat));
|
||||
}
|
||||
}
|
||||
|
||||
public Vector4(float x, float y, float z, float w) : base(x,y,z)
|
||||
{
|
||||
this.W = w;
|
||||
}
|
||||
public class Vector4 : Point3
|
||||
{
|
||||
|
||||
public float W { get; set; }
|
||||
public Vector4(float x, float y, float z, float w) : base(x, y, z)
|
||||
{
|
||||
this.W = w;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return String.Format("{0} {1} {2} {3}",
|
||||
this.X.ToString(Format.SixDecPlFormat),
|
||||
this.Y.ToString(Format.SixDecPlFormat),
|
||||
this.Z.ToString(Format.SixDecPlFormat),
|
||||
this.W.ToString(Format.SixDecPlFormat));
|
||||
}
|
||||
}
|
||||
public float W { get; set; }
|
||||
|
||||
public class Int2
|
||||
{
|
||||
public Int2(int i0, int i1)
|
||||
{
|
||||
IntArray = new int[] { i0, i1 };
|
||||
}
|
||||
public override string ToString()
|
||||
{
|
||||
return String.Format("{0} {1} {2} {3}",
|
||||
this.X.ToString(Format.SixDecPlFormat),
|
||||
this.Y.ToString(Format.SixDecPlFormat),
|
||||
this.Z.ToString(Format.SixDecPlFormat),
|
||||
this.W.ToString(Format.SixDecPlFormat));
|
||||
}
|
||||
}
|
||||
|
||||
public int[] IntArray { get; private set; }
|
||||
public class Int2
|
||||
{
|
||||
public Int2(int i0, int i1)
|
||||
{
|
||||
IntArray = new int[] { i0, i1 };
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return String.Format("{0} {1}",
|
||||
this.IntArray[0].ToString(),
|
||||
this.IntArray[1].ToString());
|
||||
}
|
||||
}
|
||||
public class Int3
|
||||
{
|
||||
public Int3(int i0, int i1, int i2)
|
||||
{
|
||||
IntArray = new int[] { i0, i1, i2 };
|
||||
}
|
||||
public int[] IntArray { get; private set; }
|
||||
|
||||
public int[] IntArray { get; private set; }
|
||||
public override string ToString()
|
||||
{
|
||||
return String.Format("{0} {1}",
|
||||
this.IntArray[0].ToString(),
|
||||
this.IntArray[1].ToString());
|
||||
}
|
||||
}
|
||||
public class Int3
|
||||
{
|
||||
public Int3(int i0, int i1, int i2)
|
||||
{
|
||||
IntArray = new int[] { i0, i1, i2 };
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return String.Format("{0} {1} {2}",
|
||||
this.IntArray[0].ToString(),
|
||||
this.IntArray[1].ToString(),
|
||||
this.IntArray[2].ToString());
|
||||
}
|
||||
}
|
||||
public int[] IntArray { get; private set; }
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return String.Format("{0} {1} {2}",
|
||||
this.IntArray[0].ToString(),
|
||||
this.IntArray[1].ToString(),
|
||||
this.IntArray[2].ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ using Autodesk.Revit.DB;
|
||||
using Autodesk.Revit.UI;
|
||||
using iText.Kernel.Pdf;
|
||||
using iText.Kernel.Pdf.Annot;
|
||||
using Microsoft.Win32;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
@ -23,23 +24,46 @@ namespace PDF3D.Addin
|
||||
UIDocument uIDocument = commandData.Application.ActiveUIDocument;
|
||||
Document doc = uIDocument.Document;
|
||||
|
||||
var elems = uIDocument.Selection.PickObjects(Autodesk.Revit.UI.Selection.ObjectType.Element).Select(x => doc.GetElement(x)).ToList();
|
||||
|
||||
IDTFBuilder iDTFBuilder = new IDTFBuilder(doc);
|
||||
|
||||
var categorys = elems.GroupBy(x => x.Category.Name);
|
||||
foreach ( var category in categorys)
|
||||
try
|
||||
{
|
||||
iDTFBuilder.InsertGroup(category.Key);
|
||||
}
|
||||
var elems = uIDocument.Selection.PickObjects(Autodesk.Revit.UI.Selection.ObjectType.Element).Select(x => doc.GetElement(x)).ToList();
|
||||
|
||||
foreach (var item in elems)
|
||||
SaveFileDialog fileDialog = new SaveFileDialog()
|
||||
{
|
||||
Filter = "Adobe 3dPdf Files (*.pdf)|*.pdf"
|
||||
};
|
||||
if (fileDialog.ShowDialog() == true)
|
||||
{
|
||||
var idtf = Path.GetTempFileName();
|
||||
|
||||
IDTFBuilder iDTFBuilder = new IDTFBuilder(doc);
|
||||
|
||||
var categorys = elems.GroupBy(x => x.Category.Name);
|
||||
foreach (var category in categorys)
|
||||
{
|
||||
iDTFBuilder.InsertGroup(category.Key);
|
||||
}
|
||||
|
||||
foreach (var item in elems)
|
||||
{
|
||||
iDTFBuilder.InsertElement(item);
|
||||
}
|
||||
|
||||
//var views = new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Views).OfClass(typeof(View3D)).Cast<View3D>().ToList();
|
||||
//foreach (var item in views)
|
||||
//{
|
||||
// iDTFBuilder.InsertView(item);
|
||||
//}
|
||||
|
||||
iDTFBuilder.Export(idtf);
|
||||
|
||||
GeneratePDF(idtf,fileDialog.FileName);
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
iDTFBuilder.InsertElement(item);
|
||||
}
|
||||
iDTFBuilder.Export(IDTF);
|
||||
|
||||
GeneratePDF();
|
||||
}
|
||||
|
||||
return Result.Succeeded;
|
||||
}
|
||||
@ -63,12 +87,12 @@ namespace PDF3D.Addin
|
||||
yield return null;
|
||||
}
|
||||
|
||||
public void GeneratePDF()
|
||||
public void GeneratePDF(string idtf,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}\" \"{pdf}\"";
|
||||
startInfo.CreateNoWindow = true;
|
||||
startInfo.UseShellExecute = false;
|
||||
exep.StartInfo = startInfo;
|
||||
|
@ -16,24 +16,21 @@ namespace PDF3D.Addin
|
||||
private Dictionary<string, int> _shaderIndex = new Dictionary<string, int>();
|
||||
|
||||
private Parent nullParent = new Parent() { Name = "<NULL>", Transform = new Transform4x4() };
|
||||
private ShadingDescription defaultShadingDesc = new ShadingDescription() { TextureCoordDimensionList = new List<int>(), ShaderID = 0 };
|
||||
|
||||
public IDTFBuilder(Autodesk.Revit.DB.Document document)
|
||||
{
|
||||
this.document = document;
|
||||
this._scene = new IDTFScene();
|
||||
// AddDefault();
|
||||
}
|
||||
private void AddDefault()
|
||||
{
|
||||
var mat = new MaterialResource()
|
||||
{
|
||||
Name = "default",
|
||||
AttributeDiffuseEnabled = true,
|
||||
MaterialDiffuse = System.Drawing.Color.FromArgb(255, 125, 125, 125),
|
||||
};
|
||||
this._scene.MaterialResources.Add(mat.Name, mat);
|
||||
this._scene.ShaderResources.Add(mat.Name, new ShaderResource() { /*AttributeAlphaTestEnabled = true,*/ ShaderMaterialName = mat.Name, Name = mat.Name });
|
||||
this._scene.ShaderResources.Add(mat.Name, new ShaderResource() { ShaderMaterialName = mat.Name, Name = mat.Name });
|
||||
_shaderIndex.Add(mat.Name, this._scene.ShaderResources.Count);
|
||||
}
|
||||
|
||||
@ -69,7 +66,7 @@ namespace PDF3D.Addin
|
||||
MaterialOpacity = (100 - material.Transparency) / 100f
|
||||
};
|
||||
this._scene.MaterialResources.Add(mat.Name, mat);
|
||||
this._scene.ShaderResources.Add(mat.Name, new ShaderResource() { /*AttributeAlphaTestEnabled = true,*/ ShaderMaterialName = mat.Name, Name = mat.Name });
|
||||
this._scene.ShaderResources.Add(mat.Name, new ShaderResource() {ShaderMaterialName = mat.Name, Name = mat.Name });
|
||||
_shaderIndex.Add(mat.Name, this._scene.ShaderResources.Count);
|
||||
return true;
|
||||
}
|
||||
@ -148,13 +145,9 @@ namespace PDF3D.Addin
|
||||
this.InsertMaterial(material);
|
||||
var shaderDesc = material == null ? new ShadingDescription(_shaderIndex["default"]) : new ShadingDescription(_shaderIndex[material.Name]);
|
||||
|
||||
// System.Drawing.Color color = material == null ? System.Drawing.Color.FromArgb(255, 125, 125, 125)
|
||||
// : System.Drawing.Color.FromArgb((int)((100 - material.Transparency) / 100f * 255), material.Color.Red, material.Color.Green, material.Color.Blue);
|
||||
// meshData.ModelDiffuseColorList.Add(color);
|
||||
meshData.ShadingDescriptionList.Add(shaderDesc);
|
||||
for (int i = 0; i < meshData.MeshFacePositionList.Count; i++)
|
||||
{
|
||||
// meshData.MeshFaceDiffuseColorList.Add(new Int3(0, 0, 0));
|
||||
meshData.MeshFaceShadingList.Add(0);
|
||||
}
|
||||
|
||||
@ -175,14 +168,9 @@ namespace PDF3D.Addin
|
||||
|
||||
var shaderDesc = material == null ? new ShadingDescription(_shaderIndex["default"]) : new ShadingDescription(_shaderIndex[material.Name]);
|
||||
|
||||
//System.Drawing.Color color = material == null ? System.Drawing.Color.FromArgb(255, 125, 125, 125)
|
||||
// : System.Drawing.Color.FromArgb((int)((100 - material.Transparency) / 100f * 255), material.Color.Red, material.Color.Green, material.Color.Blue);
|
||||
|
||||
//meshData.ModelDiffuseColorList.Add(color);
|
||||
meshData.ShadingDescriptionList.Add(shaderDesc);
|
||||
for (int i = 0; i < meshData.MeshFacePositionList.Count; i++)
|
||||
{
|
||||
// meshData.MeshFaceDiffuseColorList.Add(new Int3(0, 0, 0));
|
||||
meshData.MeshFaceShadingList.Add(0);
|
||||
}
|
||||
|
||||
@ -250,7 +238,45 @@ namespace PDF3D.Addin
|
||||
|
||||
public void Export(string path)
|
||||
{
|
||||
// Distinct();
|
||||
_scene.Export(path);
|
||||
}
|
||||
|
||||
private void Distinct()
|
||||
{
|
||||
foreach (var item in _scene.ModelResources.Values)
|
||||
{
|
||||
List<Point3> points = new List<Point3>();
|
||||
foreach (var point in item.Mesh.ModelPositionList)
|
||||
{
|
||||
var str = point.ToString();
|
||||
if (!points.Any(x => x.ToString() == str))
|
||||
{
|
||||
points.Add(point);
|
||||
}
|
||||
}
|
||||
if (points.Count != item.Mesh.ModelPositionList.Count)
|
||||
{
|
||||
var ptStr = points.Select(x => x.ToString()).ToList();
|
||||
for (int i = 0; i < item.Mesh.MeshFacePositionList.Count; i++)
|
||||
{
|
||||
Int3 face = item.Mesh.MeshFacePositionList[i];
|
||||
int a = ptStr.IndexOf(item.Mesh.ModelPositionList[face.IntArray[0]].ToString());
|
||||
int b = ptStr.IndexOf(item.Mesh.ModelPositionList[face.IntArray[1]].ToString());
|
||||
int c = ptStr.IndexOf(item.Mesh.ModelPositionList[face.IntArray[2]].ToString());
|
||||
item.Mesh.MeshFacePositionList[i] = new Int3(a, b, c);
|
||||
}
|
||||
item.Mesh.ModelPositionList = points;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal void InsertView(View3D item)
|
||||
{
|
||||
IDTF.Net.View view = new IDTF.Net.View() { Name = item.Name };
|
||||
ViewData viewData = new ViewData();
|
||||
view.ViewData = viewData;
|
||||
this._scene.Views.Add(view);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -13,4 +13,8 @@
|
||||
<ProjectReference Include="..\PDFGenerator\PDFGenerator.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Reference Include="PresentationFramework" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
@ -9,6 +9,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PDF3D.Addin", "PDF3D.Addin\
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IDTF.Net", "IDTF.Net\IDTF.Net.csproj", "{6EAA9D99-766E-4772-AA87-A219559089DB}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SkpToPdf", "SkpToPdf\SkpToPdf.csproj", "{8FD1F79E-D45A-4C36-A8D5-A95780F37918}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
@ -27,6 +29,10 @@ Global
|
||||
{6EAA9D99-766E-4772-AA87-A219559089DB}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{6EAA9D99-766E-4772-AA87-A219559089DB}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{6EAA9D99-766E-4772-AA87-A219559089DB}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{8FD1F79E-D45A-4C36-A8D5-A95780F37918}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{8FD1F79E-D45A-4C36-A8D5-A95780F37918}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{8FD1F79E-D45A-4C36-A8D5-A95780F37918}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{8FD1F79E-D45A-4C36-A8D5-A95780F37918}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
Loading…
Reference in New Issue
Block a user