Check-In files by API

Check-In files by API

Anonymous
Not applicable
5,247 Views
20 Replies
Message 1 of 21

Check-In files by API

Anonymous
Not applicable

Hi

I'm trying to create an addin to make my life a bit easier. Addin will generate PDF and AutocadDWG files from selected DWG files. One of the features is to check-in files automatically at the end.

My question is - how to to this properly to not make mess inside the Vault.

On the method ChekinFile there are lot o fields to fill:

 

File CheckinFile (
    Long fileMasterId,
    String comment,
    Boolean keepCheckedOut,
    DateTime lastWrite,
    Long [] dependFileIds,
    String [] dependSources,
    Long [] attachFileIds,
    String [] attachSources,
    BOM bom,
    Boolean copyBom,
    String newFileName,
    FileClassification fileClassification,
    Boolean hidden,
    System.Byte [] fileContents
);

 

So, what I should be aware of? How to put a correct file associations to have everything correct in Vault Explorer. And do I have to create DWF file by my self and upload it to?

I will appreciate any help.

0 Likes
5,248 Views
20 Replies
Replies (20)
Message 2 of 21

Redmond.D
Autodesk
Autodesk

This is a pretty complicated topic.  The official recommendation is to have the AutoCAD plug-in or Autoloader add the files to Vault.  If you want to add the files yourself I suggest watching the "Intermediate Vault programming" webcast from ADN's webcast archive.  There are a few slides that specifically address Add/Checkin File.



Doug Redmond
Software Engineer
Autodesk, Inc.

0 Likes
Message 3 of 21

Anonymous
Not applicable

Thank you Doug. But there is just short description of the method without any example. And example or some kind of algorithm is that what I looking for. I know that it could be quite complicated task but maybe someone have some experience with that.

I forgot to mention that I'm using Autodesk Inventor. And I have to deal with relations for parts and assemblies files related to drawings.

0 Likes
Message 4 of 21

Redmond.D
Autodesk
Autodesk

It's a very big algorithm for adding Inventor files.  If you are an inventor plug-in, I recommend invoking the check-in command from the Vault plug-in.  It will pop up the check-in dialog, but it saves you from having to code in all the Inventor data (file dependencies, BOM data, ref Id, etc..).

 

If you really want to try and code this yourself, I suggest posting this question to the Autodesk Developer Network.  This topic is probably too complex for discussion group postings. 



Doug Redmond
Software Engineer
Autodesk, Inc.

0 Likes
Message 5 of 21

Anonymous
Not applicable

Hi Doug. I gave up for a while with this task. Right now I want to try it once more time but your way. Could you please give me some exaple how I can invoke Check-In comand form vault add-ini? It could be helpfull not only for me if you could do that. Or mybe some one else have some expirience with it?

0 Likes
Message 6 of 21

Redmond.D
Autodesk
Autodesk

Unfortunately, I don't have an example of launching another Inventor command from within an Inventor plug-in.  You might want to try the Inventor customization discussion group.



Doug Redmond
Software Engineer
Autodesk, Inc.

0 Likes
Message 7 of 21

dlconsulting
Contributor
Contributor

Hi Doug,

 

I thought I'd jump in with a question related to this thread.  Example or not, is it in deed possible to invoke an existing Inventor command using the API (in my case copy), and if so, what are the API function(s) that do this.  In my case I'd like to perform a copy function to create a new file based on a template stored in Vault.  Tx.  Dan

0 Likes
Message 8 of 21

jlane
Advocate
Advocate

I'm trying to do this with a Navisworks fileset (.nwf)

 

My question is related to the CheckinFile method:

What needs to be entered in FileAssocParam to maintain all the file relationships in Vault?

 

