Message 1 of 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
is it possible to create Sectioning box (similar to GUI) by C# Code PlugIn?
Solved! Go to Solution.
is it possible to create Sectioning box (similar to GUI) by C# Code PlugIn?
Solved! Go to Solution.
Autodesk.Navisworks.Api.Application.ActiveDocument.ActiveView.SetClippingPlanes
Apply section box by GUI and you can see string of Json by GetClippingPlanes.
it Works!! thank you for suggestion,
public static void ApplyNavisworksClipping(double cloudX, double cloudY, double cloudZ, double cloudXLen, double cloudYLen, double cloudZLen)
{
try
{
// Use culture-invariant formatting to ensure decimal points are always periods
System.Globalization.CultureInfo invariantCulture = System.Globalization.CultureInfo.InvariantCulture;
// Calculate the box corners
double minX = cloudX - cloudXLen / 2;
double minY = cloudY - cloudYLen / 2;
double minZ = cloudZ - cloudZLen / 2;
double maxX = cloudX + cloudXLen / 2;
double maxY = cloudY + cloudYLen / 2;
double maxZ = cloudZ + cloudZLen / 2;
// Create JSON string for OrientedBox3D format
string jsonClipPlaneSet = $@"
{{
""Type"": ""ClipPlaneSet"",
""Version"": 1,
""OrientedBox"": {{
""Type"": ""OrientedBox3D"",
""Version"": 1,
""Box"": [
[{minX.ToString(invariantCulture)}, {minY.ToString(invariantCulture)}, {minZ.ToString(invariantCulture)}],
[{maxX.ToString(invariantCulture)}, {maxY.ToString(invariantCulture)}, {maxZ.ToString(invariantCulture)}]
],
""Rotation"": [0, 0, 0]
}},
""Enabled"": true
}}";
// Remove newlines and extra spaces for a more compact JSON
jsonClipPlaneSet = jsonClipPlaneSet.Replace("\r", "").Replace("\n", "").Replace(" ", "");
// Log coordinates for debugging
System.Diagnostics.Debug.WriteLine($"Center: ({cloudX}, {cloudY}, {cloudZ})");
System.Diagnostics.Debug.WriteLine($"Dimensions: ({cloudXLen}, {cloudYLen}, {cloudZLen})");
System.Diagnostics.Debug.WriteLine($"Box min: ({minX}, {minY}, {minZ})");
System.Diagnostics.Debug.WriteLine($"Box max: ({maxX}, {maxY}, {maxZ})");
// First try with TrySetClippingPlanes to avoid exceptions
bool success = Application.ActiveDocument.ActiveView.TrySetClippingPlanes(jsonClipPlaneSet);
if (!success)
{
System.Diagnostics.Debug.WriteLine("Failed to set clipping planes with TrySetClippingPlanes");
// Fall back to SetClippingPlanes which will throw an exception with more details if it fails
Application.ActiveDocument.ActiveView.SetClippingPlanes(jsonClipPlaneSet);
}
// Request a view update
Application.ActiveDocument.ActiveView.RequestDelayedRedraw(ViewRedrawRequests.All);
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine($"Error setting clipping planes: {ex.Message}");
// Uncomment for debugging in UI
// WF.MessageBox.Show($"Error setting clipping planes: {ex.Message}", "Error");
}
}