private void SaveAsSVF(Document Doc) { using (new HeartBeat()) { LogTrace("** Saving SVF"); try { ApplicationAddIn svfAddin = _inventorApplication .ApplicationAddIns .Cast <ApplicationAddIn>() .FirstOrDefault(item => item.ClassIdString == "{C200B99B-B7DD-4114-A5E9-6557AB5ED8EC}"); var oAddin = (TranslatorAddIn)svfAddin; if (oAddin != null) { Trace.TraceInformation("SVF Translator addin is available"); TranslationContext oContext = _inventorApplication.TransientObjects.CreateTranslationContext(); // Setting context type oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism; NameValueMap oOptions = _inventorApplication.TransientObjects.CreateNameValueMap(); // Create data medium; DataMedium oData = _inventorApplication.TransientObjects.CreateDataMedium(); Trace.TraceInformation("SVF save"); var sessionDir = Path.Combine(Directory.GetCurrentDirectory(), "SvfOutput"); oData.FileName = Path.Combine(sessionDir, "result.collaboration"); var outputDir = Path.Combine(sessionDir, "output"); var bubbleFileOriginal = Path.Combine(outputDir, "bubble.json"); var bubbleFileNew = Path.Combine(sessionDir, "bubble.json"); // Setup SVF options if (oAddin.get_HasSaveCopyAsOptions(Doc, oContext, oOptions)) { oOptions.set_Value("GeometryType", 1); oOptions.set_Value("EnableExpressTranslation", false); oOptions.set_Value("SVFFileOutputDir", sessionDir); oOptions.set_Value("ExportFileProperties", true); oOptions.set_Value("ObfuscateLabels", false); } LogTrace($"SVF files are output to: {oOptions.get_Value("SVFFileOutputDir")}"); oAddin.SaveCopyAs(Doc, oContext, oOptions, oData); Trace.TraceInformation("SVF can be exported."); LogTrace($"** Saved SVF as {oData.FileName}"); File.Move(bubbleFileOriginal, bubbleFileNew); } } catch (Exception e) { LogError($"********Export to format SVF failed: {e.Message}"); } } }
public CustomRigidJoint(RigidBodyJoint joint, CustomRigidGroup groupOnez, CustomRigidGroup groupTwoz) { foreach (AssemblyJoint aj in joint.Joints) { joints.Add(aj); } foreach (AssemblyConstraint cj in joint.Constraints) { constraints.Add(cj); } groupOne = groupOnez; groupTwo = groupTwoz; type = joint.JointType; joint.GetJointData(out geomOne, out geomTwo, out options); try { jointBased = options.get_Value("FromJoint"); } catch { jointBased = false; } }
private string SaveForgeViewable(Document doc) { string viewableOutputDir = null; //using (new HeartBeat()) { LogTrace($"** Saving SVF"); try { TranslatorAddIn oAddin = null; foreach (ApplicationAddIn item in inventorApplication.ApplicationAddIns) { if (item.ClassIdString == "{C200B99B-B7DD-4114-A5E9-6557AB5ED8EC}") { Trace.TraceInformation("SVF Translator addin is available"); oAddin = (TranslatorAddIn)item; break; } else { } } if (oAddin != null) { Trace.TraceInformation("SVF Translator addin is available"); TranslationContext oContext = inventorApplication.TransientObjects.CreateTranslationContext(); // Setting context type oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism; NameValueMap oOptions = inventorApplication.TransientObjects.CreateNameValueMap(); // Create data medium; DataMedium oData = inventorApplication.TransientObjects.CreateDataMedium(); Trace.TraceInformation("SVF save"); var workingDir = Directory.GetCurrentDirectory(); //Path.GetDirectoryName(doc.FullFileName); var sessionDir = Path.Combine(workingDir, "SvfOutput"); // Make sure we delete any old contents that may be in the output directory first, // this is for local debugging. In DA4I the working directory is always clean if (Directory.Exists(sessionDir)) { Directory.Delete(sessionDir, true); } oData.FileName = Path.Combine(sessionDir, "result.collaboration"); var outputDir = Path.Combine(sessionDir, "output"); var bubbleFileOriginal = Path.Combine(outputDir, "bubble.json"); var bubbleFileNew = Path.Combine(sessionDir, "bubble.json"); // Setup SVF options if (oAddin.get_HasSaveCopyAsOptions(doc, oContext, oOptions)) { oOptions.set_Value("EnableExpressTranslation", false); oOptions.set_Value("SVFFileOutputDir", sessionDir); oOptions.set_Value("ExportFileProperties", true); oOptions.set_Value("ObfuscateLabels", false); } LogTrace($"SVF files are oputput to: {oOptions.get_Value("SVFFileOutputDir")}"); oAddin.SaveCopyAs(doc, oContext, oOptions, oData); Trace.TraceInformation("SVF can be exported."); LogTrace($"Moving bubble file"); File.Move(bubbleFileOriginal, bubbleFileNew); LogTrace($"Deleting result.collaboration"); File.Delete(oData.FileName); viewableOutputDir = sessionDir; LogTrace($"Finished SVF generation"); } } catch (Exception e) { LogError($"********Export to format SVF failed: {e.Message}"); return(null); } } return(viewableOutputDir); }