Create folder structures with VB.net Windows Form

Create folder structures with VB.net Windows Form

w.vanaart
Participant Participant
3,196 Views
9 Replies
Message 1 of 10

Create folder structures with VB.net Windows Form

w.vanaart
Participant
Participant

Hi everybody,

 

I've searched this forum to see if there already was a thread which answers my question, but alas...

 

For every project I start working on I first need to create folder structures in several places.

i.e.: Folders related to order number, serial number and photos/videos (all in different directories).

 

I've coded a little tool in VB.net which creates these folders in the right directories, but I would like it (if at all possible) to create these as well in the Vault.

Unfortunately, since this is the first tool I've ever written, I have absolutely no idea how to go about this.

 

Some further information:

We run Vault Workgroup 2019 at our company and everybody who should be using this tool has their own login (but if more simple, it would be just fine to use "generic credentials" for this tool to work).

Permissions are set in a way that they can add sub-folders to the required folder.

 

I hope you can guide me in the right direction on how to incorporate this.

Thanks in advance.

 

 

Below my code for the tool (creation of folder structures in Windows Explorer) and attached a visual of my tool.

 

Public Class Form5a

    Private Sub Button6_Click(sender As Object, e As EventArgs) Handles Button6.Click
        'Create project and media folders
        'declare variables
        Dim CN, CC, CL, CA, AN, PRN, SD As String
        CN = Me.TextBox1.Text
        CC = Me.ComboBox11.Text
        CL = Me.TextBox2.Text
        CA = Me.TextBox3.Text
        AN = Me.TextBox4.Text
        PRN = Me.TextBox5.Text

        Dim substring As String
        substring = Strings.Right(CC, 4)
        SD = CL & " " & substring & " - " & CA


        'compile path
        If System.IO.Directory.Exists("K:\Master Data Management\02. External Projects\" & PRN) = True Then
            MessageBox.Show("Project directory already exists!")

        Else
            System.IO.Directory.CreateDirectory("K:\Master Data Management\02. External Projects\" & PRN)
            My.Computer.FileSystem.CopyDirectory("K:\Master Data Management\02. External Projects\00. Folder Templates\Folder Template - Order\00000 (Ordernr)", "K:\Master Data Management\02. External Projects\" & PRN)
            MessageBox.Show("Project directory succesfully created!")
        End If

        If System.IO.Directory.Exists("\\Nas01\Mediadisk\External Projects\" & CN & "\" & SD & "\" & "Area" & " " & AN & "\") = True Then
            MessageBox.Show("Media directory already exists!")

        Else
            System.IO.Directory.CreateDirectory("\\Nas01\Mediadisk\External Projects\" & CN & "\" & SD & "\" & "Area" & " " & AN & "\")
            My.Computer.FileSystem.CopyDirectory("\\Nas01\Mediadisk\External Projects\00. Folder Templates\Naam bestemmingsrelatie\Plaats (landcode) - Adres\Area No", "\\Nas01\Mediadisk\External Projects\" & CN & "\" & SD & "\" & "Area" & " " & AN & "\")
            MessageBox.Show("Media directory succesfully created!")
        End If
    End Sub





    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        Dim CN, PRN As String
        CN = Me.TextBox1.Text
        PRN = Me.TextBox5.Text
        Process.Start("explorer.exe", "K:\Project Data\02. External Projects\" & PRN)
        Process.Start("explorer.exe", "\\Nas01\Mediadisk\External Projects\" & CN)
    End Sub



    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim Foldername As String
        Dim CN, CC, CL, CA, AN, SD As String
        CN = Me.TextBox1.Text
        CC = Me.ComboBox11.Text
        CL = Me.TextBox2.Text
        CA = Me.TextBox3.Text
        AN = Me.TextBox4.Text

        Dim substring As String
        substring = Strings.Right(CC, 4)
        SD = CL & " " & substring & " - " & CA

        For Each Foldername In Me.ListBox2.Items

            System.IO.Directory.CreateDirectory("K:\Master Data Management\01. Service Objects\" & Foldername)
            System.IO.Directory.CreateDirectory("\\Nas01\Mediadisk\External Projects\" & CN & "\" & SD & "\" & "Area" & " " & AN & "\" & "02. Production" & "\" & Foldername)
            System.IO.Directory.CreateDirectory("\\Nas01\Mediadisk\External Projects\" & CN & "\" & SD & "\" & "Area" & " " & AN & "\" & "04. Installation" & "\" & Foldername)
            System.IO.Directory.CreateDirectory("\\Nas01\Mediadisk\External Projects\" & CN & "\" & SD & "\" & "Area" & " " & AN & "\" & "05. Aftersales" & "\" & Foldername)


            My.Computer.FileSystem.CopyDirectory("K:\Master Data Management\01. Service Objects\00. Folder Template - Service Objects\[SON] - [SOD]-[(SOC)]", "K:\Master Data Management\01. Service Objects\" & Foldername)

        Next
        MessageBox.Show("Service Object directories succesfully created!")
    End Sub

    'Add
    Private Sub Add(text As String)
        Dim SON, SOD, PUC, SOC As String
        SON = Me.NumericUpDown1.Value
        SOD = Me.ComboBox1.Text
        SOC = Me.NumericUpDown2.Value

        'create PUC abbreviation
        If SOD = "Box Handling" Then
            PUC = "BH"
        End If
        If SOD = "Buffer System" Then
            PUC = "BS"
        End If
        If SOD = "Cart Handling" Then
            PUC = "CH"
        End If
        If SOD = "Filling System" Then
            PUC = "FS"
        End If
        If SOD = "Information System" Then
            PUC = "IS"
        End If
        If SOD = "Packing Line" Then
            PUC = "PL"
        End If
        If SOD = "Palletising System" Then
            PUC = "PS"
        End If
        If SOD = "Tipping System" Then
            PUC = "TS"
        End If
        'merge to text string
        text = SON & " " & "-" & " " & SOD & " " & "(" & PUC & SOC & ")"



        ListBox2.Items.Add(text)
    End Sub

    Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
        Add(Text)

    End Sub

    Private Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click
        Dim selected As String = Me.ListBox2.SelectedItem.ToString

        If selected IsNot "" Then
            Me.ListBox2.Items.Remove(selected)
        End If
    End Sub

    Private Sub Button7_Click(sender As Object, e As EventArgs) Handles Button7.Click
        Me.ListBox2.Items.Clear()
    End Sub


End Class

 

0 Likes
Accepted solutions (3)
3,197 Views
9 Replies
Replies (9)
Message 2 of 10

Markus.Koechl
Autodesk
Autodesk
Accepted solution

You could review the AU class https://www.autodesk.com/autodesk-university/class/Autodesk-Vault-2020-Programming-101-2019 to get started using the Vault SDK/API and its project templates. The class teaches how to create a single folder. Once you reached this level, the next step, e.g., reading a template folder structure and creating folder trees, is not a big deal. Another alternative is using the extended scripting of Vault Data Standard (VDS). There are sample configurations available that read a template folder structure based on a folder category and copy the full tree for new projects or folders. My VDS Quickstart sample shares the sources here: https://github.com/koechlm/VDS-2021-Quickstart/blob/master/VDS-2021-Quickstart/Vault.Custom/addinVau.... However, if you are new to VDS, you should not start there and walk through the VDS tutorial first - vault-data-standard-tutorial.



Markus Koechl

Solutions Engineer PDM, Autodesk Central Europe
0 Likes
Message 3 of 10

w.vanaart
Participant
Participant
Thanks Markus, I'll be sure to try this!
0 Likes
Message 4 of 10

w.vanaart
Participant
Participant

@Markus.Koechl 

I've started programming your C# example in VB.net.

First I've installed the SDK for Vault Workgroup 2019 and then added the references (Connectivity.Webservices etc) to my project in Visual Studio.

 

But I just can't seem to add the AdskLicensingSDK_2.dll. Since it didn't exist, I manually added the .dll from your example (since it was the only one I could find on my harddrive) to directory: C:\Program Files (x86)\Autodesk\Autodesk Vault 2019 SDK\bin\x64.

When I then try to add it (Command: Add Reference) within Visual Studio the following error appears:

 

Reference error.JPG

 

Any help is much appreciated!

 

 

0 Likes
Message 5 of 10

Markus.Koechl
Autodesk
Autodesk
Accepted solution

Vault 2019 requires the clmloader.dll for licensing, Vault 2020 the AdskLicensingSDK_2.dll, and Vault 2021 the AdskLicensingSDK_3.dll and so on. You need to compare each SDK versions' Help documentation for it as it might continue changing.



Markus Koechl

Solutions Engineer PDM, Autodesk Central Europe
0 Likes
Message 6 of 10

w.vanaart
Participant
Participant

Thanks @Markus.Koechl

I got this to work in a simple form (click a button and the coded folder is created).

The only bug/error I run into is in the second "Throw ex" (as shown in the printscreen)

 

Error 303.JPG

 

Please see my code below (for security reasons I've altered the credentials)

 

Imports System
Imports System.Collections.Generic
Imports System.Linq
Imports System.Text
Imports System.Threading.Tasks
Imports Autodesk.Connectivity.WebServices
Imports Autodesk.Connectivity.WebServicesTools

Public Class Form11
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click


        Dim mServerId As ServerIdentities = New ServerIdentities()
        mServerId.DataServer = "***"
        mServerId.FileServer = "***"
        Dim mVaultName As String = "***"
        Dim mUserName As String = "***"
        Dim mPassword As String = "***"
        Dim mLicAgent As LicensingAgent = LicensingAgent.Server
            Dim mVault As WebServiceManager = Nothing
            Dim mCred As UserPasswordCredentials = Nothing

            Try
                mCred = New UserPasswordCredentials(mServerId, mVaultName, mUserName, mPassword, mLicAgent)
                mVault = New WebServiceManager(mCred)

                Try
                Dim mFolder As Folder = mVault.DocumentService.GetFolderByPath("$/Designs/01. Service Objects")
                Dim mProjectFolder As Folder = mVault.DocumentService.AddFolder("Test", mFolder.Id, False)
                Dim mFolderCategories As Cat() = mVault.CategoryService.GetCategoriesByEntityClassId("FLDR", True)
                Dim mProjectFldrCatId As Long = mFolderCategories.Where(Function(n) n.Name = "Folder").FirstOrDefault().Id
                Dim mUpdatedFolders As Folder() = mVault.DocumentServiceExtensions.UpdateFolderCategories(New Long() {mProjectFolder.Id}, New Long() {mProjectFldrCatId})
                Catch ex As Exception
                    Throw ex
                End Try

                mVault.Dispose()
            Catch ex As Exception
                Throw ex
            End Try
        End Sub
    End Class

 

Thanks again for your help!

0 Likes
Message 7 of 10

Markus.Koechl
Autodesk
Autodesk
Accepted solution

The error 303 reflects missing permission for action; you can look-up error codes in the SDK Help searching for the number.

I only can guess what causes the exception, but you could step by step review where it happens; because you are saying that the folder successfully created, I think that the reason is your default category is "Folder," and you try to update the new folder's category to "Folder". If you try the same in the UI, Vault returns the message that the action can't be performed because nothing changed.



Markus Koechl

Solutions Engineer PDM, Autodesk Central Europe
0 Likes
Message 8 of 10

w.vanaart
Participant
Participant

Hi @Markus.Koechl 

In your opinion, what would be the way to go if I wanted to create multiple sub-folders (e.g. from a template structure stored in Vault) in every folder the code below creates.

 

I've read into and tried Data Standards and such, but at this point that doesn't really make any sense to me.

Is it even possible to do this in VB.net without calling the Vault too much (every parent folder should get 3 or 4 sub-folders)?

 

I hope you can steer me in the right direction!

Thanks in advance.

 

 

    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click

        'create Folders for Service Objects
        Dim Foldername As String
        Dim EUN, EUC, EUL, EUA, EUSN, SD, PRN, SON, SOD, SOC, SBPC As String
        EUN = Me.TextBox1.Text
        EUC = Me.ComboBox11.Text
        EUL = Me.TextBox2.Text
        EUA = Me.TextBox3.Text
        EUSN = Me.TextBox4.Text
        PRN = Me.TextBox5.Text
        SON = Me.NumericUpDown1.Value
        SOD = Me.ComboBox1.Text
        SOC = Me.NumericUpDown2.Value
        SBPC = Me.TextBox6.Text & Me.NumericUpDown4.Value & "-v0" & Me.NumericUpDown5.Value

        Dim substring As String
        substring = Strings.Right(EUC, 4)
        SD = EUL & " " & substring & " - " & EUA

        'CREATE FOLDER IN AUTODESK VAULT

        Dim mServerId As ServerIdentities = New ServerIdentities()
        mServerId.DataServer = "***"
        mServerId.FileServer = "***"
        Dim mVaultName As String = "***"
        Dim mUserName As String = "***"
        Dim mPassword As String = "***"
        Dim mLicAgent As LicensingAgent = LicensingAgent.Server
        Dim mVault As WebServiceManager = Nothing
        Dim mCred As UserPasswordCredentials = Nothing


        For Each Foldername In Me.ListBox2.Items

            Try
                mCred = New UserPasswordCredentials(mServerId, mVaultName, mUserName, mPassword, mLicAgent)
                mVault = New WebServiceManager(mCred)

                Try
                    Dim mFolder As Autodesk.Connectivity.WebServices.Folder = mVault.DocumentService.GetFolderByPath("$/Designs/01. Service Objects")
                    Dim mProjectFolder As Autodesk.Connectivity.WebServices.Folder = mVault.DocumentService.AddFolder(Foldername, mFolder.Id, False)
                    Dim mFolderCategories As Cat() = mVault.CategoryService.GetCategoriesByEntityClassId("FLDR", True)
                    'Dim mProjectFldrCatId As Long = mFolderCategories.Where(Function(n) n.Name = "Folder").FirstOrDefault().Id
                    'Dim mUpdatedFolders As Autodesk.Connectivity.WebServices.Folder() = mVault.DocumentServiceExtensions.UpdateFolderCategories(New Long() {mProjectFolder.Id}, New Long() {mProjectFldrCatId})

                Catch ex As Exception
                    Throw ex
                End Try

                mVault.Dispose()
            Catch ex As Exception
                Throw ex
            End Try

        Next

    End Sub
0 Likes
Message 9 of 10

jeremy.hiser
Explorer
Explorer

@w.vanaart - How did you get around this issue you had adding the reference to AdskLicensingSDK_2.dll?  I get the same error you mentioned when I attempt to add that reference.

0 Likes
Message 10 of 10

w.vanaart
Participant
Participant

@jeremy.hiserThe problem with my program was that I tried to add the AdskLicensingSDK_2.dll for Autodesk Vault 2019 (most examples I studied online used that one).

But for the 2019-version you'll need to add the clmloader.dll instead of AdskLicensingSDK_2.dll (which is used for Vault 2020).

I hope this helps!

0 Likes