Here's what I'm using (C#):

connection.FileManager.CheckinFile(oFileIteration, "API check-in test", false, new FileAssocParam[] { }, null, false, null, 0, false, null);

 

All of my files exist already on Vault (i.e. I'm not checking them in for the fisrt time).

 

I can get the .nwf file checked back in, but using the above line of code it does not retain the file relationships for the dependant models.

 

Any pointers on how to do this?  Thx!

 

0 Likes
Message 9 of 21

psaarloos
Collaborator
Collaborator
If I am right you can specify 'null' for the FileAssocs argument to retain existing references.

Sent from my mobile device.

Met vriendelijke groet | Kind Regards,


Pim Saarloos
Cadac Group MFG BV
Product Manager

+31 88 9322 439
psaarloos@cadac.com
www.cadac.com

Blankenstein 134
7943 PE Meppel


[http://info.cadac.com/email/plm-1.png] [http://info.cadac.com/email/plm-2.png]
[http://info.cadac.com/email/plm-3.png] [http://info.cadac.com/email/plm-4.png]
Regards,
Pim Saarloos
Product Manager
If my post answers your question, please click the "Accept as Solution" button. Kudos are much appreciated!
0 Likes
Message 10 of 21

jlane
Advocate
Advocate
Hi psaarloos, thank you for your quick reply.  I tried using null but it still breaks the file relationships when checking back into Vault.
 
 
I tested this for both an Inventor assembly (.iam) and Navisworks fileset (.nwf).  In both cases all dependant files reside on Vault already, nothing new being checked in.
 
Any other ideas?
 
 
0 Likes
Message 11 of 21

psaarloos
Collaborator
Collaborator

Then you have to use something like this:

 

  1. Get the existing references of the file in Vault
  2. Check out the file
  3. … do stuff ..
  4. Check in the file

 

Sample:

 

  • Get References 
FileAssocLite[] fileAssocArray = manager.DocumentService.GetFileAssociationLitesByIds(new long[] { file.Id }, FileAssocAlg.Actual, FileAssociationTypeEnum.None, false, FileAssociationTypeEnum.All, false, true, false, true);

 

  • Check Out File

 

Autodesk.DataManagement.Client.Framework.Vault.Currency.Entities.FileIteration fileIteration = new Autodesk.DataManagement.Client.Framework.Vault.Currency.Entities.FileIteration(manager.Connection, file);

 

Autodesk.DataManagement.Client.Framework.Vault.Settings.AcquireFilesSettings settings = new Autodesk.DataManagement.Client.Framework.Vault.Settings.AcquireFilesSettings(manager.Connection, false);

settings.DefaultAcquisitionOption = Autodesk.DataManagement.Client.Framework.Vault.Settings.AcquireFilesSettings.AcquisitionOption.Checkout;

settings.AddFileToAcquire(fileIteration, Autodesk.DataManagement.Client.Framework.Vault.Settings.AcquireFilesSettings.AcquisitionOption.Checkout);

Autodesk.DataManagement.Client.Framework.Vault.Results.AcquireFilesResults results = manager.Connection.FileManager.AcquireFiles(settings);

 

Autodesk.DataManagement.Client.Framework.Vault.Results.FileAcquisitionResult res in results.FileResults[0]

fileIteration = res.NewFileIteration;

 

 

                   

  • // do stuff //

 

  • Check In the file
List<FileAssocParam> pars = new List<FileAssocParam>();

                if (fileAssocArray != null)
                {
                    foreach (FileAssocLite assoc in fileAssocArray)
                    {
                        FileAssocParam par = new FileAssocParam();
                        par.CldFileId = assoc.CldFileId;
                        par.RefId = assoc.RefId;
                        par.Source = assoc.Source;
                        par.Typ = assoc.Typ;
                        par.ExpectedVaultPath = assoc.ExpectedVaultPath;

                        pars.Add(par);
                    }
                }

                manager.Connection.FileManager.CheckinFile(fileIteration, comment, checkedOut, DateTime.Now, pars.ToArray(), null, true, fileIteration.EntityName, fileIteration.FileClassification, fileIteration.IsHidden, null);

 

 

Hope this helps J.         

Regards,
Pim Saarloos
Product Manager
If my post answers your question, please click the "Accept as Solution" button. Kudos are much appreciated!
Message 12 of 21

jlane
Advocate
Advocate

Wow, thank you!  This is getting me in the right direction. 

 

I want to test it out, but I'm getting some error feedback at the two lines of code at the end of your Check Out File block:

 

2016-03-14_12-15-47.png

 

I added a ";" at the end of the line.  Can you spot something that might clear these messages?

 

Thx!

 

 

 

0 Likes
Message 13 of 21

psaarloos
Collaborator
Collaborator
Sorry, my mistake. Change 'in' in '=' (I was looping through the results previously, but there is only one result)
Regards,
Pim Saarloos
Product Manager
If my post answers your question, please click the "Accept as Solution" button. Kudos are much appreciated!
0 Likes
Message 14 of 21

jlane
Advocate
Advocate

Ok, I'm so close now... I fixed it up, but I still get the message shown in the attached.

 

(Thx for your patience, I'm very new to all of this!)

0 Likes
Message 15 of 21

psaarloos
Collaborator
Collaborator

Hi,

 

try this line instead..That should work.

 

Autodesk.DataManagement.Client.Framework.Vault.Results.FileAcquisitionResult res = results.FileResults.FirstOrDefault();

 

Regards,

Pim

Regards,
Pim Saarloos
Product Manager
If my post answers your question, please click the "Accept as Solution" button. Kudos are much appreciated!
Message 16 of 21

jlane
Advocate
Advocate

Thx Pim!

 

Here's what I'm noticing as I test this out.  For now I'm just trying to get the code for check-out, then check-in + retain file dependants working properly. So there are no modifications to the parent file yet.

 

Everything seems to be working well with the file dependants, except that after the parent file is checked back in, it does not increment the Vault version.  It behaves the same as an undo check-out.

 

However, when I enter true for the keep checked out parameter (in the CheckinFile method), the Vault file version is incremented as it should.  But the file is still checked out of course.

 

Also, I notice that my string for the comments parameter is not showing up in Vault.

 

Any ideas as to what might be going wrong?

0 Likes
Message 17 of 21

psaarloos
Collaborator
Collaborator

Probably Vault is seeing there are no modifications to the checked in file and therefore basically rolls back the version. The reason you see a version increase when setting the 'Keep Checked Out' option to true is because Vault reserves/creates the new file version upon check out...

 

You could try to modify the FileAssocs array. Maybe Vault is seeing the file being checked in as a new file then. I assume you have a test Vault to play with, so setting a different source value won't break anything. Check the Source property for the existing file assocations before. They are probably all empty.

 

Change for example this line:

 

par.Source = assoc.Source;

 

to

 

par.Source = "MyTest"

 

 

 

 

Regards,
Pim Saarloos
Product Manager
If my post answers your question, please click the "Accept as Solution" button. Kudos are much appreciated!
0 Likes
Message 18 of 21

jlane
Advocate
Advocate

Ok, here are the assoc.Source properties for the three dependent files of the Navisworks fileset I am testing: 

 

Each returns the value NAVISWORKS:

2016-03-15_9-22-04 FileAssocparam loop.png

 

 

In my application, I've added the part where after checking out the fileset, it is opened in Navisworks, and saved.  This way the file has been modified.

 

After CheckinFile, I notice that the fileset remians at version 1 (not incremented), but Vault detects that the local version has been modified:

 

2016-03-15_9-29-29 After check-in.png

 

 

I don't have a test Vault to play around with, so I'm reluctant to change the assoc.Source settings just at the moment.

 

I'm so close now Pim, everything else is working exactly as I need.  Couldn't have gotten this far without your guidance!  Thx again for your support!  Any other suggestions?

 

0 Likes
Message 19 of 21

jlane
Advocate
Advocate

Ha, sorry Pim...

 

I had the code for the List<FileAssocParam> loop in the wrong location. 

 

I re-located it to after having made the file modifications (after  Step 3 ...do stuff... as you outlined above in your previous reply).

 

This is working like a charm now!

 

Awesome support Pim, thank you!!

0 Likes
Message 20 of 21

psaarloos
Collaborator
Collaborator

Glad to hear it's working! Just out of curiosity; what are you trying to achieve in the process?

 

Regards,

Pim

Regards,
Pim Saarloos
Product Manager
If my post answers your question, please click the "Accept as Solution" button. Kudos are much appreciated!
0 Likes