Importing a File via API (and other feedback)

Importing a File via API (and other feedback)

Anonymous
Not applicable
2,418 Views
12 Replies
Message 1 of 13

Importing a File via API (and other feedback)

Anonymous
Not applicable

Hey guys, 

 

I'm just diving into the API and I'm liking what I've seen so far! A few notes already on how I'm using it. I love that the files are available in the file tree. I strongly dislike using brackets and the debugger is pretty rough too (I can't get copy and paste to work), but I am using my preferred text editor, Sublime Text 3 and that seems to be working well. Additionally I really like that it uses flat HTML and JS files - why this is cool is that you can include other javascript libraries like Underscore.js for instance. Please do not change this!! 

 

I am trying right now to automatically import a file given a directory. I found an example in the previous forum thread about importing a CSV, but I am trying to import a PLY (a mesh) into Fusion 360. I can't figure out in the documentation how to do this. Thanks for the help! 

 

Jeff

0 Likes
2,419 Views
12 Replies
Replies (12)
Message 2 of 13

ekinsb
Alumni
Alumni

Hi Jeff,

 

Thanks for you feedback and it's good that you're having some success with the API.

 

This is an early release and there's still a lot of functionality missing.  I'm not sure what you want to do with the mesh data you read from the PLY file, but the ability to create a mesh object through the API is not currently supported.  It would be interesting to learn what you're trying to accomplish.


Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
0 Likes
Message 3 of 13

Anonymous
Not applicable

I am also trying to figure out how I could import a file to use in the API. The use case is the import of a text file that contains the data needed to generate a 3D model. For example outlines for curves, placement data for components, etc. I need to import the data, parse it, and then generate the 3D model. Ive done this in some other 3D tools and are looking to build out a similar import routine for Fusion.

 

I am guessing I could just have the user copy/paste the entire file contexts into a text input box but this seems very rudimentary. The text files can often be very large if its a complex model and that would be fine for a proof of concept but eventually I would need users to be able to upload the file directly. 

 

Thanks
Marc

0 Likes
Message 4 of 13

ekinsb
Alumni
Alumni

You're right about reading a file being a necessary step in many workflows.  Javascript itself doesn't support reading and writing files from the local file system for security reasons.  However, since we're using Javascript in a non-typical way and understood the need for file access we've added some additional functions in the Fusion API that can be used from Javascript.  If you look at the Fusion 360 API help there is a Javascript specific topic on the User Manual portion of the documentation that describes the functions for file IO.  Here's a direct link to the topic: http://help.autodesk.com/cloudhelp/ENU/Fusion-360-API/files/JavaScriptSpecific.htm

 


Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
0 Likes
Message 5 of 13

Anonymous
Not applicable

How does this code actually work? The API says:

 

adsk.copyFile(fromFilename, toFilename)

 

But where does it actually copy to in order to import the file into your Fusion 360 folders? I tried just putting 'C:\temp\file.ipt'' in the fromFilename but I get an error that says "Failed: File Does Not Exist"

 

 

0 Likes
Message 6 of 13

ekinsb
Alumni
Alumni

The copyFile function provides the ability to copy files on your local hard drive and is completely independent of the files on A360.  Because of security issues, JavaScript doesn't support basic file access and this function is to work around this limitation.  Here's an example of how it might be used.

 

adsk.copyFile('C:\\Temp\\Test.txt', 'C:\\Temp\\NewTest.txt');

Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
0 Likes
Message 7 of 13

Anonymous
Not applicable

Hmm, so is there no API method to import a file into Fusion360?

0 Likes
Message 8 of 13

ekinsb
Alumni
Alumni

What type of file?  For the types that Fusion currently understands, (STEP, SAT, IGES, etc.), API support should be coming in the next major release which is currently scheduled for later in September.  Import of a mesh file (stl or obj) is already supported through the Meshbodies.add method.


Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
0 Likes
Message 9 of 13

Anonymous
Not applicable

Maybe even just Fusion360 archive files. Just need to import a set of files into a directory by script.

0 Likes
Message 10 of 13

ekinsb
Alumni
Alumni

Do you mean import a set of files from a directory.  What exactly is it that you're trying to accomplish?  Is it something you can do through the UI, even though it might be a bit tedious?


Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
0 Likes
Message 11 of 13

Anonymous
Not applicable

Yes, import a set of files from a directory. Of course, it would be ideal if the directory was a internet location. Trying to setup a one click method to import tutorial class materials.

0 Likes
Message 12 of 13

Anonymous
Not applicable

I noticed the parts4cad addon has a video where they are able to import models from their website into Fusion 360 pretty seamlessly. Its not a file import directly but its pretty close. Is the API they are using for this publicly available? I dont see parts4cad in the App Exchange so Im not sure if its live or if this video is marketing something thats not yet available. 

Message 13 of 13

KrisKaplan
Autodesk
Autodesk

The parts4cad addin is using an undocumented API from our old unsupported legacy Python API to pump a local filename across a websocket to the insert component command which then starts a UI interactive insert/move workflow.  It is not a usable insert component API, and it will be disabled as soon as that workflow can be completed with the current API and the parts4cad addin is updated.  Parts4cad is included in Fusion now, and is available in the Insert toolbar.

 

The next major update will include a component insert API (Occurrences.addByInsert which will create an Occurrence of a DataFile) that will allow the insert of a component from an existing file in your project.  If you have a local file, you can use the existing uploadFile or uploadAssembly to add the file to a project and then insert it.  The next update will also include an ImportManager which will allow for the insertion of local files (IGES, STEP, SAT, SMT, F3d) into a document (you should be able to optionally import into a new Component and create any instances of that within the document).

 

Kris



Kris Kaplan
0 Likes