Modifying Viewport AlignDirection and AlignUp
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello,
I need to modify some settings for a nwd file.
First I tried to set AlignDirection, AlignUp and Position of a viewport.
Changing any of these properties results in a "System.NotSupportedException: 'Object is Read-Only'" error
Do I have to copy the current active one, modify the values and replace the existing one?
Attached is the error which is shown in Visual Studio
Here is my code
namespace NavisworksPlugin
{
[PluginAttribute("TestPlugin", //Plugin name
"ADSK", //4 character Developer ID or GUID
ToolTip = "TestPlugin tool tip",//The tooltip for the item in the ribbon
DisplayName = "TestPlugin")] //Display name for the Plugin in the Ribbon
public class TestPlugin : AddInPlugin //Derives from AddInPlugin
{
public override int Execute(params string[] parameters)
{
return SetOrientation(100, 200, 300, 0.0, 0.0, -1.0, 0.0, 1.0, 0.0);
}
public int SetOrientation(double x, double y, double z, double forwardX, double forwardY, double forwardZ, double upX, double upY, double upZ)
{
try
{
Document doc = Autodesk.Navisworks.Api.Application.ActiveDocument;
Viewpoint viewpoint = doc.CurrentViewpoint.Value;
viewpoint.Position = new Point3D(x, y, z);
viewpoint.AlignDirection(new Vector3D(forwardX, forwardY, forwardZ));
viewpoint.AlignUp(new Vector3D(upX, upY, upZ));
}
catch (Exception ex)
{
ShowMessageBox(ex.Message);
}
return 0;
}
private int ShowMessageBox(string message)
{
MessageBox.Show(Autodesk.Navisworks.Api.Application.Gui.MainWindow, message);
return 0;
}
}
}