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
Solved! Go to Solution.
Solved by naveen.kumar.t. Go to Solution.
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?
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;
Can't find what you're looking for? Ask the community or share your knowledge.