Hi all.
Does anyone know how to use the
SwDMDocument10::GetPreviewBitmap and
SwDMDocument10::GetPreviewPNGBitmap
methods that are available with the Document manager?
I would like to use these to populate a picturebox.Image propertyin VB.Net Express 2008, but the returned value on these methods arenot 'image' objects... just 'Object'
How can I use these methods to populate a picturebox?
RegardsSolidworksApi macros
Does anyone know how to use the
SwDMDocument10::GetPreviewBitmap and
SwDMDocument10::GetPreviewPNGBitmap
methods that are available with the Document manager?
I would like to use these to populate a picturebox.Image propertyin VB.Net Express 2008, but the returned value on these methods arenot 'image' objects... just 'Object'
How can I use these methods to populate a picturebox?
RegardsSolidworksApi macros

Imports System.Windows.Forms
Imports SwDocumentMgr.SwDmDocumentType
Imports SwDocumentMgr.SwDmDocumentOpenError
Imports SwConst
Imports System.Drawing
Public Class Form1
Const swDMLicenseKey = "GETYOUROWNCODEYOUCANTHAVEMINE"
' Activate part or Drawing alternatively for testing:
'Const sDocFileName As String = "c:\870150.SLDPRT"
Const sDocFileName As String = "c:\870150.SLDDRW"
Dim nDocType As Integer
Dim swClassFact As SwDocumentMgr.SwDMClassFactory
Dim swDocMgr As SwDocumentMgr.SwDMApplication
Dim swDoc As SwDocumentMgr.SwDMDocument
Dim swDoc11 As SwDocumentMgr.SwDMDocument11
Dim swCfgMgr As SwDocumentMgr.SwDMConfigurationMgr
Dim swCfg As SwDocumentMgr.SwDMConfiguration7
Dim iRetVal As Integer
Dim oMyAxHost As NewmyAxHost("00AB5D8D-2B8F-416b-9761-92FACC8872BE") 'swdocumentmgr.dll CLSID
Dim oPreview As Object
Dim oCfgNameArr As Object
Dim sCfgName As String
Dim oByteArray() As Byte
Dim oStream As New System.IO.MemoryStream
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e AsSystem.EventArgs) Handles MyBase.Load
If InStr(LCase(sDocFileName), "sldprt") > 0 Then
nDocType = swDmDocumentPart
ElseIf InStr(LCase(sDocFileName), "sldasm") > 0 Then
nDocType = swDmDocumentAssembly
ElseIf InStr(LCase(sDocFileName), "slddrw") > 0 Then
nDocType = swDmDocumentDrawing
Else
nDocType = swDmDocumentUnknown
MsgBox("Keine Solidworksdatei...")
End
End If
lbConfigurations.Items.Clear()
swClassFact = CreateObject("SwDocumentMgr.SwDMClassFactory")
swDocMgr = swClassFact.GetApplication(swDMLicenseKey)
swDoc11 = swDocMgr.GetDocument(sDocFileName, nDocType, True,iRetVal)
swDoc = swDocMgr.GetDocument(sDocFileName, nDocType, True,iRetVal)
Debug.Print("File = " & swDoc.FullName)
If nDocType = swDmDocumentDrawing Then
oByteArray = swDoc11.GetPreviewBitmapBytes(iRetVal)
oStream.Write(oByteArray, 0, oByteArray.Length)
pbPreview.Image = System.Drawing.Image.FromStream(oStream)
Else
swCfgMgr = swDoc.ConfigurationManager
oCfgNameArr = swCfgMgr.GetConfigurationNames
For Each Me.sCfgName In oCfgNameArr
swCfg = swCfgMgr.GetConfigurationByName(sCfgName)
lbConfigurations.Items.Add(sCfgName)
Next
End If
End Sub
Sub ShowConfigurationPreview(ByVal sConfig As String)
If nDocType = swDmDocumentDrawing Then Exit Sub
swCfg = swCfgMgr.GetConfigurationByName(sConfig)
oPreview = swCfg.GetPreviewBitmap(iRetVal)
pbPreview.Image = oMyAxHost.GetImage(oPreview)
Debug.Print("ShowConfigurationPreview(" & sConfig & ")")
End Sub
Private Sub lbConfigurations_SelectedIndexChanged(ByVal sender AsSystem.Object, ByVal e As System.EventArgs) HandleslbConfigurations.SelectedIndexChanged
Dim sDummy As String
sDummy = lbConfigurations.SelectedItem
ShowConfigurationPreview(sDummy)
End Sub
Private Sub btnExit_Click(ByVal sender As System.Object, ByVal eAs System.EventArgs) Handles btnExit.Click
swDoc.CloseDoc()
End
End Sub
Private Sub lbConfigurations_SelectedIndexChanged_1(ByVal senderAs System.Object, ByVal e As System.EventArgs)
Dim sDummy As String
sDummy = lbConfigurations.SelectedItem
ShowConfigurationPreview(sDummy)
End Sub
End Class
http://forum.solidworks.com/fo...ord1=getpreviewbitmap
http://forum.solidworks.com/fo...ord1=getpreviewbitmap
Why didn't I just ask on this forum earlier.... ai yaiyai....
@Josh. I was looking for a way to get thumbnails without usingsolidworks. Thanks for the reply anyway.
<p><span style="font-size: 8pt;">2636 wrote:</span></p><p><span style="font-size: 8pt;"><br></span></p><span style="font-size: 8pt;">Here is the VB.NET code I used. I was just messing around to see if I could get it to work. I found a code sample somewhere and modified it to what you see here. <br><br>Imports System.Windows.Forms <br>Imports SwDocumentMgr.SwDmDocumentType <br>Imports SwDocumentMgr.SwDmDocumentOpenError <br>Imports SwConst <br>Imports System.Drawing <br>Public Class Form1 <br></span><br><strong>Dim oMyAxHost As New myAxHost("00AB5D8D-2B8F-416b-9761-92FACC8872BE") ' swdocumentmgr.dll CLSID <br></strong><span style="font-size: 8pt;">If nDocType = swDmDocumentDrawing Then <br>oByteArray = swDoc11.GetPreviewBitmapBytes(iRetVal) <br>oStream.Write(oByteArray, 0, oByteArray.Length) <br>pbPreview.Image = System.Drawing.Image.FromStream(oStream) <br>Else <br>swCfgMgr = swDoc.ConfigurationManager <br>oCfgNameArr = swCfgMgr.GetConfigurationNames <br>For Each Me.sCfgName In oCfgNameArr <br>swCfg = swCfgMgr.GetConfigurationByName(sCfgName) <br>lbConfigurations.Items.Add(sCfgName) <br>Next <br>End If <br>End Sub</span> <br><br>Sub ShowConfigurationPreview(ByVal sConfig As String) <br><span style="font-size: 8pt;">If nDocType = swDmDocumentDrawing Then Exit Sub <br>swCfg = swCfgMgr.GetConfigurationByName(sConfig) <br>oPreview = swCfg.GetPreviewBitmap(iRetVal)</span> <br><strong>pbPreview.Image = oMyAxHost.GetImage(oPreview)</strong> <br><span style="font-size: 8pt;">Debug.Print("ShowConfigurationPreview(" & sConfig & ")")</span> <br>End Sub <br><br>Sorry to bring this post back up from the dead. I stumbled on this and it appear to be exactly what i'm looking for.... However I'm having trouble finding the code for the myAxHost Class. If someone could help me out there that would be great
There is a good way to get a thumbnail image
Public Function pv(ByVal file As String) As System.Drawing.Bitmap
Dim pvf As wpfPreviewFlowControl.wpfThumbnailCreator
pvf = New wpfPreviewFlowControl.wpfThumbnailCreator()
Dim size As System.Drawing.Size
size.Width = 200 ' SIZE OF PREVIEW
size.Height = 200 ' SIZE OF PREVIEW
pvf.DesiredSize = Size
Return pvf.GetThumbNail(file)
End Function
'add reference C:\Program Files (x86)\SolidWorks\SolidWorks Explorer 20xx\wpfPreviewFlowControl.dll
Public Class MyAxHost
Inherits System.Windows.Forms.AxHost
Public Sub New(ByVal clsid As String)
MyBase.New(clsid)
End Sub
Public ReadOnly Property GetImage(ByVal oSwImage As Object) As Image
Get
Return AxHost.GetPictureFromIPicture(oSwImage)
End Get
End Property
End Class
Perfect!
Thanks