What's new

Saving to M-Files with SaveNew Method

KageDev

Member
In the documentation it states:
"To save to MFiles vaults using the API, you will use the same methods as with the file system. The filepath should be passed with the following format: [MFiles drive letter]:\[Vault name] (ie. "M:\MyVault")".
Is this saying I need to use a different method to save to my vault or just saying the file path needs to be that for the vault. I have tried saving a drawing in the form that they gave an example of but have not had any luck. It just states that the alibre vault is not available. I'm also confused about why the parameter is an Object ref. The documentation says I could pass a windows folder path string but my C# program says the parameter type is incorrect. Anybody have any suggestions. Here is a screen shot ( keep in mind the file path is using the escape character (\) for the backslash ):
1724679734392.png
 

bolsover

Senior Member
I don't use M-files sot I'm not entirely clear about what the code does - although I understand you want to save the drawing.

Question - does line 236 succeed? Is the .dxf saved?

Line 240 looks like an attempt to save a .AD_DRW (drawing session) but possibly without the correct filename extension?

Have your tried debugging - what is the state of drawingSession at line 240?

Have your tried a simple drawingSession.saveAS(Object pDestination, string itemName) ?

David
 

KageDev

Member
does line 236 succeed? Is the .dxf saved?
Yes, this does export and save to M-Files.
what is the state of drawingSession at line 240?
The session is still open and running as it should.
Have your tried a simple drawingSession.saveAS(Object pDestination, string itemName) ?
I have tried this but came up with the same result. I have also tried the SaveAll which does work but it saves every session that I have open and not in the correct location. Only to the C drive.
 

bolsover

Senior Member
I suspect this may be one for support but you might try stepping into the SaveNew method to see if you can determine the exact failure point. I don't use Visual Studio/Code overmuch because I use Jetbrains and have access to dotPeek..

I can see that SaveNew is implemented in com.alibre.automation.AlibreSession in the alibre-api package.

The SaveNew method implementation is quite complex making numerous validation checks - such as ensuring the session is valid and (in the case of M-files) that the given path is an M-files path and that the vault is available.

Just a little bit of what I see in the SaveNew() implementation with what seem like references to the failure point..
In the context below, singleton1 is the VaultManager.

C#:
 else if (System.Type.GetTypeCode(type) == TypeCode.String)
        {
          string str = (string) destination;
          if (this.isMFilesPath(str))
          {
            if (singleton1.MFilesAvailable)
            {
              if (str.EndsWith("\\"))
                str = str.Remove(str.LastIndexOf("\\"));
              vaultName = Path.GetFileName(str);
              if (singleton1.isVaultAvailable(vaultName))
                flag = true;
              else
                customCode = -2147220696;
            }
            else
              customCode = -2147220696;
          }

Tracking down code 2147220696 I see

C#:
 this.customErrorMap[(object) -2147220696] = (object) "The Alibre Vault is not available";

This seems to tie in with your description.

So... Next question, are you sure the M files vault is available at line 240 of your code?

David
 

stepalibre

Alibre Super User
I used M-Files extensively and the API when I purchased Expert maybe 10+ years ago. Without more context and access to M-Files it's difficult debug this.

A few things to consider:

Is "Vault" selected?

1724718612031.png

Are you checking if the vault is available before calling methods?

1724718872752.png

You can use the M-Files API alongside AlibreX. I made programs that saved Alibre files to M-Files outside of Alibre using the M-Files API.

keep in mind the file path is using the escape character (\) for the backslash )
What is the purpose of this? A regex seems like overkill to me. You could use String.Replace(). Or you could add @ to the C# string literal to escape characters.

string ThePath = @"M:\MyVault\files\a"
 

Attachments

  • 1724719476193.png
    1724719476193.png
    36.9 KB · Views: 2
Last edited:

KageDev

Member
I figured out the issue. It did not like that I had the exact object location that I was trying to save to. I just needed to have M:\Kage Vault as my destination and it saved. I will just have to move the document to it's desired location after saving and closing the drawing session but it shouldn't be too hard to figure that out. Thank you both for the suggestions. I was able to figure out the issue from pieces of your responses.
 
Top