Community
Navisworks API
Welcome to Autodesk’s Navisworks API Forums. Share your knowledge, ask questions, and explore popular Navisworks API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Save a viewpoint as a local jpg image with Redlines using NET API

4 REPLIES 4
SOLVED
Reply
Message 1 of 5
Gangula2
964 Views, 4 Replies

Save a viewpoint as a local jpg image with Redlines using NET API

Is there a way to use .NET API to save a savedviewpoint as a JPG image along with the redlines?

 

I was able to fid this link which refers to an article that talks about how to do it using COM API. Is the same possible using .NET API?

 

 

 

 

// COM API Code

[PluginAttribute("VPtoIMG",
//4 character Developer ID or GUID
"Gangula",
//The tooltip for the item in the ribbon
ToolTip = "Save viewpoint to jpg images",
//Display name for the Plugin in the Ribbon
DisplayName = "Viewpoint to IMG")]
public class SavedVP2IMG : AddInPlugin
{
// execute the plug-in command
public override int Execute(params string[] parameters)
{
    // export the saved viewpoints to images
    dumpSavedVP();
    return 0;
}

#region "produce images"
//locations to export the images
static string _snapshos_location = "c:\\temp\\";
// array of names of the saved viewpoints
List<string> _fileArray = new List<string>();

// export the saved viewpoints to images

private void dumpSavedVP()
{
    // get the active document
    Document oDoc = Autodesk.Navisworks.Api.Application.ActiveDocument;
    // get the state of COM
    ComApi.InwOpState10 oState = ComBridge.State;
    // get the IO plugin for image
    ComApi.InwOaPropertyVec options = oState.GetIOPluginOptions("lcodpimage");

    // configure the option "export.image.format"
    //to export png

    foreach (ComApi.InwOaProperty opt in options.Properties())
    {
        if (opt.name == "export.image.format")
            opt.value = "lcodpexpng";
        if (opt.name == "export.image.width")
            opt.value = 1600;
        if (opt.name == "export.image.height")
            opt.value = 900;
    }

    // swtich to the saved viewpoint
    foreach (SavedViewpoint oSVP in
        oDoc.SavedViewpoints.ToSavedItemCollection())
    {
        string svpName = oSVP.DisplayName;
        oDoc.SavedViewpoints.CurrentSavedViewpoint = oSVP;
        // set the current viewpoint  oDoc.SavedViewpoints.CurrentSavedViewpoint = oSVP; 
        // the image name
        string tempFileName = _snapshos_location + svpName + ".png";

        // delete the existing image if there is.
        if (System.IO.File.Exists(tempFileName))
            System.IO.File.Delete(tempFileName);
        try
        {
            //export the viewpoint to the image
            oState.DriveIOPlugin("lcodpimage", tempFileName, options);
            System.Drawing.Bitmap oBitmap = new System.Drawing.Bitmap(tempFileName);
            System.IO.MemoryStream ImageStream = new System.IO.MemoryStream();
            oBitmap.Save(ImageStream, System.Drawing.Imaging.ImageFormat.Jpeg);

            // add the image name to the list for use
            //of uploading to cloud
            _fileArray.Add(svpName);
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.ToString());
        }
    }
}
#endregion

 

 

 

Labels (2)
4 REPLIES 4
Message 2 of 5
naveen.kumar.t
in reply to: Gangula2

Hi @Gangula2 ,

 

Could you please take a look at the below link?

https://forums.autodesk.com/t5/navisworks-api/how-to-define-redlines-for-an-activeview-that-has-been... 

 


Naveen Kumar T
Developer Technical Services
Autodesk Developer Network

Message 3 of 5
Gangula2
in reply to: naveen.kumar.t

Thank you for sharing this Naveen.

The link you shared refers to COM API. can you please point me to  the answer you're referring to?

Message 4 of 5
naveen.kumar.t
in reply to: Gangula2

Hi @Gangula2 ,

 

Please take a look at this below sample code

public void ExportViewPointAsImage()
       {
            string path = @"....\ImageJpg.jpg";
            Autodesk.Navisworks.Api.View currentView = Application.ActiveDocument.ActiveView;
            Bitmap bmp = Application.ActiveDocument.ActiveView.GenerateImage(ImageGenerationStyle.ScenePlusOverlay, currentView.Width, currentView.Height);
            bmp.Save(path);
       } 

Get all the viewpoints and make each viewpoint as the current viewpoint(so that redlines will be visible in the view) and export the image

SavedViewpoint iteratedView = savedItem as SavedViewpoint;
SavedViewpoint current = Application.ActiveDocument.SavedViewpoints.CurrentSavedViewpoint as SavedViewpoint;
Application.ActiveDocument.SavedViewpoints.CurrentSavedViewpoint = iteratedView;

 


Naveen Kumar T
Developer Technical Services
Autodesk Developer Network

Message 5 of 5
Gangula2
in reply to: Gangula2

Thank you Naveen. That worked for me.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Rail Community


 

Autodesk Design & Make Report