Due to a company policy on how the PDM system operates, when the user checks in a file, the local copy is deleted from the users cache. My macro checks files out, edits them and checks back in again. If I try and edit a file that has just been edited I get a 'file not found' error (because it's been deleted from cache). I have tried to get around this by writing a sub to get the latest copy of a file immediatly before editing it to ensure there is always a file present but the code doesnt seem to retrieve the file. The sub is as below.
Sub GetLatest(fName As String)
Dim vaultName As String
Dim eVault As IEdmVault13
Dim eFile As IEdmFile8
Dim BG As IEdmBatchGet
Dim files(1) As EdmSelItem
'log into the vault
vaultName = Config.ReadXMLElement(pathConfig, "vaultname")
Set eVault = New EdmVault5
If Not eVault.IsLoggedIn Then
Call eVault.LoginAuto(vaultName, 0)
End If
'get the file to get lastest
Set eFile = eVault.GetFileFromPath(fName)
'put the file in an array
files(0).mlDocID = 0
files(0).mlProjID = eFile.ID
Set BG = eVault.CreateUtility(EdmUtil_BatchGet)
Call BG.AddSelection(eVault, files())
Call BG.CreateTree(0, EdmGetCmdFlags.Egcf_SkipExisting)
Call BG.GetFiles(0, Nothing)
End Sub
If I manually 'get latest' in the EPDM browser before editing the file, the macro reads it fine. The code is slightly modified from that posted by Michael Dekoning at https://forum.solidworks.com/thread/51105
From first glance, it looks like you are populating the EdmSelItem properties incorrectly.
The docID property is the database ID of the document. The ProjID property is the ID of the containing folder. For getting the latest version, you can use any containing folder, as it will be checked out in all folders. With EPDM, when a file is "shared" it can have multiple parent folder IDs it belongs to, and we can enumerate over then using the methods from iEdmFile5 GetFirstFolderPosition and GetNextFolder.
You can refer to the documentation for further information and examples.
If you want to get a single file, try the following adjustment and see if that does it:
Set eFile = eVault.GetFileFromPath(fName)
Dim eFolder as iEdmFolder5
Dim Pos as iEdmPos5
Set Pos=eFile.GetFirstFolderPosition
Set eFolder=eFile.GetNextFolder(Pos)
'Get the file from the folder
files(0).mlDocID = eFile.ID
files(0).mlProjID = eFolder.ID
When you provide DocID = 0 it tells EPDM to get all the files in the folder specified. Like so:
'Get all files from the folder
files(0).mlDocID = 0
files(0).mlProjID = eFolder.ID
Related
I have currently created code which grabs a ceratin file extension and puts it into a certain folder.
My.Computer.FileSystem.CreateDirectory(
"C:\Users\bj\Desktop\Excel Files")
Dim filePaths31 = IO.Directory.GetFiles("C:\Users\bj\Desktop\", "*.xlsx")
For Each filePath31 In filePaths31
Dim filename31 = IO.Path.GetFileName(filePath31)
Dim newPath31 = IO.Path.Combine("C:\Users\bj\Desktop\Excel Files", filename31)
If IO.File.Exists(newPath31) Then
MessageBox.Show("Error: Please check if the file elready exists")
Return
End If
IO.File.Move(filePath31, newPath31)
Next filePath31
MessageBox.Show("Excel Files Compiled And Cleaned")
This code works well although the directory implemented inside the code and should be different for every user.
I have experimented with this code here which allows a user to select a directory, although now I need help assigning that full directory into IO.Path.Combine(users chosen directory here + \Excel Files, filename31
If FolderBrowserDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then
Dim grade As New IO.DirectoryInfo(FolderBrowserDialog1.SelectedPath)
This code I believe grabs the user directory and stores it in the grade variable. I need to figure out how to store that 'grade' variable into my code, and also create a new folder in that directory that is specified in the code.
I got this problem at work that I have to do a lot with iManage (aka FileSite, DeskSite, WorkSite etc.) and maybe you've heard of it.
Anyways, what I'm trying to do is to write a VBA code which will be able to download a particular file based on its InFin number (7-digit number that is assigned to every file when being uploaded to iManage) and then place the file somewhere; For example, on the Desktop.
I know that iManage does expose an object model and I've already set the reference to IManExtLib.dll
I believe that the command I need is the Copy.Cmd (I don't want to cut sth from WorkSite but only download a copy of the file for the performed task).
Any help would be appreciated.
Assuming you already have a DMS session, you need to get an IManDocument object for your document you're trying to get and then call the GetCopy method. As an example, the following retrieves a physical copy of document number 123456 to a temp folder. Note you'll need to add a reference to IManage.dll as opposed to IManExtLib.dll.
Dim dmsRoot As IManDMS
Dim dmsSession As IManSession
Dim dmsDatabase As IManDatabase
Dim doc As IManDocument
Dim tempDocName As String
Const ServerName As String = "YourDMS"
Const DatabaseName As String = "YourDatabaseName"
Const DocNumToFind = 123456
Const DocVerToFind = 1
tempDocName = "C:\temp\mydoc.doc"
Set dmsRoot = New ManDMS
Set dmsSession = dmsRoot.Sessions.Add(ServerName)
dmsSession.TrustedLogin
Set dmsDatabase = dmsSession.Databases.ItemByName(DatabaseName)
Set doc = dmsDatabase.GetDocument(DocNumToFind, DocVerToFind)
doc.GetCopy tempDocName, imGetCopyOptions.imNativeFormat
I've got a checked list box that populates files and subfiles from a selected location using a folder browser dialog. What I'm trying to accomplish is retrieve each location/directory of every checked item within that list. I'm using these locations as a spot to copy and paste new files into if that makes sense.
I should add that I'm new to coding, and I don't know how to do something as "complex" as this. This is also my first post and I apologize if this is an easier type question for you guys.
For Each file As IO.FileInfo In ListBox1.CheckedItems
Dim NewFileName As String = FindListBox2ItemThatContains(file.Name)
Dim lstfiles As String = Directory.GetFiles(FBD2.SelectedPath)
If NewFileName.Trim.Length > 0 Then
IO.File.Copy(file.FullName, IO.Path.Combine(FBD2.SelectedPath, "item parent folder", NewFileName.Trim), True)
End If
ProgressBar1.Increment(+1)
Next
Alright, I am currently working on an Updater which is updating several files such as executable and drivers. I don't want to replace every single file every time I push an update and rather just replace the file that is actually getting updated. An easy way would be reading the Version of the program but I don't know how to read the required information. I went through IO.File but didn't find anything useful.
Try this for looping through a folder's files.
Option Explicit
Sub Macro1()
Dim varFile As Variant
Dim i As Integer
Dim objShell
Dim objDir
Set objShell = CreateObject("Shell.Application")
Set objDir = objShell.Namespace("C:\DIRECTORY_OF_FILES_HERE\")
For Each varFile In objDir.Items
Debug.Print objDir.GetDetailsOf(varFile, 156) ' 156 = File Version
Next
' Use this to see the numbers of all the attributes, e.g. 156 = File Version
'For i = 0 To 300
' Debug.Print i, objDir.GetDetailsOf(objDir.Items, i)
'Next
End Sub
You could create a separate file that will indicate the version of each individual files you will be updating. This is generally how I do things.
Say you have a file for this, we'll call it "version.txt". This is ideally what you would set it up like this: (you could do a lines format or javascript, whatever you feel most comfortable with)
mainapplication.version = 2.1
So, in your updater method, you would set the latest version as something like 2.2.
Dim alatestVersion As Double
alatestVersion = 2.2
You could then parse the text file and create a method to check if the component is of the latest version or not. Following this, if mainapplicationVersion != alatestVersion then [update].
Hope this helps.
Hi i've used the code bellow successfully at the beginning but i don't know what i did so it stopped creating the file MessageIO.dat under the folder (ProgramFiles)\UniWin Activator Data
i used this code: (result: created only folder UniWin Activator Data)
Dim UniWinPath As String = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles), "UniWin Activator Data")
Directory.CreateDirectory(UniWinPath)
Dim MsgIO = Path.Combine(UniWinPath, "\MessageIO.dat")
File.Create(MsgIO)
and used this: (result: error at the command File.Create)
Dim UniWinPath As String = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles), "UniWin Activator Data\MessageIO.dat")
File.Create(UniWinPath)
and used this: (result: nothing happened)
Dim UniWinPath As String = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles), "UniWin Activator Data")
Dim MsgIO = Path.Combine(UniWinPath, "\MessageIO.dat")
File.Create(MsgIO)
what's the way to create that file? (I have admin rights already)
The first of your code is perfectly fine. Just change Dim MsgIO = Path.Combine(UniWinPath, "\MessageIO.dat") to Dim MsgIO = Path.Combine(UniWinPath, "MessageIO.dat"). (Remove the backslash). Path.Combine automatically adds one. And as always, to access special directories, make sure you have Administrator Privilleges. The reason the last two codes aren't working is that File.Create creates a file in an existing directory. It can't create the directory itself.
When combining paths, you should not specify the "\" char at begining of the second path item as this will mean the root path!
for example, Path.Combine("D:\Folder1", "\MessageIO.dat") will result "\MessageIO.dat". but you have to write Path.Combine("D:\Folder1", "MessageIO.dat") which will return "D:\Folder1\MessageIO.dat"
Note: in windows 7 or above, access to special folders like as Program Files require special permissions! check that your app has such permission. (you can test for other norman folder first to ensure other parts of your code is ok)