iLogic make a excel list , check out write iProp, checkin and next read seznam check out write iProp

iLogic make a excel list , check out write iProp, checkin and next read seznam check out write iProp

pkrejcirik
Participant Participant
330 Views
4 Replies
Message 1 of 5

iLogic make a excel list , check out write iProp, checkin and next read seznam check out write iProp

pkrejcirik
Participant
Participant

Hi,

What I need,
I have Vault Basic, which doesn't allow for lifecycles. I'm trying to replace it with iLlogic. Which is to write the status released, save, checkin and checkout for the user "Released project" to the documentation from the release list. It writes the iprop only so that when the user sets the "Released project" to unchanged it will be returned back. We want the "Released project" user to checkin and make it obvious at a glance that the documentation has been released and is undergoing change control.

 

Now i have two ilogic. The first one creates a list of checkout assemblies and all referenced parts. It writes the status released and checkin the assembly and parts. For checkin I using:

ThisApplication.CommandManager.ControlDefinitions.Item("VaultCheckinTop").Execute2(False)
System.Windows.Forms.SendKeys.SendWait("" & Chr(9) & vbCrLf)

 This works well when called at the end of the code. Not in the second macro, which read through the list in excel to release the file and write the iProp.

This is a sub modified from @JhoelForshav I think that in the mVltCon object it should be possible to checkout the file, and write iprop. I blindly tried the objects it contains, but without success.
now I have this. It not work god 🙂 the problem is the line 

System.Windows.Forms.SendKeys.SendWait(vbCrLf)

