This commit is contained in:
Zhuangkh 2023-05-05 17:08:24 +08:00
parent ddb95480ad
commit 6e8ba1b7ed
5 changed files with 158 additions and 93 deletions

View File

@ -16,6 +16,11 @@ namespace IDTF.Net
public float Y { get; set; } public float Y { get; set; }
public float Z { get; set; } public float Z { get; set; }
public bool Equals(Point3 other)
{
return this.X == other.X && this.Y == other.Y && this.Z == other.Z;
}
public override string ToString() public override string ToString()
{ {
return String.Format("{0} {1} {2}", return String.Format("{0} {1} {2}",
@ -28,7 +33,7 @@ namespace IDTF.Net
public class Vector4 : Point3 public class Vector4 : Point3
{ {
public Vector4(float x, float y, float z, float w) : base(x,y,z) public Vector4(float x, float y, float z, float w) : base(x, y, z)
{ {
this.W = w; this.W = w;
} }

View File

@ -3,6 +3,7 @@ using Autodesk.Revit.DB;
using Autodesk.Revit.UI; using Autodesk.Revit.UI;
using iText.Kernel.Pdf; using iText.Kernel.Pdf;
using iText.Kernel.Pdf.Annot; using iText.Kernel.Pdf.Annot;
using Microsoft.Win32;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
@ -23,12 +24,22 @@ namespace PDF3D.Addin
UIDocument uIDocument = commandData.Application.ActiveUIDocument; UIDocument uIDocument = commandData.Application.ActiveUIDocument;
Document doc = uIDocument.Document; Document doc = uIDocument.Document;
try
{
var elems = uIDocument.Selection.PickObjects(Autodesk.Revit.UI.Selection.ObjectType.Element).Select(x => doc.GetElement(x)).ToList(); var elems = uIDocument.Selection.PickObjects(Autodesk.Revit.UI.Selection.ObjectType.Element).Select(x => doc.GetElement(x)).ToList();
SaveFileDialog fileDialog = new SaveFileDialog()
{
Filter = "Adobe 3dPdf Files (*.pdf)|*.pdf"
};
if (fileDialog.ShowDialog() == true)
{
var idtf = Path.GetTempFileName();
IDTFBuilder iDTFBuilder = new IDTFBuilder(doc); IDTFBuilder iDTFBuilder = new IDTFBuilder(doc);
var categorys = elems.GroupBy(x => x.Category.Name); var categorys = elems.GroupBy(x => x.Category.Name);
foreach ( var category in categorys) foreach (var category in categorys)
{ {
iDTFBuilder.InsertGroup(category.Key); iDTFBuilder.InsertGroup(category.Key);
} }
@ -37,9 +48,22 @@ namespace PDF3D.Addin
{ {
iDTFBuilder.InsertElement(item); iDTFBuilder.InsertElement(item);
} }
iDTFBuilder.Export(IDTF);
GeneratePDF(); //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
{
}
return Result.Succeeded; return Result.Succeeded;
} }
@ -63,12 +87,12 @@ namespace PDF3D.Addin
yield return null; yield return null;
} }
public void GeneratePDF() public void GeneratePDF(string idtf,string pdf)
{ {
System.Diagnostics.Process exep = new System.Diagnostics.Process(); System.Diagnostics.Process exep = new System.Diagnostics.Process();
System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo(); System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
startInfo.FileName = PDFTool; startInfo.FileName = PDFTool;
startInfo.Arguments = $"\"{IDTF}\" \"{PDF}\""; startInfo.Arguments = $"\"{idtf}\" \"{pdf}\"";
startInfo.CreateNoWindow = true; startInfo.CreateNoWindow = true;
startInfo.UseShellExecute = false; startInfo.UseShellExecute = false;
exep.StartInfo = startInfo; exep.StartInfo = startInfo;

View File

@ -16,24 +16,21 @@ namespace PDF3D.Addin
private Dictionary<string, int> _shaderIndex = new Dictionary<string, int>(); private Dictionary<string, int> _shaderIndex = new Dictionary<string, int>();
private Parent nullParent = new Parent() { Name = "<NULL>", Transform = new Transform4x4() }; 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) public IDTFBuilder(Autodesk.Revit.DB.Document document)
{ {
this.document = document; this.document = document;
this._scene = new IDTFScene(); this._scene = new IDTFScene();
// AddDefault();
} }
private void AddDefault() private void AddDefault()
{ {
var mat = new MaterialResource() var mat = new MaterialResource()
{ {
Name = "default", Name = "default",
AttributeDiffuseEnabled = true,
MaterialDiffuse = System.Drawing.Color.FromArgb(255, 125, 125, 125), MaterialDiffuse = System.Drawing.Color.FromArgb(255, 125, 125, 125),
}; };
this._scene.MaterialResources.Add(mat.Name, mat); 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); _shaderIndex.Add(mat.Name, this._scene.ShaderResources.Count);
} }
@ -69,7 +66,7 @@ namespace PDF3D.Addin
MaterialOpacity = (100 - material.Transparency) / 100f MaterialOpacity = (100 - material.Transparency) / 100f
}; };
this._scene.MaterialResources.Add(mat.Name, mat); 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); _shaderIndex.Add(mat.Name, this._scene.ShaderResources.Count);
return true; return true;
} }
@ -148,13 +145,9 @@ namespace PDF3D.Addin
this.InsertMaterial(material); this.InsertMaterial(material);
var shaderDesc = material == null ? new ShadingDescription(_shaderIndex["default"]) : new ShadingDescription(_shaderIndex[material.Name]); 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); meshData.ShadingDescriptionList.Add(shaderDesc);
for (int i = 0; i < meshData.MeshFacePositionList.Count; i++) for (int i = 0; i < meshData.MeshFacePositionList.Count; i++)
{ {
// meshData.MeshFaceDiffuseColorList.Add(new Int3(0, 0, 0));
meshData.MeshFaceShadingList.Add(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]); 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); meshData.ShadingDescriptionList.Add(shaderDesc);
for (int i = 0; i < meshData.MeshFacePositionList.Count; i++) for (int i = 0; i < meshData.MeshFacePositionList.Count; i++)
{ {
// meshData.MeshFaceDiffuseColorList.Add(new Int3(0, 0, 0));
meshData.MeshFaceShadingList.Add(0); meshData.MeshFaceShadingList.Add(0);
} }
@ -250,7 +238,45 @@ namespace PDF3D.Addin
public void Export(string path) public void Export(string path)
{ {
// Distinct();
_scene.Export(path); _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);
}
} }
} }

View File

@ -13,4 +13,8 @@
<ProjectReference Include="..\PDFGenerator\PDFGenerator.csproj" /> <ProjectReference Include="..\PDFGenerator\PDFGenerator.csproj" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<Reference Include="PresentationFramework" />
</ItemGroup>
</Project> </Project>

View File

@ -9,6 +9,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PDF3D.Addin", "PDF3D.Addin\
EndProject EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IDTF.Net", "IDTF.Net\IDTF.Net.csproj", "{6EAA9D99-766E-4772-AA87-A219559089DB}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IDTF.Net", "IDTF.Net\IDTF.Net.csproj", "{6EAA9D99-766E-4772-AA87-A219559089DB}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SkpToPdf", "SkpToPdf\SkpToPdf.csproj", "{8FD1F79E-D45A-4C36-A8D5-A95780F37918}"
EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU 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}.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.ActiveCfg = Release|Any CPU
{6EAA9D99-766E-4772-AA87-A219559089DB}.Release|Any CPU.Build.0 = 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 EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE