0

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?

cyrille
  • 2,616
  • 1
  • 10
  • 18

2 Answers2

1

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; }
cyrille
  • 2,616
  • 1
  • 10
  • 18
  • Hey Cyrille, thank you for your time. I've just sorted it out, it was basically the order of actions and urn troubles. There are few attention points we need to be careful when we're using this resource. I have to check it out to make sure but I think the endpoint "references" isn't fully working so it'd be great if someone could have a look at it. Thank you once again. – Ayslan Ferreira Feb 07 '18 at 23:03
  • @Ayslan, would be great if you give me an example where it does not work to investigate the issue. In the meantime, can you accept the answer above as the answer if it address the issue for you, so people can use it with confidence. – cyrille Feb 08 '18 at 08:12
0

@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.