Add/Remove Attachments via scripting

Add/Remove Attachments via scripting

PLM-Sylvain.Bailly
Collaborator Collaborator
1,206 Views
7 Replies
Message 1 of 8

Add/Remove Attachments via scripting

PLM-Sylvain.Bailly
Collaborator
Collaborator

Hi,

 

I am wondering if it is possible to add/remove attachments with an action script?

When I look at the help I see nothing about that: Autodesk GUID

 

@Anonymous has already asked but did you create this feature since 2017? https://forums.autodesk.com/t5/fusion-lifecycle-forum/remove-attachments-via-scripting/m-p/7491825#M7180

 

Thanks,

0 Likes
Accepted solutions (1)
1,207 Views
7 Replies
Replies (7)
Message 2 of 8

Anonymous
Not applicable

I don't think it exists via scripting.  I've been looking for something like this since the beginning because I would be able to auto-upload files rather than have a human do it.

0 Likes
Message 3 of 8

philipfrench
Collaborator
Collaborator
Accepted solution

you are right:
javascript access to item.attachments array is read-only.
you cannot create/edit/upload/download attachments through javascript.
you CAN read the metadata for any attachments that do exist.

 

You CAN create/edit/upload/download attachments through UI, or ReST API.

0 Likes
Message 4 of 8

PLM-Sylvain.Bailly
Collaborator
Collaborator

Thanks!

0 Likes
Message 5 of 8

Anonymous
Not applicable

Does this mean that it is possible to bulk upload attachments? Also, will this not need a CO if the item is already released in I&B workspace?

0 Likes
Message 6 of 8

philipfrench
Collaborator
Collaborator
You can absolutely batch load (or delete or download) attachments. But do this through batch calling the rest API. There are some utilities around that people have written to batch call the rest API. The upload attachment API is a special case API because it uses a binary payload.

But this is using rest API. You cannot do this with JavaScript API.



You can indeed upload to the working version and then release this through a CO.

Also, you can upload to a released version if you give the user the relevant permission (see special permissions section). This applies whether manual or API attachment upload.

Of course normally you would not give anyone permission to edit an item after release - but it is possible by granting the special permission.
Message 7 of 8

Anonymous
Not applicable

Hello,

 

If Attachments are dataObjects, you can check the syntax if it works for you.

 

 
  1. var myDoc = event.target;  
  2. myDoc.removeDataObject("the full file name of the attachment.pdf);  

 

Good luck,

0 Likes
Message 8 of 8

philipfrench
Collaborator
Collaborator

I think "removeDataObject()" refers to either the in-browser javascript (called the Document Object Model, which is effectively inside the browser), and/or Adobe's own javascript API for driving automation of PDFs.

 

I don't believe either of these (browser scripting, Adobe scripting) are relevant to the javascript API available in Fusion Lifecycle.

 

This supports "standard javascript language stuff", plus the FLC API, which is documented here:

 

http://help.autodesk.com/view/PLM/ENU/?guid=GUID-BBBBAB3B-FEAE-4EB7-8D1B-29E76EC6BC65#GUID-BBBBAB3B-...

 

 

You can see it refers to item.attachments array. "You can GET..."

but there are no methods() on this array (unlike others).

 

As I said before, FLC javascript has only read-only access to the metadata of the item attachments.

0 Likes