I'm working on upgrading old VB6 code to vb .net (under visual studio 2012 & .net V4.0)
In VB6 I had a code that copied a draft view from Solid Edge, put it into PictureBox object, and then made a save to bmp.
I tried to do the same in vb .net, but for some strange reason the .net will not get the solid clipboard object into an image object:
Open SE draft, select a drawing view and do Copy, now run this code.
Private Sub Form1_load () Handles MyBase.Load
Dim bmp as Bitmap
bmp = Clipboard.GetImage
bmp = Ctype(Clipboard.GetImage, Bitmap)
bmp = Ctype(Clipboard.GetData(System.Windows.Forms.DataF
None of the bmp= lines work
What am I doing wrong?
After copying a view in SE Draft, I am able to Paste it to MS Paint so there is certainly some data on the clipboard, but,
Also, copying a shaded viewin draft, pastes a wireframe of it in MS Paint, so I doubt the format of the data on the Clipboard is in a usable format. The following is False too:
So data on the clipboard cannot be assigned to Bitmap even using CType.
I would suggest a workaround by first saving the view into a temporary image file and reading the file into the picture box as below:
oView.SaveAsImage(Path & "\Temp.bmp", 400, 300, , , , SolidEdgeConstants.SeImageQualityType.seImageQuali
PictureBox1.Image = System.Drawing.Image.FromFile(Path & "\Temp.bmp")
Later you can delete the temp file:
If System.IO.File.Exists(Path & "\Temp.bmp") Then
System.IO.File.Delete(Path & "\Temp.bmp")
Hope that was useful.
Meanwhile, if you find a solution to your original problem about "bmp = Nothing", kindly do post it here. Thanks.
Here's a solution if you do not want to use the temp file on disk method.
Create some views in Draft, place a PictureBox1 control on the Form and call the following from a Button Click:
Private Sub Button23_Click(sender As System.Object, e As System.EventArgs) Handles Button23.Click
Dim oApp As SolidEdgeFramework.Application = Marshal.GetActiveObject("SolidEdge.Application")
Dim oDoc As SolidEdgeDraft.DraftDocument = oApp.ActiveDocument Dim oSheet As SolidEdgeDraft.Sheet = oDoc.ActiveSheet Dim oViews As DrawingViews = oSheet.DrawingViews For Each oView As DrawingView In oSheet.DrawingViews oView.Copy() PictureBox1.Image = GetEnhMetafileOnClipboard(Me.Handle) MessageBox.Show("Click OK for next View.") Next
To use the GetEnhMetafileOnClipboard, add the code below anywhere within your Form Class in VB.Net:
Const CF_ENHMETAFILE As Integer = 14 <DllImport("user32.dll")> _ Private Shared Function OpenClipboard(ByVal hWndNewOwner As IntPtr) As Boolean End Function <DllImport("user32.dll")> _ Private Shared Function IsClipboardFormatAvailable(ByVal wFormat As Integer) As Integer End Function <DllImport("user32.dll")> _ Private Shared Function GetClipboardData(ByVal wFormat As Integer) As IntPtr End Function <DllImport("user32.dll")> _ Private Shared Function CloseClipboard() As Integer End Function Public Shared Function GetEnhMetafileOnClipboard(ByVal hWnd As IntPtr) As System.Drawing.Imaging.Metafile Dim meta As System.Drawing.Imaging.Metafile = Nothing If OpenClipboard(hWnd) Then Try If IsClipboardFormatAvailable(CF_ENHMETAFILE) <> 0 Then Dim hmeta As IntPtr = GetClipboardData(CF_ENHMETAFILE) meta = New System.Drawing.Imaging.Metafile(hmeta, True) End If Finally CloseClipboard() End Try End If Return meta End Function
Hope you find this useful.
Thanks, it works great!
But can you make it even better:
In the copyed image all the lines have the same line width.
If I make the copy into MS word the image has the correct line width for each line type.
Can this allso be done in VB?
I think it has hit a dead-end.
Solid Edge does copy line-width data to the metafile on the clipboard.
The picturebox control is not able to read it properly.
Not just the line-width, a shaded Solid Edge view pastes shaded in MS Word but not in the picturebox control. Only line data without line-width info gets pasted.
Original SE View:
Pasted in MS Word and scaled by dragging handles:
Same view in the picturebox:
So I think any further coding may not be of use or does not exist, nor the picturebox control has any property to display images any better.
The starnge thing is that the VB6
do get the image with the correct width for the body lines.
Well Microsoft always go two steps forword & one step back.