when any part is open and iLogic is started, which loads excel and opens individual files and performs individual steps the send keys command is started when the document is closed again. I cannot get control over this.

 

	Sub Zarad(fileName, oRow)

		Dim oDoc As Document ' objekt dokumentu

		Dim oWF As String = mVltCon.WorkingFoldersManager.GetWorkingFolder("$/").FullPath
		If fileName.ToLower().Contains(oWF.ToLower()) Then
			oVaultFileName = fileName.Replace(oWF, "$/").Replace("\", "/")
		Else
			oCell = xlWs.Cells(oRow, 7) : oCell.Value = "Nenuložený/špatná cesta"		'zápis do určené buňky
			Trace.WriteLine("<Debug> 'Neuložený/špatná cesta  ")	' Debugovací výstup do Trace Konzole
			Exit Sub
		End If

		Dim oWSmgr As Autodesk.Connectivity.WebServicesTools.WebServiceManager = mVltCon.WebServiceManager
		Dim oFile As ACW.File = oWSmgr.DocumentService.FindLatestFilesByPaths(New String() {oVaultFileName }).FirstOrDefault()
		If oFile.Id = -1 Then
			oCell = xlWs.Cells(oRow, 7) : oCell.Value = "Není ve Vault"		'zápis do určené buňky
			Trace.WriteLine("<Debug> 'File Not in vault 2  ")	' Debugovací výstup do Trace Konzole
			Exit Sub
		End If

		Dim oFileIteration As New VDF.Vault.Currency.Entities.FileIteration(mVltCon, oFile)
		Dim oProps As PropertyDefinitionDictionary = mVltCon.PropertyManager.GetPropertyDefinitions(VDF.Vault.Currency.Entities.EntityClassIds.Files, Nothing, PropertyDefinitionFilter.IncludeAll)
		Dim oVaultStatus As PropertyDefinition = oProps(PropertyDefinitionIds.Client.VaultStatus)
		Dim status As EntityStatusImageInfo = TryCast(mVltCon.PropertyManager.GetPropertyValue(oFileIteration, oVaultStatus, Nothing), EntityStatusImageInfo)
		Dim oCheckoutState As EntityStatus.CheckoutStateEnum = status.Status.CheckoutState

		'		Dim wsFiels() As ACW.File = mVltCon.WebServiceManager.DocumentService.FindLatestFilesByPaths(VaultPaths)
		'		Dim mFileIt As VDF.Vault.Currency.Entities.FileIteration = New VDF.Vault.Currency.Entities.FileIteration(conn, wsFiels(0))

		Dim vydal As String = oFileIteration.CreateUserName

		If oCheckoutState = EntityStatus.CheckoutStateEnum.NotCheckedOut
			Trace.WriteLine("<Debug> 'nevydáno		" + CStr(fileName))	' Debugovací výstup do Trace Konzole
			Try
				oDoc = ThisApplication.Documents.Open(fileName, True)
			Catch
				oCell = xlWs.Cells(oRow, 8) : oCell.Value = "nepodařilo se otevřít soubor"		'nastaví zápis na určenou buňku
				'nepodařilo se otevřít soubor
			End Try

			Trace.WriteLine("<Debug> před release Kalan		" + CStr(fileName))	' Debugovací výstup do Trace Konzole

			oCtrdef = ThisApplication.CommandManager.ControlDefinitions.Item("VaultGetLatest")
			If Not oCtrdef Is Nothing Then		'Kontrola zda definovany ctrdef vubec existuje 
				oCtrdef.Execute2(False)
				System.Windows.Forms.SendKeys.SendWait(vbCrLf)
				ThisApplication.CommandManager.StopActiveCommand ' přeruší pokračující příkaz, pokud je stále v běhu
				Trace.WriteLine("<Debug> VaultGetLatest OK		" + CStr(fileName))	' Debugovací výstup do Trace Konzole
			Else
				Trace.WriteLine("<Debug> VaultGetLatest Neproveden		" + CStr(fileName))	' Debugovací výstup do Trace Konzole
			End If
			
			
			oCtrdef2 = ThisApplication.CommandManager.ControlDefinitions.Item("VaultCheckoutTop")
			ThisApplication.CommandManager.ControlDefinitions.Item("VaultCheckinTop").Execute2(False)
			System.Windows.Forms.SendKeys.SendWait("" & Chr(9) & vbCrLf)
			If Not oCtrdef2 Is Nothing Then
				oCtrdef2.Execute2(False)		'Kontrola zda definovany ctrdef vubec existuje
				Trace.WriteLine("<Debug> VaultCheckoutTop OK		" + CStr(fileName))	' Debugovací výstup do Trace Konzole
				ThisApplication.CommandManager.StopActiveCommand ' přeruší pokračující příkaz, pokud je stále v běhu
				oCell = xlWs.Cells(oRow, 7) : oCell.Value = "OK"		'nastaví zápis na určenou buňku
			Else
				oCell = xlWs.Cells(oRow, 7) : oCell.Value = "NE"		'nastaví zápis na určenou buňku
				Trace.WriteLine("<Debug> VaultCheckoutTop Neproveden		" + CStr(fileName))	' Debugovací výstup do Trace Konzole
			End If
			oDoc.Close

		ElseIf oCheckoutState = EntityStatus.CheckoutStateEnum.CheckedOutByOtherUser
			oCell = xlWs.Cells(oRow, 8) : oCell.Value = vydal		'nastaví zápis na určenou buňku
			Trace.WriteLine("<Debug> vydáno někomu jinému		" + CStr(fileName))	' Debugovací výstup do Trace Konzole

		ElseIf oCheckoutState = EntityStatus.CheckoutStateEnum.CheckedOutByCurrentUser
			oCell = xlWs.Cells(oRow, 8) : oCell.Value = "již byl proveden release Kalan"		'nastaví zápis na určenou buňku
			Trace.WriteLine("<Debug> již byl proveden release Kalan		" + CStr(fileName))	' Debugovací výstup do Trace Konzole
		Else
			Trace.WriteLine("<Debug> neznámý stav		" + CStr(fileName))	' Debugovací výstup do Trace Konzole
		End If

	End Sub


 

0 Likes
331 Views
4 Replies
Replies (4)
Message 2 of 5

pkrejcirik
Participant
Participant

No one knows how checkin and checkout occurencies from excel list? @JhoelForshav or @WCrihfield.

I really don't know what to do.

0 Likes
Message 3 of 5

WCrihfield
Mentor
Mentor

Hi @pkrejcirik.  I may not be much help in this specific case, because I do not currently use Vault, and have not used it in the recent past either.  So I do not have any experience interacting with Vault by code either.  Hopefully either Jhoel or one of the others here on the forum can help you out with this challenge.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 4 of 5

pkrejcirik
Participant
Participant

Hi, thanks for the reply, I'll wait for Jhoel

0 Likes
Message 5 of 5

pkrejcirik
Participant
Participant

For completeness I am inserting the whole iLogic for checkin.

 

AddReference "C:\Program Files\Autodesk\Inventor 2020\Bin\Autodesk.Connectivity.WebServices.dll"
AddReference "C:\Program Files\Autodesk\Inventor 2020\Bin\Autodesk.DataManagement.Client.Framework.dll"
AddReference "C:\Program Files\Autodesk\Inventor 2020\Bin\Autodesk.DataManagement.Client.Framework.Vault.dll"
AddReference "C:\Program Files\Autodesk\Inventor 2020\Bin\Connectivity.Application.VaultBase.dll"
'AddReference "C:\Program Files\Autodesk\Inventor 2020\Bin\Connectivity.InventorAddin.EdmAddin.dll" ' pravděpodobně pro Vault profesional/workgroup
Imports VDF = Autodesk.DataManagement.Client.Framework
Imports Autodesk.DataManagement.Client.Framework.Vault.Currency.Connections
Imports ACW = Autodesk.Connectivity.WebServices
Imports VB = Connectivity.Application.VaultBase
Imports Autodesk.DataManagement.Client.Framework.Vault.Currency.Properties

AddReference "Microsoft.Office.Interop.Excel" 'Pro použití excelu

Imports Microsoft.Office.Interop.Excel        'Pro použití excelu
Imports System.Runtime.InteropServices        'Pro použití zařazení
Imports System.Activator                      'Použití Instance
Imports System.Type                           'Použití GetTypeFromProgID
Class Excel

	Dim mVltCon As VDF.Vault.Currency.Connections.Connection
	Dim oXLtemplate As String
	Dim oXLWorkBook As String
	Dim oXLWorkSheet As String
	Dim xlWb As Workbook
	Dim xlWs As Worksheet
	Dim oList As ArrayList

	Sub Main()

		mVltCon = VB.ConnectionManager.Instance.Connection
		If mVltCon Is Nothing Then
			MessageBox.Show("Nejsi přihlášen do Vaultu" & vbCrLf & vbCrLf & "Přihlas se prosím a znovu spusť makro")
			Exit Sub
		End If

		'Iventor File Dialog
		Dim oFileDlg As Inventor.FileDialog
		Dim oDocFile As Document, oDocFileName As String
		InventorVb.Application.CreateFileDialog(oFileDlg)		'Spusť  File Selection Code

		'přednastavení cesty a omezení výběru přípony
		oFileDlg.InitialDirectory = "P:\Projekty\WOL20\01a_PDM"
		oFileDlg.Filter = "Excel Spec Sheet (*.xls;*.xlsx;*xlsm)|*.xls;*.xlsx;*xlsm"
		If oFileDlg.CancelError = True Then Exit Sub		'nastavení stisku tlačítka Cancel na error - ukončí dialog a vrátí zpět prázdnou cestu
		'Otevři Dialog.
		oFileDlg.ShowOpen()		'Otevři Dialog.
		If oFileDlg.FileName = ""		'pokud je cesta prázdná ukonči
			'MessageBox.Show("Není vybrán soubor", "Release NST Kalan")
			Exit Sub
		End If

		oXLWorkBook = oFileDlg.FileName		'vloží fullfilename vybraného souboru
		'oXLWorkBook = InputBox("VLOŽ ÚPNOU CESTU K EXCELU z .....uvolněno.log", "PŘÍSTUP K SOUBORU", "") ' Test listu načteneho KODu => zobrazí hodnoty které nalezl v tabulce
		'oXLWorkBook = "P:\Projekty\WOL20\01a_PDM\20230718_KV_TEST_001\KV_TEST_001_uvolněno.xlsx"
		oXLWorkSheet = "Release (k uvolnění)"
		Dim oXLClass As New Cl_xlApp		'definuje třídu pro ověření, zda je excel otevřen pokud ne aktivuje již otevřený.
		Dim oExcelApp As Microsoft.Office.Interop.Excel.Application = oXLClass.ExcelInstance		'spuštění třídy.
		System.Windows.Forms.SendKeys.SendWait(vbCrLf)
		Try
			oExcelApp.DisplayAlerts = False	' nezobrazí výstrahy pokud dokument není nalezen
		Catch
			MessageBox.Show("V excelu edituješ buňku, běž do excelu a Tabulátorem, nebo entrem zruš editaci", "Release NST Kalan", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1)
			oExcelApp = Nothing
			Exit Sub
		End Try
		Try
			xlWb = oExcelApp.Workbooks.Open(oXLWorkBook)
		Catch
			MessageBox.Show("Excel nenalezen. ZADEJ PLNOU ADRESU K SOUBORU", "Release NST Kalan", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1)
			oExcelApp = Nothing
			Exit Sub
		End Try

		xlWs = xlWb.Worksheets(oXLWorkSheet)
		'oExcelApp.Visible = True

		FindRow()

		xlWb.Save			'uloží excel
		oExcelApp = Nothing ' ukončení třídy

	End Sub

	Sub FindRow()

		oList = New ArrayList
		Dim oLastRow As Integer = xlWs.Cells(xlWs.Rows.Count, 5).End(XlDirection.xlUp).Row   'najde poslední zapsaný řádek v 5. sloupci
		Trace.WriteLine("<Debug> Poslední nalezený řádek:   " + CStr(oLastRow))	' Debugovací výstup do Trace Konzole
		For i = 2 To oLastRow 'nastavení rozsahu opakování

			pol = xlWs.Cells.Item(i, 5).Value	'získá do proměnné hodnotu adresované buňky
			Trace.WriteLine("<Debug>řádek " + CStr(i) + "	cesta	" + CStr(pol))	' Debugovací výstup do Trace Konzole

			Zarad(pol, i)

			'			If pol = "" Then Exit For 'pokud bude buňka prázdná přeruš smyčku 
			'			oList.Add(pol) ' vloží hodnotu do Arraylistu
		Next
		'InputListBox("Nedělá nic", oList, "Seznam") ' Test list načteneho excelu => zobrazí hodnoty které nalezl v tabulce

	End Sub

	Sub Zarad(fileName, oRow)

		Dim oDoc As Document ' objekt dokumentu
		Dim invDesignInfo As PropertySet


		Dim oWF As String = mVltCon.WorkingFoldersManager.GetWorkingFolder("$/").FullPath
		If fileName.ToLower().Contains(oWF.ToLower()) Then
			oVaultFileName = fileName.Replace(oWF, "$/").Replace("\", "/")
		Else
			oCell = xlWs.Cells(oRow, 7) : oCell.Value = "Nenuložený/špatná cesta"		'zápis do určené buňky
			Trace.WriteLine("<Debug> 'Neuložený/špatná cesta  ")	' Debugovací výstup do Trace Konzole
			Exit Sub
		End If

		Dim oWSmgr As Autodesk.Connectivity.WebServicesTools.WebServiceManager = mVltCon.WebServiceManager
		Dim oFile As ACW.File = oWSmgr.DocumentService.FindLatestFilesByPaths(New String() {oVaultFileName }).FirstOrDefault()
		If oFile.Id = -1 Then
			oCell = xlWs.Cells(oRow, 7) : oCell.Value = "Není ve Vault"		'zápis do určené buňky
			Trace.WriteLine("<Debug> 'File Not in vault 2  ")	' Debugovací výstup do Trace Konzole
			Exit Sub
		End If

		Dim oFileIteration As New VDF.Vault.Currency.Entities.FileIteration(mVltCon, oFile)
	
		Dim oProps As PropertyDefinitionDictionary = mVltCon.PropertyManager.GetPropertyDefinitions(VDF.Vault.Currency.Entities.EntityClassIds.Files, Nothing, PropertyDefinitionFilter.IncludeAll)
		Dim oVaultStatus As PropertyDefinition = oProps(PropertyDefinitionIds.Client.VaultStatus)
		Dim status As EntityStatusImageInfo = TryCast(mVltCon.PropertyManager.GetPropertyValue(oFileIteration, oVaultStatus, Nothing), EntityStatusImageInfo)
		Dim oCheckoutState As EntityStatus.CheckoutStateEnum = status.Status.CheckoutState

		Dim vydal As String = oFileIteration.CreateUserName

		If oCheckoutState = EntityStatus.CheckoutStateEnum.NotCheckedOut
			Trace.WriteLine("<Debug> 'nevydáno		" + CStr(fileName))	' Debugovací výstup do Trace Konzole
			Try
				oDoc = ThisApplication.Documents.Open(fileName, True)
				invDesignInfo = oDoc.PropertySets.Item("Design Tracking Properties") ' definice objektu iProp
			Catch
				oCell = xlWs.Cells(oRow, 8) : oCell.Value = "nepodařilo se otevřít soubor"		'nastaví zápis na určenou buňku
				'nepodařilo se otevřít soubor
			End Try

			Trace.WriteLine("<Debug> před release Kalan		" + CStr(fileName))	' Debugovací výstup do Trace Konzole

			'			oCtrdef = ThisApplication.CommandManager.ControlDefinitions.Item("VaultGetLatest")
			'			If Not oCtrdef Is Nothing Then		'Kontrola zda definovany ctrdef vubec existuje 
			'				oCtrdef.Execute2(False)
			'				System.Windows.Forms.SendKeys.SendWait(vbCrLf)
			'				ThisApplication.CommandManager.StopActiveCommand ' přeruší pokračující příkaz, pokud je stále v běhu
			'				Trace.WriteLine("<Debug> VaultGetLatest OK		" + CStr(fileName))	' Debugovací výstup do Trace Konzole
			'			Else
			'				Trace.WriteLine("<Debug> VaultGetLatest Neproveden		" + CStr(fileName))	' Debugovací výstup do Trace Konzole
			'			End If


			oCtrdef2 = ThisApplication.CommandManager.ControlDefinitions.Item("VaultCheckoutTop")
			System.Windows.Forms.SendKeys.SendWait("" & Chr(9) & vbCrLf)
			If Not oCtrdef2 Is Nothing Then
				oCtrdef2.Execute2(False)		'Kontrola zda definovany ctrdef vubec existuje
				Trace.WriteLine("<Debug> VaultCheckoutTop OK		" + CStr(fileName))	' Debugovací výstup do Trace Konzole
				ThisApplication.CommandManager.StopActiveCommand ' přeruší pokračující příkaz, pokud je stále v běhu
				oCell = xlWs.Cells(oRow, 7) : oCell.Value = "OK"		'nastaví zápis na určenou buňku
				
				'invDesignInfo.Item("Description").Value = "Release"
			Else
				oCell = xlWs.Cells(oRow, 7) : oCell.Value = "NE"		'nastaví zápis na určenou buňku
				Trace.WriteLine("<Debug> VaultCheckoutTop Neproveden		" + CStr(fileName))	' Debugovací výstup do Trace Konzole
			End If
			oDoc.Save
			oDoc.Close

		ElseIf oCheckoutState = EntityStatus.CheckoutStateEnum.CheckedOutByOtherUser
			oCell = xlWs.Cells(oRow, 8) : oCell.Value = vydal		'nastaví zápis na určenou buňku
			Trace.WriteLine("<Debug> vydáno někomu jinému		" + CStr(fileName))	' Debugovací výstup do Trace Konzole

		ElseIf oCheckoutState = EntityStatus.CheckoutStateEnum.CheckedOutByCurrentUser
			oCell = xlWs.Cells(oRow, 8) : oCell.Value = "již byl proveden release Kalan"		'nastaví zápis na určenou buňku
			Trace.WriteLine("<Debug> již byl proveden release Kalan		" + CStr(fileName))	' Debugovací výstup do Trace Konzole
		Else
			Trace.WriteLine("<Debug> neznámý stav		" + CStr(fileName))	' Debugovací výstup do Trace Konzole
		End If

	End Sub

End Class

Class Cl_xlApp

	Dim Public ExcelInstance As Microsoft.Office.Interop.Excel.Application
	Dim Public ActiveBook As Workbook
	Dim Public _started As Boolean

	Public Sub New()

		Try
			ExcelInstance = Marshal.GetActiveObject("Excel.Application")
			ActiveBook = ExcelInstance.ActiveWorkbook
			Trace.WriteLine("<Debug> Cl_xlApp ActiveBook   ")	' Debugovací výstup do Trace Konzole
		Catch ex As Exception
			Try
				Dim xlAppType As Type = GetTypeFromProgID("Excel.Application")
				ExcelInstance = CreateInstance(xlAppType)
				ExcelInstance.Visible = True
				ActiveBook = ExcelInstance.ActiveWorkbook
				_started = True
			Catch ex2 As Exception
				MsgBox(ex2.ToString())
				MessageBox.Show("Nelze spustit excel", "Release NST Kalan", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1)
			End Try
		End Try
	End Sub
End Class
 

 

0 Likes