Reputation: 71
I'm exporting SVFs from a model using the design automation API. With some models, the orientation in the Viewer of the viewable does not match the orientation in Inventor.
How do I correct this so that all models come out with their Viewer orientation matching the input Inventor model? The following code is where the SVF is exported. A blog post on this functionality would be helpful.
private string SaveForgeViewable(Inventor.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 = 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("GeometryType", 1);
oOptions.set_Value("EnableExpressTranslation", true);
oOptions.set_Value("SVFFileOutputDir", sessionDir);
oOptions.set_Value("ExportFileProperties", false);
oOptions.set_Value("ObfuscateLabels", true);
}
oAddin.SaveCopyAs(doc, oContext, oOptions, oData);
LogTrace($ "** Saved SVF as {oData.FileName}");
File.Move(bubbleFileOriginal, bubbleFileNew);
viewableOutputDir = sessionDir;
}
}
catch(Exception e) {
LogError($ "********Export to format SVF failed: {e.Message}");
return null;
}
}
return viewableOutputDir;
}
Upvotes: 1
Views: 302
Reputation: 81
we have met this issue too, this is our setup of SVF output which respects the ground of your design:
oOptions.set_Value("EnableExpressTranslation", false);
oOptions.set_Value("ExportFileProperties", true);
oOptions.set_Value("ObfuscateLabels", false);
For full code you can see our new sample app repository https://github.com/Developer-Autodesk/forge-configurator-inventor/blob/master/AppBundles/CreateSVFPlugin/CreateSvfAutomation.cs#L96
Upvotes: 1