API file checkin

API file checkin

mfoster9TD82
Advocate Advocate
1,566件の閲覧回数
7件の返信
メッセージ1/8

API file checkin

mfoster9TD82
Advocate
Advocate

Hi all,

I'm running into an issue checking in files through the API. I keep running into this error when trying to checkin files with :

InventorApp.CommandManager.ControlDefinitions["VaultCheckinTop"].Execute2(true);

Snag_32d2d502.png


I can't checkin the files through the Vault API because of our vault settings. I've managed to find a workaround by turning silent operations off, putting the current Inventor session in focus, call Doc.Close(false) then simulating an {ENTER} keypress to get past the save dialog. The only(major) issue with this is the timing between making the Inventor session window in focus and simulating the {ENTER} keypress; there are times where another process will sneak in there and take focus away before {ENTER} can be pressed.

Does anyone know of a way to set the save on close always yes and initiate the checkin(Or any suggestions on why my files aren't saving correctly to avoid the first checkin error)?

Thanks!

0 件のいいね
解決済み
1,567件の閲覧回数
7件の返信
返信 (7)
メッセージ2/8

JelteDeJong
Mentor
Mentor

Did you try to save the document by api before check-in? something like:

document.Save2();
InventorApp.CommandManager.ControlDefinitions["VaultCheckinTop"].Execute2(true);

 Maybe you don't need to silence Inventor anymore.

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

0 件のいいね
メッセージ3/8

mfoster9TD82
Advocate
Advocate
yes I updated and saved the document right before checking it in
0 件のいいね
メッセージ4/8

Darkforce_the_ilogic_guy
Advisor
Advisor

often when you get this error you will have to save all files ... that inventor want to save .. even the files that was lock by vault.  when you save the files hit the yes to all when you save ... that will fix that error 99% of the time

 

You dont need to chekc them out ... just allow inventor to save it local  🙂

メッセージ5/8

bradeneuropeArthur
Mentor
Mentor

Using the vault api is the best option here. You have there pre and post events that will help you here.

Let me have a look later on if you come not further...

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

0 件のいいね
メッセージ6/8

mfoster9TD82
Advocate
Advocate

I ended up going with this route except I didn't realize I had to update the iProperties in the CompAttrArray of the BOM(passed in the BOM as null in the checkinFile() function). Now the file properties don't get updated in the Item when I update it. I went through the file BOMs and updated the iProperty values in CompAttrArray but some of the files are basically getting undo checkout when I call the checkinFile() function. I'm not really sure what I'm missing, the files are downloading and checking out ok with AcquireFiles, but after the checkinFile() the file is checked in but the latest version if the version I checked out, not a new version.

 

My code is attached for updating the file BOMs. I basically just updated the description of the files. Let me know if you see anything that screams at you.

This picture is what I'm trying to fix.

mfoster9TD82_1-1673281527225.png

 

0 件のいいね
メッセージ7/8

mfoster9TD82
Advocate
Advocate
I'm not sure which prompts you are referring to?
0 件のいいね
メッセージ8/8

mfoster9TD82
Advocate
Advocate
解決済み

I found a solution that has yet to not work so I'm going to stick with it. It's kind of a hack in my opinion but I haven't been able to find a better one. I tried checking in the files with the Vault api but I was only able to get that to work inconsistently. This could be avoided if inventor would allow Always save on close, but no luck there.

Here's the code if anyone is curious:

[DllImport("user32.dll")]
static extern IntPtr SetForegroundWindow(IntPtr hWnd);

[DllImport("user32.dll")]
static extern IntPtr GetForegroundWindow();

private static readonly SemaphoreSlim semaphore = new SemaphoreSlim(1, 1);
public Inventor.Application InventorApp { get; private set; } = null;

 

InventorApp.SilentOperation = false;

Task closeTask;

//prevent other threads from running this section
await semaphore.WaitAsync();
try
{
    //make inventor session as focus
    SetForegroundWindow((IntPtr)InventorApp.MainFrameHWND);

    //try to get file to checking on close
    closeTask = Task.Run(() => oDoc.Close(false));
    IntPtr popupHandle = GetForegroundWindow();

    //wait for save window to pop up
    while(popupHandle == (IntPtr)InventorApp.MainFrameHWND)
    {
          await Task.WhenAny(closeTask, Task.Delay(500, cToken)).ConfigureAwait(false);
          popupHandle = GetForegroundWindow();
    }
                            

     if (!closeTask.IsCompleted)
     {
         try
         {
             SetForegroundWindow(popupHandle);

             //send enter key press in save file dialoge
             SendKeys.SendWait("{ENTER}");
          }
          catch (Exception ex)
          {
              LogMessage("Couldn't press {ENTER}, Error: " + ex.Message, $"{instanceNo}: Error", 0);
          }
     }
}
finally
{
     //release section to other threads
     semaphore.Release();
}
InventorApp.SilentOperation = true;

 

 

0 件のいいね