Hello,
i'm working on a vb.net program that can search the vault and show parts specifications. After a lot of sniping and the Vault SDK I came to the code below that searches a part and shows the part number and other specs. I also found the RenderThumbnailToImage function but seem unable to get it working. How do I call this function so that I can display the thumbnail image in a picturebox. Setting the propInst right seems to be the problem.
Any help is much appreciated,
Private Sub m_searchResultsListBox_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles m_searchResultsListBox.SelectedIndexChanged
If m_searchResultsListBox.SelectedItem IsNot Nothing Then
Dim fileItem As ListBoxFileItem = DirectCast(m_searchResultsListBox.SelectedItem, ListBoxFileItem)
If m_searchResultsListBox.SelectedItem IsNot Nothing Then
Dim file As File = fileItem.File
lblpartnumber.Text = getProperty(file, "PartNumber")
lblstocknr.Text = getProperty(file, "StockNumber")
lbldescription.Text = getProperty(file, "Description")
lblrevision.Text = getProperty(file, "Rev Number")
End If
End If
End Sub
Public Function getProperty(ByVal file As File, ByVal zoekproperty As String)
On Error Resume Next
Using serviceManager As WebServiceManager = m_connection.WebServiceManager
Dim providerString As String
Dim providerPropInst As PropInst
Dim providerPropDef As PropDef
providerPropDef = serviceManager.PropertyService.GetPropertyDefinitionsByEntityClassId("FILE").First(Function(propDef) propDef.SysName.Equals(zoekproperty))
providerPropInst = serviceManager.PropertyService.GetProperties("FILE", New Long() {file.Id}, New Long() {providerPropDef.Id}).First()
providerString = TryCast(providerPropInst.Val, String)
Return providerString
End Using
errorhandler:
End Function
Public Shared Function RenderThumbnailToImage(ByVal propInst As PropInst, ByVal width As Integer, ByVal height As Integer) As Image
' convert the property value to a byte array
Dim thumbnailRaw As Byte() = TryCast(propInst.Val, Byte())
If thumbnailRaw Is Nothing OrElse 0 = thumbnailRaw.Length Then
Return Nothing
End If
Dim retImage As Image = Nothing
Using memStream As New System.IO.MemoryStream(thumbnailRaw)
Using br As New System.IO.BinaryReader(memStream)
Dim CF_METAFILEPICT As Integer = 3
Dim CF_ENHMETAFILE As Integer = 14
Dim clipboardFormatId As Integer = br.ReadInt32()
'int clipFormat =
Dim bytesRepresentMetafile As Boolean = (clipboardFormatId = CF_METAFILEPICT OrElse clipboardFormatId = CF_ENHMETAFILE)
Try
If bytesRepresentMetafile Then
' the bytes represent a clipboard metafile
' read past header information
br.ReadInt16()
br.ReadInt16()
br.ReadInt16()
br.ReadInt16()
Dim mf As New System.Drawing.Imaging.Metafile(br.BaseStream)
retImage = mf.GetThumbnailImage(width, height, New Image.GetThumbnailImageAbort(AddressOf getThumbnailImageAbort), IntPtr.Zero)
Else
' the bytes do not represent a metafile, try to convert to an Image
memStream.Seek(0, System.IO.SeekOrigin.Begin)
Dim im As Image = Image.FromStream(memStream, True, False)
retImage = im.GetThumbnailImage(width, height, New Image.GetThumbnailImageAbort(AddressOf getThumbnailImageAbort), IntPtr.Zero)
End If
Catch
End Try
End Using
End Using
retImage.Save("C:\Test.bmp")
Return retImage
End Function
Private Shared Function getThumbnailImageAbort() As Boolean
Return False
End Function
Hi,
Does the example in Doug's blog post help?
http://justonesandzeros.typepad.com/blog/2011/05/viewing-thumbnails.html
Thanks,
I am working on a vb.net program that can save thumbnails of all ipt and iam files in Vault to a local directory. I found VaultList from SDK can list all files and I can use it to extract the Thmbnail.
Like the OP from This Post, I also found the RenderThumbnailToImage (from http://justonesandzeros.typepad.com/blog/2012/05/thumbnail-optimization.html) function but seem unable to get it working.
How do I call this function from VaultList program?
'***********************
' get all the Files in the current Folder.
Dim childFiles As File() = connection.WebServiceManager.DocumentService.GetLatestFilesByFolderId(parentFolder.Id, False)
Dim myPropInst As PropInst
' print out any Files we find.
If childFiles IsNot Nothing AndAlso childFiles.Any() Then
For Each file As File In childFiles
' print the full path, which is Folder name + File name.
myPropInst = ??? 'how to set this value
Me.m_listBox.Items.Add((Convert.ToString(parentFolder.FullName) & "/") + file.Name)
RenderThumbnailToImage(myPropInst, 400, 400)
Next
End If
'***********************
Any help is much appreciated.
Hello,
Hope this helps: lFileId is ACW.File.Id
Autodesk.DataManagement.Client.Framework.Vault.Currency.Properties.PropertyDefinition thmbpropdef = _VaultConnection.PropertyManager.GetPropertyDefinitionBySystemName("Thumbnail"); ACW.PropInst[] pint = _VaultConnection.WebServiceManager.PropertyService.GetProperties("FILE", new long[] { lFileId }, new long[] { thmbpropdef.Id }); byte[] bits = pint[0].Val as byte[];
Thank you sfriedrich.
Since I did not get any reply earlier, I solved it using similar code found elsewhere. But there is a warning message "Warning 1 Variable 'nillvalue' is used before it has been assigned a value. A null reference exception could result at runtime. C:\Users\xxxx\Desktop\VaultList\Form1.vb 109 109 VaultList".
I have managed to pull all the thumbnails I wanted from vault. Posting this for the benefit of others and may be someone can suggest a better way.
Private Sub PrintFilesInFolder(parentFolder As VDF.Vault.Currency.Entities.Folder, connection As VDF.Vault.Currency.Connections.Connection) ' get all the Files in the current Folder. Dim m_conn As VDF.Vault.Currency.Connections.Connection = connection Dim childFiles As File() = connection.WebServiceManager.DocumentService.GetLatestFilesByFolderId(parentFolder.Id, False) Dim nillvalue As Autodesk.DataManagement.Client.Framework.Vault.Currency.Properties.PropertyValueSettings Dim props As Autodesk.DataManagement.Client.Framework.Vault.Currency.Properties.PropertyDefinitionDictionary = _ m_conn.PropertyManager.GetPropertyDefinitions(VDF.Vault.Currency.Entities.EntityClassIds.Files, Nothing, _ Autodesk.DataManagement.Client.Framework.Vault.Currency.Properties.PropertyDefinitionFilter.IncludeAll) Dim thumbnailPropDef As Autodesk.DataManagement.Client.Framework.Vault.Currency.Properties.PropertyDefinition = _ props(Autodesk.DataManagement.Client.Framework.Vault.Currency.Properties.PropertyDefinitionIds.Server.ThumbnailSystem) Dim thumbnailInfo As Autodesk.DataManagement.Client.Framework.Vault.Currency.Properties.ThumbnailInfo ' print out any Files we find. Dim fileIter As VDF.Vault.Currency.Entities.FileIteration = Nothing Me.m_listBox.Items.Add(Convert.ToString(parentFolder.FullName)) If childFiles IsNot Nothing AndAlso childFiles.Any() Then For Each file As File In childFiles If file.Name.Length - 4 = 8 Then 'filter for files with 8 letter file names If Strings.Right(file.Name, 3) = "ipt" Or Strings.Right(file.Name, 3) = "iam" Then ' Get the FileIteration fileIter = getFileIteration(file.Name, m_conn) thumbnailInfo = m_conn.PropertyManager.GetPropertyValue(fileIter, thumbnailPropDef, nillvalue) ' print the full path, which is Folder name + File name. 'Me.m_listBox.Items.Add((Convert.ToString(parentFolder.FullName) & "/") + file.Name) GetImage(thumbnailInfo.Image, 180, 180).Save("c:\temp\" & file.Name.Substring(0, file.Name.Length - 4) & ".png") End If End If Next End If ' check for any sub Folders. '....... End Sub Public Shared Function RenderThumbnailToImage(propInst As Byte(), width As Integer, height As Integer) As Image ' convert the property value to a byte array Dim thumbnailRaw As Byte() = propInst 'TryCast(propInst.Val, Byte()) '...... Return retImage End Function
I am a self-taught .Net programer. Please correct my code if you find any mistakes.