From af408b44aa1e7d94ae0a856522b18a7d83053605 Mon Sep 17 00:00:00 2001 From: Max Richter Date: Wed, 11 Jun 2025 16:51:33 +0200 Subject: [PATCH] feat: publish app bundle test --- .../DebugPluginLocally/Program.cs | 10 +-- .../SampleAutomation.cs | 74 ++++++++++++------- 2 files changed, 53 insertions(+), 31 deletions(-) diff --git a/MachinePlannerExport/DebugPluginLocally/Program.cs b/MachinePlannerExport/DebugPluginLocally/Program.cs index 8685b73..69f5265 100644 --- a/MachinePlannerExport/DebugPluginLocally/Program.cs +++ b/MachinePlannerExport/DebugPluginLocally/Program.cs @@ -65,8 +65,8 @@ namespace DebugPluginLocally // create a copy System.IO.File.Copy(boxPath, boxPathCopy); - // open box.ipt by Inventor - Document doc = app.Documents.Open(boxPathCopy); + // open boxcopy.ipt by Inventor + Document doc = app.Documents.Open(boxPathCopy);; // get params.json absolute path string paramsPath = System.IO.Path.Combine(projectdir, @"inputFiles\", "params.json"); @@ -78,10 +78,8 @@ namespace DebugPluginLocally map.Add("_1", paramsPath); // add extra parameters to showcase newly supported parsing and new helper class NameValueMapHelper - map.Add("intIndex", "1"); - map.Add("stringIndex", "test"); - map.Add("stringCollectionIndex", "str1, str2, str3"); - map.Add("intCollectionIndex", "34, 256, 9999, 500, 43"); + map.Add("height", "5.0"); + map.Add("width", "10.0"); // create an instance of MachinePlannerExportPlugin diff --git a/MachinePlannerExport/MachinePlannerExportPlugin/SampleAutomation.cs b/MachinePlannerExport/MachinePlannerExportPlugin/SampleAutomation.cs index 9bdaa43..bf68b04 100644 --- a/MachinePlannerExport/MachinePlannerExportPlugin/SampleAutomation.cs +++ b/MachinePlannerExport/MachinePlannerExportPlugin/SampleAutomation.cs @@ -17,10 +17,8 @@ ///////////////////////////////////////////////////////////////////// using System; -using System.Collections.Generic; using System.Diagnostics; using System.Runtime.InteropServices; -using Autodesk.Forge.DesignAutomation.Inventor.Utils; using Autodesk.Forge.DesignAutomation.Inventor.Utils.Helpers; using Inventor; @@ -47,37 +45,63 @@ namespace MachinePlannerExportPlugin try { - // Using NameValueMapExtension - if (map.HasKey("intIndex")) + // Parameter aus der Config lesen + double height = 1.0; + if (map.HasKey("height")) { - int intValue = map.AsInt("intIndex"); - LogTrace($"Value of intIndex is: {intValue}"); + height = map.AsDouble("height"); } - if (map.HasKey("stringCollectionIndex")) + double width = 1.0; + if (map.HasKey("width")) { - IEnumerable strCollection = map.AsStringCollection("stringCollectionIndex"); - - foreach (string strValue in strCollection) - { - LogTrace($"String value is: {strValue}"); - } + width = map.AsDouble("width"); } - if (doc.DocumentType == DocumentTypeEnum.kPartDocumentObject) + string name = "Box"; + if (map.HasKey("name")) { - using (new HeartBeat()) - { - // TODO: handle the Inventor part here - } - } - else if (doc.DocumentType == DocumentTypeEnum.kAssemblyDocumentObject) // Assembly. - { - using (new HeartBeat()) - { - // TODO: handle the Inventor assembly here - } + name = map.AsString("name"); } + + // Neues Part-Dokument anlegen + PartDocument partDoc = (PartDocument)inventorApplication.Documents.Add(DocumentTypeEnum.kPartDocumentObject, + inventorApplication.FileManager.GetTemplateFile(DocumentTypeEnum.kPartDocumentObject), true); + + PartComponentDefinition compDef = partDoc.ComponentDefinition; + compDef.Document.Name = name; // Set the document name + + // 2D-Skizze auf XY-Ebene anlegen + PlanarSketch sketch = compDef.Sketches.Add(compDef.WorkPlanes[3]); // 3 = XY Plane + + // Rechteck zeichnen + sketch.SketchLines.AddAsTwoPointRectangle( + inventorApplication.TransientGeometry.CreatePoint2d(0, 0), + inventorApplication.TransientGeometry.CreatePoint2d(width, height) + ); + + // Rechteck extrudieren (Würfel) + Profile profile = sketch.Profiles.AddForSolid(); + ExtrudeDefinition extrudeDef = compDef.Features.ExtrudeFeatures.CreateExtrudeDefinition( + profile, PartFeatureOperationEnum.kJoinOperation); + + extrudeDef.SetDistanceExtent(width, PartFeatureExtentDirectionEnum.kPositiveExtentDirection); + ExtrudeFeature boxFeature = compDef.Features.ExtrudeFeatures.Add(extrudeDef); + + + // Speicherort für das temporäre IPT + string tempDir = System.IO.Path.GetTempPath(); + string partPath = System.IO.Path.Combine(tempDir, "CubeExport.ipt"); + partDoc.SaveAs(partPath, false); + + // Jetzt ist FullFileName gesetzt und du kannst das Verzeichnis verwenden + string stepPath = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(partDoc.FullFileName), "CubeExport.step"); + + // STEP-Export + partDoc.SaveAs(stepPath, true); // true für STEP-Export, wenn als .step angegeben + + // Optional: Log-Ausgabe + LogTrace($"Würfel mit Breite={width} und Höhe={height} und Text '{name}' als STEP exportiert: {stepPath}"); } catch (Exception e) {