What's new

ADSession.PreviewSnapshot

alexfranke

Senior Member
ADSession.PreviewSnapshot

Can you give us some insight on ADSession.PreviewSnapshot? e.g. What it is and how to use it.

Thanks
Alex
 


Hi Alex and Clint,

Sorry for the late reply.

IADSession.PreviewSnapshot gives you back the snapshot of the session in form of an OLE picture. If you are using it in VB follwoing is the simple code snippet for its use:

To draw a OLE picture into a VB image control:


Dim picture As IUnknown

Set picture = objWorkspace.PreviewSnapshot

Set Image1.picture = picture '''' where Image1 is a image control on the VB form.


If you would like to use it in C++ you will need to get the IPicturePtr from IUnknown first and then get the image handle from it. Following is code snippet for that.

HBITMAP hBmp;


// Get the OLE picture object's handle

if(pPic){

pPic->get_Handle((OLE_HANDLE*)&hBmp);

}

Let me know if that answers your question.

Thanks,
Chaitanya
 

jkohlhoff

New Member
IADSession.PreviewSnapshot

Has anyone been able to get IADSession.PreviewSnapshot to work without throwing an exception? I'm running Alibre Design 10, and writing a program in C#.

Accessing the IADSession.PreviewSnapshot throws the following exception -

System.Runtime.InteropServices.COMException was unhandled
Message="Catastrophic failure (Exception from HRESULT: 0x8000FFFF (E_UNEXPECTED))"
Source="Interop.AlibreX"
ErrorCode=-2147418113
StackTrace:
at AlibreX.IADSession.get_PreviewSnapshot()
at AlibreSnapshot.AlibreSnapshot.getPreviewSnapshot() in C:\\Users\\...


The following C# code reproduces the error -

AutomationHook hook;
IADRoot root;
IADSessions sessions;
IADSession session;
object oPicture;

//hook = (AutomationHook)Marshal.GetActiveObject("AlibreX.AutomationHook");
hook = new AlibreX.AutomationHook();
hook.Initialize("", "", "", true, 0);

root = (IADRoot)adHook.Root;
root.OpenFile(@"C:\\temp\\8020-1515-Model.ad_prt");
sessions = root.Sessions;
session = sessions.Item(0);

oPicture = session.PreviewSnapshot;


Thanks,
 
Top