public void Run(Document placeholder) { // LogTrace("Run called with {0}", doc.DisplayName); LogTrace("Running Update BOM..."); string currDir = Directory.GetCurrentDirectory(); // For local debugging //string inputPath = System.IO.Path.Combine(currDir, @"../../inputFiles", "params.json"); //Dictionary<string, string> options = JsonConvert.DeserializeObject<Dictionary<string, string>>(System.IO.File.ReadAllText(inputPath)); Dictionary <string, string> options = JsonConvert.DeserializeObject <Dictionary <string, string> >(System.IO.File.ReadAllText("inputParams.json")); string inputFile = options["inputFile"]; string projectFile = options["projectFile"]; string assemblyPath = Path.GetFullPath(Path.Combine(currDir, inputFile)); string fullProjectPath = Path.GetFullPath(Path.Combine(currDir, projectFile)); Console.WriteLine("fullProjectPath = " + fullProjectPath); DesignProject dp = inventorApplication.DesignProjectManager.DesignProjects.AddExisting(fullProjectPath); dp.Activate(); Console.WriteLine("assemblyPath = " + assemblyPath); Document doc = inventorApplication.Documents.Open(assemblyPath); using (new HeartBeat()) { GetBom(doc); } }
public void Run(Document doc) { LogTrace("Run()"); if (IsLocalDebug) { dynamic dynDoc = doc; string parameters = getParamsAsJson(dynDoc.ComponentDefinition.Parameters.UserParameters); System.IO.File.WriteAllText("documentParams.json", parameters); } else { string currentDir = System.IO.Directory.GetCurrentDirectory(); LogTrace("Current Dir = " + currentDir); Dictionary <string, string> inputParameters = JsonConvert.DeserializeObject <Dictionary <string, string> >(System.IO.File.ReadAllText("inputParams.json")); logInputParameters(inputParameters); using (new HeartBeat()) { if (inputParameters.ContainsKey("projectPath")) { string projectPath = inputParameters["projectPath"]; string fullProjectPath = System.IO.Path.GetFullPath(System.IO.Path.Combine(currentDir, projectPath)); LogTrace("fullProjectPath = " + fullProjectPath); DesignProject dp = inventorApplication.DesignProjectManager.DesignProjects.AddExisting(fullProjectPath); dp.Activate(); } else { LogTrace("No 'projectPath' property"); } if (inputParameters.ContainsKey("documentPath")) { string documentPath = inputParameters["documentPath"]; string fullDocumentPath = System.IO.Path.GetFullPath(System.IO.Path.Combine(currentDir, documentPath)); LogTrace("fullDocumentPath = " + fullDocumentPath); dynamic invDoc = inventorApplication.Documents.Open(fullDocumentPath); LogTrace("Opened input document file"); dynamic compDef = invDoc.ComponentDefinition; string parameters = getParamsAsJson(compDef.Parameters.UserParameters); System.IO.File.WriteAllText("documentParams.json", parameters); LogTrace("Created documentParams.json"); } else { LogTrace("No 'documentPath' property"); } } } }
public void BadInput_Null() { Inventor.Application app = ApplicationShim.Instance(); app.Documents.CloseAll(); DesignProject dp = app.DesignProjectManager.ActiveDesignProject; dp.Activate(); string test = null; Assert.IsFalse(PathShim.IsContentCenterPath(test, ref app)); }
/// <summary> /// Activate Inventor Project /// </summary> /// <param name="projectName"></param> /// <returns></returns> public bool ActivateInventorProject(string projectName) { try { //string currentDirectory = Directory.GetCurrentDirectory(); string fullProjectPath = Path.GetFullPath(Path.Combine(currentDirectory, projectName)); DesignProject project = inventorApplication.DesignProjectManager.DesignProjects.AddExisting(fullProjectPath); project.Activate(); } catch (Exception ex) { LogTrace(ex.ToString()); return(false); } return(true); }
public void Run(Document placeholder) { LogTrace("Creating Drawing from iLogic rule..."); string currDir = Directory.GetCurrentDirectory(); LogTrace("currDir: " + currDir); // For local debugging //string inputPath = System.IO.Path.Combine(currDir, @"../../inputFiles", "params.json"); //Dictionary<string, string> options = JsonConvert.DeserializeObject<Dictionary<string, string>>(System.IO.File.ReadAllText(inputPath)); Dictionary <string, string> options = JsonConvert.DeserializeObject <Dictionary <string, string> >(System.IO.File.ReadAllText("inputParams.json")); string inputFile = options["inputFile"]; string projectFile = options["projectFile"]; string rule = options["runRule"]; string drawingDocName = "result"; string assemblyPath = Path.GetFullPath(Path.Combine(currDir, inputFile)); string fullProjectPath = Path.GetFullPath(Path.Combine(currDir, projectFile)); Console.WriteLine("fullProjectPath = " + fullProjectPath); DesignProject dp = inventorApplication.DesignProjectManager.DesignProjects.AddExisting(fullProjectPath); dp.Activate(); Console.WriteLine("assemblyPath = " + assemblyPath); Document doc = inventorApplication.Documents.Open(assemblyPath); //RunRule(doc, rule); CreateDrawing(doc); // Drawing will be the last one created int docCount = inventorApplication.Documents.Count; Document lastDoc = inventorApplication.Documents[docCount]; LogTrace("lastDoc: " + lastDoc.DisplayName); string drawingPath = Directory.GetCurrentDirectory() + "/result.idw"; LogTrace("saving drawing: " + drawingPath); lastDoc.SaveAs(drawingPath, false); LogTrace("saving as pdf: " + drawingDocName); SaveAsPdf(lastDoc, drawingDocName); }
private void ActivateDefaultProject(string dir) { var defaultProjectName = "FDADefault"; var projectFullFileName = System.IO.Path.Combine(dir, defaultProjectName + ".ipj"); DesignProject project = null; if (System.IO.File.Exists(projectFullFileName)) { project = inventorApplication.DesignProjectManager.DesignProjects.AddExisting(projectFullFileName); Trace.TraceInformation("Adding existing default project file: {0}", projectFullFileName); } else { project = inventorApplication.DesignProjectManager.DesignProjects.Add(MultiUserModeEnum.kSingleUserMode, defaultProjectName, dir); Trace.TraceInformation("Creating default project file with name: {0} at {1}", defaultProjectName, dir); } Trace.TraceInformation("Activating default project {0}", project.FullFileName); project.Activate(true); }
public void Run(Document placeholder /*not used*/) { LogTrace("Running v16 - open active LOD with logging - openVisible = false"); try { // !AA! Get project path and assembly from json passed in // !AA! Pass in output type, assembly or SVF using (new HeartBeat()) { string currDir = Directory.GetCurrentDirectory(); // Uncomment out for local debug //string inputPath = System.IO.Path.Combine(currDir, @"../../inputFiles", "params.json"); //Dictionary<string, string> options = JsonConvert.DeserializeObject<Dictionary<string, string>>(System.IO.File.ReadAllText(inputPath)); Dictionary <string, string> options = JsonConvert.DeserializeObject <Dictionary <string, string> >(System.IO.File.ReadAllText("inputParams.json")); string outputType = options["outputType"]; string inputFile = options["inputFile"]; string assemblyPath = Path.GetFullPath(Path.Combine(currDir, inputFile)); if (options.ContainsKey("verboseLogs")) { isVerbose = true; } if (options.ContainsKey("projectFile")) { string projectFile = options["projectFile"]; string fullProjectPath = Path.GetFullPath(Path.Combine(currDir, projectFile)); // For debug of input data set //DirPrint(currDir); Console.WriteLine("fullProjectPath = " + fullProjectPath); DesignProject dp = inventorApplication.DesignProjectManager.DesignProjects.AddExisting(fullProjectPath); dp.Activate(); } Console.WriteLine("assemblyPath = " + assemblyPath); Document doc = null; if (assemblyPath.ToUpper().EndsWith(".IAM")) { FileManager fm = inventorApplication.FileManager; string[] dvReps = fm.GetDesignViewRepresentations(assemblyPath); string dvActRep = fm.GetLastActiveDesignViewRepresentation(assemblyPath); LogTrace($"LastActiveDesignViewRepresentation: {dvActRep}"); string[] lodReps = fm.GetLevelOfDetailRepresentations(assemblyPath); string lodActRep = fm.GetLastActiveLevelOfDetailRepresentation(assemblyPath); LogTrace($"LastActiveLevelOfDetailRepresentation: {lodActRep}"); //string[] posReps = fm.GetPositionalRepresentations(assemblyPath); //string posActRep = fm.get NameValueMap openOptions = inventorApplication.TransientObjects.CreateNameValueMap(); openOptions.Add("LevelOfDetailRepresentation", lodActRep); openOptions.Add("DesignViewRepresentation", dvActRep); doc = inventorApplication.Documents.OpenWithOptions(assemblyPath, openOptions, false); } else { doc = inventorApplication.Documents.Open(assemblyPath); } LogTrace($"Full document name: {doc.FullDocumentName}"); // Uncomment out for local debug //string paramInputPath = System.IO.Path.Combine(currDir, @"../../inputFiles", "parameters.json"); //Dictionary<string, string> parameters = JsonConvert.DeserializeObject<Dictionary<string, string>>(System.IO.File.ReadAllText(paramInputPath)); Dictionary <string, string> parameters = JsonConvert.DeserializeObject <Dictionary <string, string> >(System.IO.File.ReadAllText("documentParams.json")); foreach (KeyValuePair <string, string> entry in parameters) { var paramName = entry.Key; var paramValue = entry.Value; LogTrace($" params: {paramName}, {paramValue}"); ChangeParam(doc, paramName, paramValue); } LogTrace($"Getting full file name of assembly"); var docDir = Path.GetDirectoryName(doc.FullFileName); var pathName = doc.FullFileName; doc.Update2(true); // Save both svf and iam for now. To optimize check output type to only save one or the other // Save Forge Viewer format (SVF) string viewableDir = SaveForgeViewable(doc); //string viewableZip = Path.Combine(Directory.GetCurrentDirectory(), "viewable.zip"); //ZipOutput(viewableDir, viewableZip); if (isVerbose) { LogTrace(">> Start of listing folder contents (before flatten)"); listFolderContents(currDir); LogTrace(">> End of listing folder contents (before flatten)"); } if (!options.ContainsKey("dontFlattenFolder")) { LogTrace($"Flattening SvfOutput folder"); flattenFolder(viewableDir, viewableDir, ""); } if (isVerbose) { LogTrace(">> Start of listing folder contents (after flatten)"); listFolderContents(currDir); LogTrace(">> End of listing folder contents (after flatten)"); } LogTrace($"Code finished"); doc.Save2(true); doc.Close(true); // Zip up the output assembly // // assembly lives in own folder under WorkingDir. Get the WorkingDir. We want to zip up the original zip to include things like project // files and libraries //var zipInputDir = Path.GetDirectoryName(Path.GetDirectoryName(pathName) + "/../"); //var fileName = Path.Combine(Directory.GetCurrentDirectory(), "result.zip"); // the name must be in sync with OutputIam localName in Activity //ZipOutput(zipInputDir, fileName); } } catch (Exception e) { LogError("Processing failed. " + e.ToString()); } }
public void Run(Document placeholder /*not used*/) { //LogTrace("Run called with {0}", doc.DisplayName); try { // !AA! Get project path and assembly from json passed in // !AA! Pass in output type, assembly or SVF using (new HeartBeat()) { string currDir = Directory.GetCurrentDirectory(); // Uncomment out for local debug //string inputPath = System.IO.Path.Combine(currDir, @"../../inputFiles", "params.json"); //Dictionary<string, string> options = JsonConvert.DeserializeObject<Dictionary<string, string>>(System.IO.File.ReadAllText(inputPath)); Dictionary <string, string> options = JsonConvert.DeserializeObject <Dictionary <string, string> >(System.IO.File.ReadAllText("inputParams.json")); string outputType = options["outputType"]; string inputFile = options["inputFile"]; string projectFile = options["projectFile"]; string assemblyPath = Path.GetFullPath(Path.Combine(currDir, inputFile)); string fullProjectPath = Path.GetFullPath(Path.Combine(currDir, projectFile)); if (options.ContainsKey("projectPath")) { // For debug of input data set //DirPrint(currDir); Console.WriteLine("fullProjectPath = " + fullProjectPath); DesignProject dp = inventorApplication.DesignProjectManager.DesignProjects.AddExisting(fullProjectPath); dp.Activate(); } Console.WriteLine("documentPath = " + assemblyPath); Document doc = inventorApplication.Documents.Open(assemblyPath); // Uncomment out for local debug //string paramInputPath = System.IO.Path.Combine(currDir, @"../../inputFiles", "documentParams.json"); //Dictionary<string, string> parameters = JsonConvert.DeserializeObject<Dictionary<string, string>>(System.IO.File.ReadAllText(paramInputPath)); Dictionary <string, string> parameters = JsonConvert.DeserializeObject <Dictionary <string, string> >(System.IO.File.ReadAllText("documentParams.json")); foreach (KeyValuePair <string, string> entry in parameters) { var paramName = entry.Key; var paramValue = entry.Value; LogTrace($" params: {paramName}, {paramValue}"); ChangeParam(doc, paramName, paramValue); } LogTrace($"Getting full file name of assembly"); var docDir = Path.GetDirectoryName(doc.FullFileName); var pathName = doc.FullFileName; doc.Update2(true); // Save Forge Viewer format (SVF) string viewableDir = SaveForgeViewable(doc); string viewableZip = Path.Combine(Directory.GetCurrentDirectory(), "viewable.zip"); ZipOutput(viewableDir, viewableZip); // Save both svf and iam for now. To optimize check output type to only save one or the other LogTrace($"Saving updated assembly"); doc.Save2(true); doc.Close(true); // Zip up the output assembly // // assembly lives in own folder under WorkingDir. Get the WorkingDir. We want to zip up the original zip to include things like project // files and libraries. For parts make sure they are also in a subdirectory LogTrace("Zipping up path: " + Path.GetDirectoryName(pathName)); var zipInputDir = Path.GetDirectoryName(Path.GetDirectoryName(pathName) + "/../"); var fileName = Path.Combine(Directory.GetCurrentDirectory(), "result.zip"); // the name must be in sync with OutputIam localName in Activity ZipOutput(zipInputDir, fileName); } } catch (Exception e) { LogError("Processing failed. " + e.ToString()); } }
//public void SetExternalRulesDirectory(string externalRuleDirName) //{ // LogTrace(" ************ Start Processing Adding External Rules Directory *********"); // string ClientId = "{3BDD8D79-2179-4B11-8A5A-257B1C0263AC}"; // ApplicationAddIn iLogicAddIn = inventorApplication.ApplicationAddIns.ItemById[(ClientId)]; // dynamic iLogicAuto = iLogicAddIn.Automation; // if (iLogicAuto == null) // { // LogError("Error: No iLogicAuto Atuomation set!"); // } // else // { // List<string> externalRuleDirectories = new List<string>(); // foreach (string path in iLogicAuto.FileOptions.ExternalRuleDirectories) // { // externalRuleDirectories.Add(path); // LogTrace("Existing Extrenal Rule Directory:" + path); // } // if (!externalRuleDirectories.Contains(externalRuleDirName)) // { // LogTrace("Add a new Extrenal Directory:" + externalRuleDirName); // externalRuleDirectories.Add(externalRuleDirName); // iLogicAuto.FileOptions.ExternalRuleDirectories = externalRuleDirectories.ToArray(); // } // } // LogTrace(" ************ End Processing Adding External Rules Directory *********"); //} public void Run(Document doc) { LogTrace("Run()"); string currentDir = System.IO.Directory.GetCurrentDirectory(); LogTrace("Current Dir = " + currentDir); var map = CreateEnumMap(); JObject parameters = JObject.Parse(System.IO.File.ReadAllText("params.json")); string assemblyPath = parameters.GetValue("assemblyPath").Value <string>(); using (new HeartBeat()) { CheckPerformance(); if (parameters.ContainsKey("projectPath")) { string projectPath = parameters.GetValue("projectPath").Value <string>(); string fullProjectPath = System.IO.Path.GetFullPath(System.IO.Path.Combine(currentDir, projectPath)); LogTrace("fullProjectPath = " + fullProjectPath); if (System.IO.File.Exists(fullProjectPath)) { LogTrace("Loading and activating project"); DesignProject dp = inventorApplication.DesignProjectManager.DesignProjects.AddExisting(fullProjectPath); dp.Activate(); } else { LogTrace("Project file not found"); } } string fullAssemblyPath = System.IO.Path.GetFullPath(System.IO.Path.Combine(currentDir, assemblyPath)); LogTrace("fullAssemblyPath = " + fullAssemblyPath); if (!System.IO.File.Exists(fullAssemblyPath)) { LogTrace("Did not find assembly"); return; } string ext = System.IO.Path.GetExtension(fullAssemblyPath); AssemblyDocument asmDoc; if (ext == ".iam") { if (parameters.ContainsKey("LOD")) { fullAssemblyPath += "<" + parameters.GetValue("LOD").Value <string>() + ">"; } asmDoc = inventorApplication.Documents.Open(fullAssemblyPath, true) as AssemblyDocument; } else { asmDoc = AnyCADImport(fullAssemblyPath); fullAssemblyPath = System.IO.Path.ChangeExtension(fullAssemblyPath, ".iam"); } LogTrace("fullAssemblyPath = " + fullAssemblyPath); LogTrace("Opened input assembly file"); AssemblyComponentDefinition compDef = asmDoc.ComponentDefinition; LogTrace("Before Update2"); asmDoc.Update2(true); LogTrace("After Update2"); PartDocument partDoc = inventorApplication.Documents.Add(DocumentTypeEnum.kPartDocumentObject, "", true) as PartDocument; LogTrace("Created part document"); PartComponentDefinition partCompDef = partDoc.ComponentDefinition; ShrinkwrapDefinition SWD = null; try { LogTrace("asmDoc.FullDocumentName = " + asmDoc.FullDocumentName); LogTrace("LOD = " + asmDoc.LevelOfDetailName); SWD = partCompDef.ReferenceComponents.ShrinkwrapComponents.CreateDefinition(asmDoc.FullDocumentName); LogTrace("After ShrinkwrapComponents.CreateDefinition"); if (parameters.ContainsKey("CreateIndependentBodiesOnFailedBoolean")) { SWD.CreateIndependentBodiesOnFailedBoolean = GetValue <bool>(parameters, "CreateIndependentBodiesOnFailedBoolean"); } if (parameters.ContainsKey("DeriveStyle")) { // e.g. DerivedComponentStyleEnum.kDeriveAsSingleBodyNoSeams SWD.DeriveStyle = map[GetValue <string>(parameters, "DeriveStyle")]; } if (parameters.ContainsKey("RemoveInternalParts")) { SWD.RemoveInternalParts = GetValue <bool>(parameters, "RemoveInternalParts"); } if (parameters.ContainsKey("RemoveAllInternalVoids")) { SWD.RemoveAllInternalVoids = GetValue <bool>(parameters, "RemoveAllInternalVoids"); } if (parameters.ContainsKey("RemoveHolesDiameterRange")) { SWD.RemoveHolesDiameterRange = GetValue <double>(parameters, "RemoveHolesDiameterRange"); // in cm } if (parameters.ContainsKey("RemoveHolesStyle")) { SWD.RemoveHolesStyle = map[GetValue <string>(parameters, "RemoveHolesStyle")]; } if (parameters.ContainsKey("RemoveFilletsRadiusRange")) { SWD.RemoveFilletsRadiusRange = GetValue <double>(parameters, "RemoveFilletsRadiusRange"); // in cm } if (parameters.ContainsKey("RemoveFilletsStyle")) { SWD.RemoveFilletsStyle = map[GetValue <string>(parameters, "RemoveFilletsStyle")]; } if (parameters.ContainsKey("RemoveChamfersDistanceRange")) { SWD.RemoveChamfersDistanceRange = GetValue <double>(parameters, "RemoveChamfersDistanceRange"); } if (parameters.ContainsKey("RemoveChamfersStyle")) { SWD.RemoveChamfersStyle = map[GetValue <string>(parameters, "RemoveChamfersStyle")]; } if (parameters.ContainsKey("RemovePartsBySize")) { SWD.RemovePartsBySize = GetValue <bool>(parameters, "RemovePartsBySize"); } if (parameters.ContainsKey("RemovePartsSize")) { SWD.RemovePartsSize = GetValue <double>(parameters, "RemovePartsSize"); // in cm } if (parameters.ContainsKey("RemovePocketsStyle")) { SWD.RemovePocketsStyle = map[GetValue <string>(parameters, "RemovePocketsStyle")]; } if (parameters.ContainsKey("RemovePocketsMaxFaceLoopRange")) { SWD.RemovePocketsMaxFaceLoopRange = GetValue <double>(parameters, "RemovePocketsMaxFaceLoopRange"); // in cm } LogTrace("Before ShrinkwrapComponents.Add"); ShrinkwrapComponent SWComp = null; try { SWComp = partCompDef.ReferenceComponents.ShrinkwrapComponents.Add(SWD); } catch (Exception ex) { LogTrace(ex.Message); SWComp = partCompDef.ReferenceComponents.ShrinkwrapComponents[1]; } LogTrace("After ShrinkwrapComponents.Add"); LogTrace("Before SuppressLinkToFile = true"); try { if (parameters.ContainsKey("SuppressLinkToFile")) { SWComp.SuppressLinkToFile = parameters.GetValue("SuppressLinkToFile").Value <bool>(); } } catch (Exception ex) { LogTrace(ex.Message); } LogTrace("After SuppressLinkToFile = true"); LogTrace("Saving part document"); partDoc.SaveAs(System.IO.Path.Combine(currentDir, "output.ipt"), false); LogTrace("Saved part document to output.ipt"); //LogTrace("Saving to OBJ"); //partDoc.SaveAs(System.IO.Path.Combine(currentDir, "outputObjZip", "output.obj"), true); //LogTrace("Saved to OBJ named output.obj"); } catch (Exception ex) { LogTrace("Error: " + ex.Message); } LogTrace("Finished"); } }