Uploading linked Revit models to Autodesk Forge

2019-08-25 02:35发布

I've been trying to use the Post references (https://developer.autodesk.com/en/docs/model-derivative/v2/reference/http/urn-references-POST/) to set up the reference between two files in forge but although I get a message "success" as result when I try it on the forge viewer I still see the files separately even after I translate the models. Has someone been through the same issue?

2条回答
叛逆
2楼-- · 2019-08-25 03:21

@Cyrille, this is my request:

curl -X 'POST' -H 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsI' -H 'Content-Type: application/json' -v 'https://developer.api.autodesk.com/modelderivative/v2/designdata/{urn}/references' -d 
'{
  "urn": "urn:adsk.objects:os.object:bucket/non-existent.rvt",
  "filename": "",
  "references": [
    {
      "urn": "urn:adsk.objects:os.object:bucket/non-existent.rvt",
      "relativePath": "",
      "filename": ""
    }
  ]
}'

I got as result:

'{
  "result": "success"
}'

The point is I'm getting success as a result even when I do not have the specified file on the server, so I'd suggest few server-side validations, for example, when a model has been translated once we can't set as reference right so it should at least return an error. Thank you and I hope this helps.

查看更多
小情绪 Triste *
3楼-- · 2019-08-25 03:24

Without seeing you code it is hard to tell what is happening. Below I copied my bash script code which references/translate an obj with material and texture.

Au.obj
  +- Au.mtl
       +- Au.jpg

After upload, I got these

  • idObj="urn:adsk.objects:os.object:cyrillejcrja/Au.obj"
  • idMtl="urn:adsk.objects:os.object:cyrillejcrja/Au.mtl"
  • idJpg="urn:adsk.objects:os.object:cyrillejcrja/Au.jpg"

the code to set references, now

urn=$(xbase64encode $idObj)
job='{
    "urn": "'${idObj}'",
    "filename": "Au.obj",
    "references": [{
        "urn": "'${idMtl}'",
        "relativePath": "./Au.mtl",
        "filename": "Au.mtl",
        "references": [{
            "urn": "'${idJpg}'",
            "relativePath": "./Au.jpg"
        }]
    }]
}'
response=$(curl -H "Content-Type: application/json" \
    -H "Authorization: ${bearer}" \
    -X POST ${ForgeHost}/modelderivative/v2/designdata/${urn}/references \
    -k -s -d "${job}")

Here is got a reply like below which only means that the references are registered.

{
  "result": "success"
}

Now, I do this to translate the obj and use the references

urn=$(xbase64encode $idObj)
job='{
    "input": {
      "urn": "'${urn}'",
      "checkReferences": true
    },
    "output": {
      "formats": [
        {
          "type": "svf",
          "views": [
            "2d",
            "3d"
          ]
        }
      ]
    }
}'
response=$(curl -H "Content-Type: application/json" \
    -H  "Authorization: ${bearer}" \
    -H "x-ads-force: true" \
    -X POST ${ForgeHost}/modelderivative/v2/designdata/job \
    -k -s -d "${job}")

Note the "checkReferences": true, as documented here.

Now, I can wait the translation to complete and see the result in the Viewer.

For reference the xbase64safeencode function used above

function xbase64safeencode () { local id64=$(echo -ne $1 | base64  $wrap_arg | tr -d '=' | tr '+/' '-_'); echo $id64; }
查看更多
登录 后发表回答