Check if Sectioning is enabled

Check if Sectioning is enabled

Anonymous
Not applicable
2,121 Views
10 Replies
Message 1 of 11

Check if Sectioning is enabled

Anonymous
Not applicable

Hi all,

 

Is it possible to check if Sectioning is enabled from .NET API?

 

I tried fetching window handle of Sectioning Tools tab in order to check if it is enabled but I did not have any success.

 

Looking forward to your answers.

 

Kind Regards,

Nikola

0 Likes
Accepted solutions (1)
2,122 Views
10 Replies
Replies (10)
Message 2 of 11

jmlovelace
Enthusiast
Enthusiast
I did some digging on this because I needed to know this as well. If you call ActiveView.GetClippingPlanes() a JSON string is returned. Each plane in the set has an Enabled property, so you can check them this way plane-by-plane. You can also check the planes through the COM API, but this way didn't work for me because it counted even the planes that were disabled.
0 Likes
Message 3 of 11

jmlovelace
Enthusiast
Enthusiast
EDIT: After further checking even this method is inconsistent. I turned some planes on and off and the JSON object does not change. Strange...
0 Likes
Message 4 of 11

Anonymous
Not applicable
I have encountered same issues as you. JSON object is not returning consistent results. When you try to do same thing through COM API you will get the same inconsistent results.
0 Likes
Message 5 of 11

jmlovelace
Enthusiast
Enthusiast
I think I figured it out. The Enabled property of the JSON object is in fact reading correct...I had a bug in my code. You have to go by the Enabled property on each plane object, not the number of planes in the array. It looks like Navisworks is generating plane objects as needed when they are activated in the UI, but they don't disappear when deactivated - the Enabled property just gets set to false.
0 Likes
Message 6 of 11

Anonymous
Not applicable
Can you please post a snippet of code?
0 Likes
Message 7 of 11

jmlovelace
Enthusiast
Enthusiast
My code is being used to prepare a url string of section parameters but this is the gist. Requires Json.NET string sectiondata = ActiveDoc.ActiveView.GetClippingPlanes(); dynamic parsedSection = JsonConvert.DeserializeObject(sectiondata); string sectionURLdata = "["; List planeNums = new List(); if (parsedSection.Planes.Count > 0) { foreach (var plane in parsedSection.Planes) { if (plane.Enabled.Value == true) { planeNums.Add(plane.Normal[0].Value.ToString()); planeNums.Add(plane.Normal[1].Value.ToString()); planeNums.Add(plane.Normal[2].Value.ToString()); planeNums.Add(plane.Distance.Value.ToString()); } } } if (planeNums.Any()) { sectionURLdata += String.Join(",", planeNums); } sectionURLdata += "]";
0 Likes
Message 8 of 11

Anonymous
Not applicable
I managed to implement solution. Here is the complete snippet that can be used, it is implemented using JavaScriptSerializer, so no third party libraries are required. using System.Web.Script.Serialization; // add System.Web.Extensions reference to project private class ClipPlanes { public bool Enabled { get; set; } } private static bool IsSectioningEnabled() { var serializer = new JavaScriptSerializer(); string clippingPlanesJson = Autodesk.Navisworks.Api.Application.ActiveDocument.ActiveView.GetClippingPlanes(); var clippingPlanesParsed = serializer.Deserialize(clippingPlanesJson); return clippingPlanesParsed.Enabled; }
0 Likes
Message 9 of 11

Anonymous
Not applicable
Accepted solution
I managed to implement solution. Here is the complete snippet that can be used, it is implemented using JavaScriptSerializer, so no third party libraries are required.
using System.Web.Script.Serialization; // add System.Web.Extensions reference to project 
private class ClipPlanes 
{ 
    public bool Enabled { get; set; } 
} 

private static bool IsSectioningEnabled()
 { 
    var serializer = new JavaScriptSerializer(); string clippingPlanesJson = Autodesk.Navisworks.Api.Application.ActiveDocument.ActiveView.GetClippingPlanes(); 
    var clippingPlanesParsed = serializer.Deserialize(clippingPlanesJson); 
    return clippingPlanesParsed.Enabled; 
}
Message 10 of 11

Anonymous
Not applicable

Hello ngrujic ,

 

Wonder if you could help me. I am trying to use your code as it is. However, I am getting an issue with this line:

 

var clippingPlanesParsed = serializer.Deserialize(stringJson);

It keeps giving me the following error:

"The type arguments for method 'JavaScriptSerializer.Deserialize<T>(string)' cannot be inferred from the usage. Try specifying the type arguments explicitly."

 

The only way I can pass that line is by providing the method with a type in the following way:

 

object clippingPlanesParsed = serializer.Deserialize<object>(stringJson);

The problem is that now I have an "object" type and it won't take the parameter ".Enable" from the next line.

 

Any chance you found the same? And if so, could you shed me a light?

 

Thanks.  

 

 

 

 

0 Likes
Message 11 of 11

alexisDVJML
Collaborator
Collaborator

Avoid the JSON route: inefficient, undocumented format.

 

Go direct to the LcOaClipPlaneSet clipping object:

var cps = NavisworksApp.ActiveDocument.State.GetCurrentClipPlaneSet();
bool enabled = cps.IsEnabled();
Main Scientist, Full Stack Developer & When Time Permits Director of IDIGO ► On your marks, Set, Go
0 Likes