Autodesk Forge download object, but cannot tell if it is a Revit model or zip file - autodesk-forge

I was downloading Revit models from BIM360 team hub via ForgeAPI using the following uri.
https://developer.api.autodesk.com/oss/v2/buckets/:bucketKey/objects/:objectName
All my objectName ended with .rvt. So I downloaded and saved them as rvt file.
However I noticed that some of the files cannot be opened by Revit. They are actually not rvt files but zip files. So I have to change the extension to .zip and unzip the file to get real 'rvt` files.
My Problem is that not all files is zip file. I cannot tell from the API because the URI I request is always ended with .rvt.

Every Unix OS provides the file command, a standard utility program for recognising the type of data contained in a computer file:
https://en.wikipedia.org/wiki/File_(command)
A zip file is directly recognised and reported like this:
$ file test_dataset.zip
test_dataset.zip: Zip archive data, at least v2.0 to extract
A Revit RVT model is a Windows compound document file, so it generates the following output:
$ file little_house_2021.rvt
little_house_2021.rvt: Composite Document File V2 Document, Cannot read section info
Hence you can use the same algorithm as file does to distinguish between RVT and ZIP files.
Afaik, file just looks at the first couple of bytes in the given file.
The Python programming language offers similar utilities; try an Internet search
for distinguish file type python; the first hits explain
How to check type of files without extensions in Python
and point to the filetype Python project.
Other programming languages can provide similar functionality.

Related

How can I download the svf file in the forge api?

How can I convert the file I uploaded to Forge to svf format and then download it to my own server?
I wanted to do these operations using your project "https://github.com/Autodesk-Forge/forge-bucketsmanager-desktop/tree/master/bucket.manager". As a result, I downloaded it, but there are files in it that I will not use. The reason for this is that the load on the download process increases. I just want the "3d views" folder. Can you help with this?
As Alex said, the structure of an SVF asset can vary depending on the input file format. For more details on how to download the SVF (or just some of its parts), take a look at the forge-convert-utils library, specifically the SvfDownloader. It parses the actual SVF file to identify all the additional assets (e.g., geometry files, textures, property database files, etc.) that need to be downloaded as well.

Editing .json files in a zip folder, without unzipping

I am in the process of uploading a huge number of tests for my school (I am a computer science teacher). These come in the form of .h5p files. I need to parse information into the .h5p files from .txt documents, ready for uploading to Moodle courses. To do this, I have built an app to push the data from .txt files into the .json files in the .h5p file.
The problem is that my app converts the h5p to a zip, unzips it and then parses the information, rezips and then changes the extension again to h5p. Would you mind watching this video https://youtu.be/FTyQddAcWa8 and letting me know how I might be able to edit the .json files and then rezip ready for uploading to the Moodle courses? The files throw up errors once unzipped and then zipped again.
I think the unzipping process is altering the relative links.
Bottom line is, these tests are critical in my school of 1,274 children mitigating the impact of COVID-19 lockdown.
The unzipping process is not the problem, but the zipping is.
When you upload the file, H5P is complaining because it expects some flags to be set when zipping:
-D do not add directory entries
-X eXclude eXtra file attributes
I assume that at some point your script is calling zip. That call would need to pass the correct flags. On a command line, you'd use
zip -rDX myNewFile.h5p *
to pack all files in the current directory into a valid H5P content file named myNewFile.h5p. Just "translate" that into your script.

How can I find which Revit files are linked in BIM 360 via Forge?

In certain circumstances, BIM360 will serve a zip file of a Revit document along with its links, such as explained here: https://forums.autodesk.com/t5/bim-360-document-management/linked-revit-files-in-bim-360-docs/td-p/8774004
In this circumstances, however, when interacting with GET projects/:project_id/folders/:folder_id/contents the file still is shown as a regular file (potentially the isCompositeDesign attribute distinguishes it) with a .rvt file extension. In addition, the filesize shown in storageSize of the object is the sum of the main Revit file and all of its links. Checking the details in GET buckets/:bucketKey/objects/:objectName/details equally show the size object size attribute to be the sum of the main Revit file and all of its links.
I cannot seem to find functionality in Forge that:
Distinguishes a zip file from a lone file (potentially the isCompositeDesign attribute does this)
Provides a list of which other files are linked into the main file, or a list of the zip file contents and their URNs.
Provides a true filesize of the main revit file itself, not just the sum of all linked files in the zip.
Ideas?
Revit 4 worksharing, publishes a file to BIM360.
This file is named as a .rvt file (ie. 'mybigrevitproject.rvt'), but in fact, it's really a zip file in disguise. If you rename it to zip, download it, and unzip it, you'll find lots of .RVT inside the zip.
There's a neat trick to figuring this out, without downloading the entire file.
Use a range GET on the first 16 bytes, and check for the magic header.
For full details, check out this repo: https://github.com/wallabyway
Here's a snippet of the code that will help:
https://github.com/wallabyway/bim360-zip-extract/blob/master/server.js#L167
I think it's related to this question: Forge Data management returns zip file

Get IFC schema version

Opening an *.ifc file we can find "File_Schema" in the Header, for example:
HEADER;
...
FILE_SCHEMA (('IFC4'));
ENDSEC;
We are downloading IFC stream file and it would be nice to know the file schema version for it.
Is it somehow possible to get this information via DataManagement API?
This is already an old post, but just to mention that for those who download the file before any other operation: once downloaded, the following command can be used (on a Unix-like environment) to get exactly the IFC schema (e.g. "IFC2X3", "IFC4"):
grep "^FILE_SCHEMA" file.ifc | cut -d"'" -f2
Of course this command can be integrated in a program written in Node.js for example (using childProcess.exec), or any other programming language. Note that this is usually faster than streaming the file and searching in it, or even using a language-specific library to "grep" the file, especially for big IFC files.

show linked files in autodesk forge viewer

i am trying to make auto-desk forge viewer.
using this link Forge & ASP.NET: from zero to hero in 30 minutes
and it works fine with single revit file.
now i want to view revit document that has linked document and i found this post How to Set References with Revit Files for View and Data API
but i think it is an old version of api.
so i don't know how to apply these steps in the viewer code.
any help
A zipped file which is contained the host RVT file and corresponding linked files can help you archive this goal. After uploading this ZIP file to the Forge DM, you have to make sure that ‘compressedUrn: true’ and ‘rootFilename: {your host RVT filename with the sub filename .rvt}’ your input field of the job configuration body while submitting your translation job. Please refer here for the details: https://developer.autodesk.com/en/docs/model-derivative/v2/reference/http/job-POST/
Some more info:
If you do not want to manage the reference, while simply count on Forge detects the reference automatically, the choice is what Eason mentioned: package all files in an zip, upload, and ask Forge Post Job service to translate the zip. You only need to specify the root file.
https://developer.autodesk.com/en/docs/model-derivative/v2/reference/http/job-POST/
This blog tells more:
https://forge.autodesk.com/cloud_and_mobile/2016/07/translate-referenced-files-by-derivative-api.html
If you want to manage the reference, e.g. in one time, you have uploaded all files of one version or only a few files of the package. While after some time, some files need to be updated, or are not referred anymore, but it is unnecessary to upload all related files again (as in #1, upload zip again).
In such scenario, the choice is, firstly, set reference manually by another Forge service (Set Reference):
https://developer.autodesk.com/en/docs/model-derivative/v2/reference/http/urn-references-POST/
next, ask POST Job service to translate:
https://developer.autodesk.com/en/docs/model-derivative/v2/reference/http/job-POST/
As of 1/2020 Autodesk has said that they do not support reference endpoint when exporting to SVG so zip file is the only supported method currenty.