1

我正在使用设计自动化 API 从模型中导出 SVF。对于某些模型,可视项的查看器中的方向与 Inventor 中的方向不匹配。 在此处输入图像描述

在查看器中与在 Inventor 中

如何更正此问题,以使所有模型的查看器方向与输入的 Inventor 模型匹配?以下代码是导出 SVF 的位置。有关此功能的博客文章会有所帮助。

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;
}
4

1 回答 1

1

我们也遇到了这个问题,这是我们的 SVF 输出设置,它尊重您的设计基础:

oOptions.set_Value("EnableExpressTranslation", false);
oOptions.set_Value("ExportFileProperties", true);
oOptions.set_Value("ObfuscateLabels", false);

有关完整代码,您可以查看我们的新示例应用程序存储库https://github.com/Developer-Autodesk/forge-configurator-inventor/blob/master/AppBundles/CreateSVFPlugin/CreateSvfAutomation.cs#L96

于 2020-08-31T18:29:04.730 回答