如何在 Forge 中正确翻译和显示 .sldasm 文件?

How to properly translate and display .sldasm files in Forge?

使用下面的代码我们可以翻译和显示.dwg、.sldprt、.3ds、.pdf。上传和翻译 .sldasm 文件似乎成功了,但是当尝试在查看器中加载它时,我们收到此消息:"Model is empty, there is no geometry to show"。这似乎发生在所有 .sldasm 文件中。有没有人有任何指点,或者可以发现任何错误?

翻译:

 private async Task<TranslateResponse> StartTranslateFileJob(string bucketUrn)
    {
        var json = JsonConvert.SerializeObject(new
        {
            input = new
            {
                urn = ToUrlSafeBase64(bucketUrn)
            },
            output = new
            {
                formats = new List<Dictionary<string, dynamic>>()
                {
                    new Dictionary<string, dynamic>() { { "type", "svf" }, {"views", new List<string>() { "2d", "3d"} } }
                }
            }
        });
        Header header = new Header()
        {
            ContentType = "application/json",
            Body = json.ToString(),
            Authorization = new AuthenticationHeaderValue("Bearer", await GetAccessToken())
        };
        string response = await request.Request(HttpMethod.Post, "/modelderivative/v2/designdata/job", header);
        return JsonConvert.DeserializeObject<TranslateResponse>(response);
    }

显示:

    private async load(urn: string) {
    let options = {
        env: 'AutodeskProduction',
        accessToken: this.access_token
    };

    let viewerDocument = await new Promise<Autodesk.Viewing.Document>((resolve, reject) =>
        Autodesk.Viewing.Initializer(options, () => {
            Autodesk.Viewing.Document.load(urn, (viewerDocument) => resolve(viewerDocument), (e) => reject(new Error("Blueprint load error: " + e)));
        })
    );

    let documentNode = viewerDocument.getRoot().search({ 'type': 'geometry' })[0];
    this.viewer.loadDocumentNode(viewerDocument, documentNode);
}

*.sldasm(SolidWorks 程序集)或 *.iam(Inventor 程序集)这样的文件通常引用其他文件(*.sldprt*.ipt), Forge 无法自动找出这些引用。您可以执行以下操作之一:

  1. *.sdlasm 及其所有引用部分一起上传到 ZIP 存档中,并在触发翻译时使用 compressedUrnrootFilename 属性工作(tutorial)。

  1. 使用 POST references 端点建立引用。

如果有人有同样的问题,这里是答案:

I've discussed your issue with the development team. It appears that the SLDASM file format supports "temporary/baked visualization primitives" that are included in the main file even when the referenced SLDPRT files are missing. Unfortunately, the Forge translation expects the up-to-date referenced files, and currently does not support the temporary visualization data stored directly within the SLDASM file. In order to translate and view this file in Forge, you could take one of the following approaches:

  1. (preferred) provide your SLDASM file with all its referenced files in a ZIP file as I explained in the Stack Overflow post
  2. Use the "Pack and Go" feature in SolidWorks to bundle all the references into the single SLDASM file
  3. (this might help but we can't confirm that) Load the assembly in SolidWorks and ask for a forced full rebuild (Ctrl+Q), and then process the single SLDASM file in Forge as usual