<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Exported .stl file works on developer pc but not the other users in Revit API Forum</title>
    <link>https://forums.autodesk.com/t5/revit-api-forum/exported-stl-file-works-on-developer-pc-but-not-the-other-users/m-p/12902645#M4120</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/413917"&gt;@jeremytammik&lt;/a&gt;&amp;nbsp;and all&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have recently made a plugin for Revit 2023 which&amp;nbsp;can modify building elements. I had to create another button for exporting to STL. As the developer, I'm exporting my Revit document to STL using my own "export to STL" function. The exported STL file works with Prusa and other software, but when I share my plugin files (.dll &amp;amp; .addin) with other users, they get an error when opening the STL file in Prusa. (should i gave them more files?)&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;can someone please help me with this issue?&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;here is the code:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;using Autodesk.Revit.UI;&lt;BR /&gt;using Autodesk.Revit.DB;&lt;BR /&gt;using Autodesk.Revit.Attributes;&lt;BR /&gt;using System;&lt;BR /&gt;using System.IO;&lt;BR /&gt;using System.Windows;&lt;BR /&gt;using Microsoft.Win32;&lt;BR /&gt;using System.Collections.Generic;&lt;BR /&gt;using System.Linq;&lt;/P&gt;&lt;P&gt;namespace [XXXXXXXXXXXX]&lt;BR /&gt;{&lt;BR /&gt;[Transaction(TransactionMode.Manual)]&lt;BR /&gt;public class ExportToSTL : IExternalCommand&lt;BR /&gt;{&lt;BR /&gt;public Result Execute(&lt;BR /&gt;ExternalCommandData commandData,&lt;BR /&gt;ref string message,&lt;BR /&gt;ElementSet elements)&lt;BR /&gt;{&lt;BR /&gt;UIApplication uiApp = commandData.Application;&lt;BR /&gt;UIDocument uiDoc = uiApp.ActiveUIDocument;&lt;BR /&gt;Document document = uiDoc.Document;&lt;/P&gt;&lt;P&gt;// Show options form to user&lt;BR /&gt;ExportOptionsControl optionsControl = new ExportOptionsControl();&lt;BR /&gt;Window window = new Window&lt;BR /&gt;{&lt;BR /&gt;Title = "STL Export Options",&lt;BR /&gt;Content = optionsControl,&lt;BR /&gt;SizeToContent = SizeToContent.WidthAndHeight,&lt;BR /&gt;WindowStartupLocation = WindowStartupLocation.CenterScreen&lt;BR /&gt;};&lt;/P&gt;&lt;P&gt;if (window.ShowDialog() != true)&lt;BR /&gt;{&lt;BR /&gt;return Result.Cancelled;&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;// Retrieve user options&lt;BR /&gt;var format = optionsControl.ExportFormat;&lt;BR /&gt;var resolution = optionsControl.Resolution;&lt;BR /&gt;var units = optionsControl.Units;&lt;/P&gt;&lt;P&gt;// Define the output path as savefile dialog&lt;BR /&gt;string outputPath = string.Empty;&lt;/P&gt;&lt;P&gt;SaveFileDialog saveFileDialog = new SaveFileDialog&lt;BR /&gt;{&lt;BR /&gt;Filter = "STL files (*.stl)|*.stl"&lt;BR /&gt;};&lt;BR /&gt;if (saveFileDialog.ShowDialog() == true)&lt;BR /&gt;{&lt;BR /&gt;outputPath = saveFileDialog.FileName;&lt;BR /&gt;}&lt;BR /&gt;else&lt;BR /&gt;{&lt;BR /&gt;return Result.Cancelled;&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;// Implement STL Export logic here&lt;BR /&gt;try&lt;BR /&gt;{&lt;BR /&gt;ExportSTL(document, uiDoc, outputPath, format, resolution, units);&lt;/P&gt;&lt;P&gt;TaskDialog.Show("Export STL", "Model exported successfully to " + outputPath);&lt;BR /&gt;return Result.Succeeded;&lt;BR /&gt;}&lt;BR /&gt;catch (Exception ex)&lt;BR /&gt;{&lt;BR /&gt;message = ex.Message;&lt;BR /&gt;return Result.Failed;&lt;BR /&gt;}&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;void ExportSTL(Document doc, UIDocument uiDoc, string exportPath, string format, string resolution, string units)&lt;BR /&gt;{&lt;BR /&gt;// Determine the scaling factor based on the selected units&lt;BR /&gt;double scaleFactor = 1.0;&lt;BR /&gt;switch (units)&lt;BR /&gt;{&lt;BR /&gt;case "Millimeters":&lt;BR /&gt;scaleFactor = 304.8; // 1 foot = 304.8 millimeters&lt;BR /&gt;break;&lt;BR /&gt;case "Meters and centimeters":&lt;BR /&gt;scaleFactor = 0.3048; // 1 foot = 0.3048 meters&lt;BR /&gt;break;&lt;BR /&gt;case "Inches":&lt;BR /&gt;scaleFactor = 12.0; // 1 foot = 12 inches&lt;BR /&gt;break;&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;using (StreamWriter writer = new StreamWriter(exportPath))&lt;BR /&gt;{&lt;BR /&gt;writer.WriteLine("solid model");&lt;/P&gt;&lt;P&gt;// Collect selected elements or visible elements in the current view&lt;BR /&gt;ICollection&amp;lt;ElementId&amp;gt; selectedIds = uiDoc.Selection.GetElementIds();&lt;BR /&gt;FilteredElementCollector collector = new FilteredElementCollector(doc);&lt;/P&gt;&lt;P&gt;if (selectedIds.Count &amp;gt; 0)&lt;BR /&gt;{&lt;BR /&gt;collector = new FilteredElementCollector(doc, selectedIds).WhereElementIsNotElementType();&lt;BR /&gt;}&lt;BR /&gt;else&lt;BR /&gt;{&lt;BR /&gt;collector = new FilteredElementCollector(doc, uiDoc.ActiveView.Id)&lt;BR /&gt;.WhereElementIsNotElementType()&lt;BR /&gt;.WhereElementIsViewIndependent();&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;foreach (Element element in collector)&lt;BR /&gt;{&lt;BR /&gt;if (element is FamilyInstance || element is Wall || element is Floor || element is RoofBase || element is HostObject)&lt;BR /&gt;{&lt;BR /&gt;Options geomOptions = new Options();&lt;BR /&gt;GeometryElement geomElement = element.get_Geometry(geomOptions);&lt;/P&gt;&lt;P&gt;if (geomElement != null)&lt;BR /&gt;{&lt;BR /&gt;foreach (GeometryObject geomObj in geomElement)&lt;BR /&gt;{&lt;BR /&gt;if (geomObj is Solid solid)&lt;BR /&gt;{&lt;BR /&gt;ExportSolidToSTL(solid, writer, scaleFactor);&lt;BR /&gt;}&lt;BR /&gt;else if (geomObj is GeometryInstance geomInstance)&lt;BR /&gt;{&lt;BR /&gt;GeometryElement instanceGeometry = geomInstance.GetInstanceGeometry();&lt;BR /&gt;foreach (GeometryObject instanceGeomObj in instanceGeometry)&lt;BR /&gt;{&lt;BR /&gt;if (instanceGeomObj is Solid instanceSolid)&lt;BR /&gt;{&lt;BR /&gt;ExportSolidToSTL(instanceSolid, writer, scaleFactor);&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;writer.WriteLine("endsolid model");&lt;BR /&gt;}&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;void ExportSolidToSTL(Solid solid, StreamWriter writer, double scaleFactor)&lt;BR /&gt;{&lt;BR /&gt;foreach (Face face in solid.Faces)&lt;BR /&gt;{&lt;BR /&gt;Mesh mesh = face.Triangulate();&lt;/P&gt;&lt;P&gt;for (int i = 0; i &amp;lt; mesh.NumTriangles; i++)&lt;BR /&gt;{&lt;BR /&gt;MeshTriangle tri = mesh.get_Triangle(i);&lt;/P&gt;&lt;P&gt;XYZ normal = (tri.get_Vertex(1) - tri.get_Vertex(0)).CrossProduct(tri.get_Vertex(2) - tri.get_Vertex(0)).Normalize();&lt;BR /&gt;writer.WriteLine("facet normal {0} {1} {2}", normal.X, normal.Y, normal.Z);&lt;BR /&gt;writer.WriteLine(" outer loop");&lt;/P&gt;&lt;P&gt;for (int j = 0; j &amp;lt; 3; j++)&lt;BR /&gt;{&lt;BR /&gt;XYZ vertex = tri.get_Vertex(j) * scaleFactor;&lt;BR /&gt;writer.WriteLine(" vertex {0} {1} {2}", vertex.X, vertex.Y, vertex.Z);&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;writer.WriteLine(" endloop");&lt;BR /&gt;writer.WriteLine("endfacet");&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;}&lt;/P&gt;</description>
    <pubDate>Wed, 17 Jul 2024 10:54:16 GMT</pubDate>
    <dc:creator>mahdi_jafari8CJYM</dc:creator>
    <dc:date>2024-07-17T10:54:16Z</dc:date>
    <item>
      <title>Exported .stl file works on developer pc but not the other users</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/exported-stl-file-works-on-developer-pc-but-not-the-other-users/m-p/12902645#M4120</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/413917"&gt;@jeremytammik&lt;/a&gt;&amp;nbsp;and all&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have recently made a plugin for Revit 2023 which&amp;nbsp;can modify building elements. I had to create another button for exporting to STL. As the developer, I'm exporting my Revit document to STL using my own "export to STL" function. The exported STL file works with Prusa and other software, but when I share my plugin files (.dll &amp;amp; .addin) with other users, they get an error when opening the STL file in Prusa. (should i gave them more files?)&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;can someone please help me with this issue?&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;here is the code:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;using Autodesk.Revit.UI;&lt;BR /&gt;using Autodesk.Revit.DB;&lt;BR /&gt;using Autodesk.Revit.Attributes;&lt;BR /&gt;using System;&lt;BR /&gt;using System.IO;&lt;BR /&gt;using System.Windows;&lt;BR /&gt;using Microsoft.Win32;&lt;BR /&gt;using System.Collections.Generic;&lt;BR /&gt;using System.Linq;&lt;/P&gt;&lt;P&gt;namespace [XXXXXXXXXXXX]&lt;BR /&gt;{&lt;BR /&gt;[Transaction(TransactionMode.Manual)]&lt;BR /&gt;public class ExportToSTL : IExternalCommand&lt;BR /&gt;{&lt;BR /&gt;public Result Execute(&lt;BR /&gt;ExternalCommandData commandData,&lt;BR /&gt;ref string message,&lt;BR /&gt;ElementSet elements)&lt;BR /&gt;{&lt;BR /&gt;UIApplication uiApp = commandData.Application;&lt;BR /&gt;UIDocument uiDoc = uiApp.ActiveUIDocument;&lt;BR /&gt;Document document = uiDoc.Document;&lt;/P&gt;&lt;P&gt;// Show options form to user&lt;BR /&gt;ExportOptionsControl optionsControl = new ExportOptionsControl();&lt;BR /&gt;Window window = new Window&lt;BR /&gt;{&lt;BR /&gt;Title = "STL Export Options",&lt;BR /&gt;Content = optionsControl,&lt;BR /&gt;SizeToContent = SizeToContent.WidthAndHeight,&lt;BR /&gt;WindowStartupLocation = WindowStartupLocation.CenterScreen&lt;BR /&gt;};&lt;/P&gt;&lt;P&gt;if (window.ShowDialog() != true)&lt;BR /&gt;{&lt;BR /&gt;return Result.Cancelled;&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;// Retrieve user options&lt;BR /&gt;var format = optionsControl.ExportFormat;&lt;BR /&gt;var resolution = optionsControl.Resolution;&lt;BR /&gt;var units = optionsControl.Units;&lt;/P&gt;&lt;P&gt;// Define the output path as savefile dialog&lt;BR /&gt;string outputPath = string.Empty;&lt;/P&gt;&lt;P&gt;SaveFileDialog saveFileDialog = new SaveFileDialog&lt;BR /&gt;{&lt;BR /&gt;Filter = "STL files (*.stl)|*.stl"&lt;BR /&gt;};&lt;BR /&gt;if (saveFileDialog.ShowDialog() == true)&lt;BR /&gt;{&lt;BR /&gt;outputPath = saveFileDialog.FileName;&lt;BR /&gt;}&lt;BR /&gt;else&lt;BR /&gt;{&lt;BR /&gt;return Result.Cancelled;&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;// Implement STL Export logic here&lt;BR /&gt;try&lt;BR /&gt;{&lt;BR /&gt;ExportSTL(document, uiDoc, outputPath, format, resolution, units);&lt;/P&gt;&lt;P&gt;TaskDialog.Show("Export STL", "Model exported successfully to " + outputPath);&lt;BR /&gt;return Result.Succeeded;&lt;BR /&gt;}&lt;BR /&gt;catch (Exception ex)&lt;BR /&gt;{&lt;BR /&gt;message = ex.Message;&lt;BR /&gt;return Result.Failed;&lt;BR /&gt;}&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;void ExportSTL(Document doc, UIDocument uiDoc, string exportPath, string format, string resolution, string units)&lt;BR /&gt;{&lt;BR /&gt;// Determine the scaling factor based on the selected units&lt;BR /&gt;double scaleFactor = 1.0;&lt;BR /&gt;switch (units)&lt;BR /&gt;{&lt;BR /&gt;case "Millimeters":&lt;BR /&gt;scaleFactor = 304.8; // 1 foot = 304.8 millimeters&lt;BR /&gt;break;&lt;BR /&gt;case "Meters and centimeters":&lt;BR /&gt;scaleFactor = 0.3048; // 1 foot = 0.3048 meters&lt;BR /&gt;break;&lt;BR /&gt;case "Inches":&lt;BR /&gt;scaleFactor = 12.0; // 1 foot = 12 inches&lt;BR /&gt;break;&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;using (StreamWriter writer = new StreamWriter(exportPath))&lt;BR /&gt;{&lt;BR /&gt;writer.WriteLine("solid model");&lt;/P&gt;&lt;P&gt;// Collect selected elements or visible elements in the current view&lt;BR /&gt;ICollection&amp;lt;ElementId&amp;gt; selectedIds = uiDoc.Selection.GetElementIds();&lt;BR /&gt;FilteredElementCollector collector = new FilteredElementCollector(doc);&lt;/P&gt;&lt;P&gt;if (selectedIds.Count &amp;gt; 0)&lt;BR /&gt;{&lt;BR /&gt;collector = new FilteredElementCollector(doc, selectedIds).WhereElementIsNotElementType();&lt;BR /&gt;}&lt;BR /&gt;else&lt;BR /&gt;{&lt;BR /&gt;collector = new FilteredElementCollector(doc, uiDoc.ActiveView.Id)&lt;BR /&gt;.WhereElementIsNotElementType()&lt;BR /&gt;.WhereElementIsViewIndependent();&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;foreach (Element element in collector)&lt;BR /&gt;{&lt;BR /&gt;if (element is FamilyInstance || element is Wall || element is Floor || element is RoofBase || element is HostObject)&lt;BR /&gt;{&lt;BR /&gt;Options geomOptions = new Options();&lt;BR /&gt;GeometryElement geomElement = element.get_Geometry(geomOptions);&lt;/P&gt;&lt;P&gt;if (geomElement != null)&lt;BR /&gt;{&lt;BR /&gt;foreach (GeometryObject geomObj in geomElement)&lt;BR /&gt;{&lt;BR /&gt;if (geomObj is Solid solid)&lt;BR /&gt;{&lt;BR /&gt;ExportSolidToSTL(solid, writer, scaleFactor);&lt;BR /&gt;}&lt;BR /&gt;else if (geomObj is GeometryInstance geomInstance)&lt;BR /&gt;{&lt;BR /&gt;GeometryElement instanceGeometry = geomInstance.GetInstanceGeometry();&lt;BR /&gt;foreach (GeometryObject instanceGeomObj in instanceGeometry)&lt;BR /&gt;{&lt;BR /&gt;if (instanceGeomObj is Solid instanceSolid)&lt;BR /&gt;{&lt;BR /&gt;ExportSolidToSTL(instanceSolid, writer, scaleFactor);&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;writer.WriteLine("endsolid model");&lt;BR /&gt;}&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;void ExportSolidToSTL(Solid solid, StreamWriter writer, double scaleFactor)&lt;BR /&gt;{&lt;BR /&gt;foreach (Face face in solid.Faces)&lt;BR /&gt;{&lt;BR /&gt;Mesh mesh = face.Triangulate();&lt;/P&gt;&lt;P&gt;for (int i = 0; i &amp;lt; mesh.NumTriangles; i++)&lt;BR /&gt;{&lt;BR /&gt;MeshTriangle tri = mesh.get_Triangle(i);&lt;/P&gt;&lt;P&gt;XYZ normal = (tri.get_Vertex(1) - tri.get_Vertex(0)).CrossProduct(tri.get_Vertex(2) - tri.get_Vertex(0)).Normalize();&lt;BR /&gt;writer.WriteLine("facet normal {0} {1} {2}", normal.X, normal.Y, normal.Z);&lt;BR /&gt;writer.WriteLine(" outer loop");&lt;/P&gt;&lt;P&gt;for (int j = 0; j &amp;lt; 3; j++)&lt;BR /&gt;{&lt;BR /&gt;XYZ vertex = tri.get_Vertex(j) * scaleFactor;&lt;BR /&gt;writer.WriteLine(" vertex {0} {1} {2}", vertex.X, vertex.Y, vertex.Z);&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;writer.WriteLine(" endloop");&lt;BR /&gt;writer.WriteLine("endfacet");&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;}&lt;/P&gt;</description>
      <pubDate>Wed, 17 Jul 2024 10:54:16 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/exported-stl-file-works-on-developer-pc-but-not-the-other-users/m-p/12902645#M4120</guid>
      <dc:creator>mahdi_jafari8CJYM</dc:creator>
      <dc:date>2024-07-17T10:54:16Z</dc:date>
    </item>
  </channel>
</rss>

