Hello everyone,
I'm using Navisworks 2014 and I'm trying to create a plugin to add to a specific/selected object the closest grid intersection point in a property user tab.
Although I know how to create the user tab and add properties pragmatically, I cannot find a reference to retrieve the closest grid intersection point. This should basically be what the clash detective "Grid Intersection" shows.
Should I use the "GridIntersection Class" to do this? And if so, where should I start?
Thanks!
Solved! Go to Solution.
Solved by xiaodong_liang. Go to Solution.
Xiaodong,
I'm having a hard time getting the intersection point data I can add to the user tab:
This is what I have:
static public Point3D GetClosestGridIntersection() { //check that selection is valid if (!Autodesk.Navisworks.Api.Application.ActiveDocument.CurrentSelection.IsEmpty) { //Get bounding box of the selection BoundingBox3D bb3d = Autodesk.Navisworks.Api.Application.ActiveDocument.CurrentSelection.SelectedItems.BoundingBox(); //get the closest grid intersection point GridIntersection oGridIntersection = Autodesk.Navisworks.Api.GridSystem.ClosestIntersection(bb3d.Center); } //return the vector return oGridIntersection; }
I would then buidl the string I need to put in th euser tab property.
I get the following error message:
"Error 5 An object reference is required for the non-static field, method, or property 'Autodesk.Navisworks.Api.GridSystem.ClosestIntersection(Autodesk.Navisworks.Api.Point3D)'"
I'm new to C#... can someone let me know what I'm missing?
Thanks,
The GridSystem class does not provide a static method to get the closest point. You need to get the current grid system and call ClosestIntersection. The following is the updated code:
static public Point3D GetClosestGridIntersection() { GridIntersection oGridIntersection = null; ; //check that selection is valid if (!Autodesk.Navisworks.Api.Application.ActiveDocument.CurrentSelection.IsEmpty) { //Get bounding box of the selection BoundingBox3D bb3d = Autodesk.Navisworks.Api.Application.ActiveDocument.CurrentSelection.SelectedItems.BoundingBox(); GridSystem oGS = Autodesk.Navisworks.Api.Application.ActiveDocument.Grids.ActiveSystem; //get the closest grid intersection point oGridIntersection = oGS.ClosestIntersection(bb3d.Center); } //return the vector return oGridIntersection.Position; }
I wrote a blog with the demo:
http://adndevblog.typepad.com/aec/2014/01/closest-grid-point-intersection-to-an-object.html