Converting slide to WMF / BMP format

By Balaji Ramamoorthy

Slides can be converted to WMF / BMP format which is often useful if you want to display it in a picturebox control. To do this conversion, the SlideLibrary COM object comes very handy.

This COM object is available for use after you have registered the slide.ocx from the AutoCAD Utilities.

To register the control, open the command prompt and type :

regsvr32 /c “C:Program FilesAutodeskADNUtilities2013_X64AutoCADControlsSlide.ocx”

Use of late-binding calls will avoid the need for any additional references in our project.

Here is a sample code in C# and VB.Net that makes late-bound calls to the SlideLibrary COM object :

1) C# code using the “InvokeMember” :

//using System.Reflection;
try
{
    const string progID = "AutoCAD.SlideLib";
 
    Type slideLibType = Type.GetTypeFromProgID(progID);
    object slidLibObj = Activator.CreateInstance(slideLibType, true);
 
    if (slidLibObj != null)
    {
        object[] dataArry1 = new object[1];
        dataArry1[0] = @"C:TempSolids.sld";
        slidLibObj.GetType().InvokeMember(
                                            "Append", 
                                            BindingFlags.InvokeMethod, 
                                            null, 
                                            slidLibObj, 
                                            dataArry1
                                         );
 
        object[] dataArry2 = new object[2];
 
        // Index to the slide in the slide library
        dataArry2[0] = 0;
        // Path of the bitmap to generate
        dataArry2[1] = @"C:TempMySlideImage.bmp"; 
 
        slidLibObj.GetType().InvokeMember(
                                            "SaveToBmp", 
                                            BindingFlags.InvokeMethod, 
                                            null, 
                                            slidLibObj, 
                                            dataArry2
                                         );
    }
}
catch (System.Exception ex)
{
    System.Windows.Forms.MessageBox.Show(ex.Message);
}

2) C# code using the “dynamic” keyword (available in .Net 4.0 onwards) :

// Using the .Net 4.0 dynamic keyword, it is easier 
// to make late-bound calls to COM objects
try
{
    const string progID = "AutoCAD.SlideLib";
    Type slideLibType = Type.GetTypeFromProgID(progID);
    dynamic slidLibObj = Activator.CreateInstance(slideLibType, true);
    slidLibObj.Append(@"C:TempSolids.sld");
    slidLibObj.SaveToBmp(0, @"C:TempMySlideImage.bmp");
}
catch (System.Exception ex)
{
    System.Windows.Forms.MessageBox.Show(ex.Message);
}

3) VB.Net code :

Try
Dim slb As Object
    slb = CreateObject("AutoCAD.SlideLib")
    slb.Append("C:TempSolids.sld")
    slb.SaveToBmp(0, "C:TempMySlideImage.bmp")
Catch ex As System.Exception
    System.Windows.Forms.MessageBox.Show(ex.Message)
End Try

The slidelibrary object also provides a method to convert it to a WMF format. For this, please use “SaveToWmf” instead of the “SaveToBmp” in the above code.


Comments

3 responses to “Converting slide to WMF / BMP format”

  1. I don’t know why, is the lib version changed or something else, but this line:
    const string progID = “AutoCAD.SlideLib”;
    should be changed to:
    const string progID = “AutoCAD.SlideLib.5”;

  2. Hi Eric,
    Thanks for mentioning this.
    You are right. I see that the 2013 version of the slide library has a progId “AutoCAD.SlideLib.5”.
    Regards,
    Balaji

  3. Hola
    Estoy usando autocad 2016, no funciona con AutoCAD.SlideLib.5 ni con AutoCAD.SlideLib

Leave a Reply to bieresCadCancel reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading