Get Plane from DatumPlane (Grid, Level or ReferencePlane)

Get Plane from DatumPlane (Grid, Level or ReferencePlane)

lvirone
Enthusiast Enthusiast
1,426 Views
4 Replies
Message 1 of 5

Get Plane from DatumPlane (Grid, Level or ReferencePlane)

lvirone
Enthusiast
Enthusiast

Hello,

 

DatumPlane is a class inherited by Grid, Level and ReferencePlane. Is it possible to get the plane referenced by the DatumPlane Object?

 

If it's not possible, is it possible to get the plane for Grid Object? For Level we can get the Level SketchPlane Plane, for the ReferencePlane there is a method GetPlane, but I saw nothing for Grid.

 

Thanks

0 Likes
Accepted solutions (1)
1,427 Views
4 Replies
Replies (4)
Message 2 of 5

jeremy_tammik
Alumni
Alumni

Afaict, it should be pretty straightforward for a Level element:

  

Use the Level.FindAssociatedPlanViewId method to obtain a plan view:

  

  

Use the View.SketchPlane property to access the sketch plane:

  

  

Does that work for you?

  

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
0 Likes
Message 3 of 5

lvirone
Enthusiast
Enthusiast

Hello @jeremy_tammik 

 

Yes for a Level it's easy because it's linked to a View which have a SketchPlane. The Level have the method "GetPlaneReference" BUT the Reference is a simple Reference, not a ReferencePlane even though the method to get it is called "GetPlaneReference".

 

The challenge is for Grid Elements. I achieve to create a ReferencePlane from a Grid like this:

 

doc.Create.NewReferencePlane(grid.Curve.GetEndPoint(0), grid.Curve.GetEndPoint(1), new XYZ(0,0,1), doc.ActiveView);

 

 

I use the Grid Line EndPoints, and the third parameter is the direction (which is always vertical for a Grid). It works only if the ActiveView is a 3D which see the Grid.

 

"DatumPlane" is the super class of Level, Grid and ReferencePlane but this Object doesn't seem to have enough geometric properties to make a Plane from it.

0 Likes
Message 4 of 5

Moustafa_K
Advisor
Advisor

Grid curves are 2D lines, the possibilities for extracting a plan is practically infinite. This is why your code snippet includes the third point XYZ.BasisZ. Similarly, when accessing to get curves from the DatumPlan class, a view is required as part of the method parameters. The documentation clarifies that the curves displayed are a reflection of the original, especially in elevation or section views. I am sure you read the below snippet, but placed it here for just in case of clarity. so what I can see from all this, the sketch plan of the view that shows the grid, is supposed to be the plan of the grid or the DatumPlan

 

A DatumPlane represents a 3d surface with finite extents. It can be either a
rectangle with arbitrary orientation, or a cylinder whose axis is parallel to
the project z-axis. If a datum is visible in a plan or section view, it will
be displayed as one or more curves. These curves are determined by the intersection
of the datum surface with the cut plane of the view. By default, the extents
of these curves reflect the 3d extents of the datum surface. If the surface is
a plane, then the extents represent the projection of the surface onto the cut
plane. This matters, for example, when viewing a datum plane, really a 3d rectangle,
along one of its diagonals. The extents of the curve do not vary with the location
of the view, because we use the projection of the rectangle and not the actual
intersection. If the surface is a cylinder, then the extents reflect the actual
intersection of the surface with the cut plane. In addition, the curves that
represent a DatumPlane can be modified on a view specific basis. In this case,
the ends of the curve no longer reflect the 3d extents of the datum.

 

I would be glad to know why you are seeking the plan of a grid or a datum in general

 

 

Moustafa Khalil
Cropped-Sharp-Bim-500x125-Autodesk-1
Message 5 of 5

lvirone
Enthusiast
Enthusiast
Accepted solution

Hello @Moustafa_K

 

Thank you for your clarification.

 

I'm using Grid and Level to cut elements like walls, floors or whatever geometry using BooleanOperationsUtils.CutWithHalfSpace method. So I want a ReferencePlane and not a Plane because ReferencePlane has the Flip method.

 

This method seems to work fine:

        public static ReferencePlane GetPlane(this DatumPlane datumPlane)
        {
            var doc = datumPlane.Document;

            if (datumPlane is Level level)
            {
                return doc.Create.NewReferencePlane(
                    new XYZ(0,1,level.Elevation), new XYZ(1, 0, level.Elevation), new XYZ(1, 1, 0), doc.ActiveView);
            }

            if (datumPlane is Grid grid)
            {
                return doc.Create.NewReferencePlane(
                    grid.Curve.GetEndPoint(0), grid.Curve.GetEndPoint(1), new XYZ(0,0,1), doc.ActiveView);
            }

            if (datumPlane is ReferencePlane referencePlane) return referencePlane;

            throw new InvalidCastException("Element must be Level, Grid or ReferencePlane");
        }
0 Likes