Get curve from Reference Plane

Get curve from Reference Plane

diogo.vieiraBCKUL
Contributor Contributor
1,649 Views
9 Replies
Message 1 of 10

Get curve from Reference Plane

diogo.vieiraBCKUL
Contributor
Contributor

I would like to get the curve from a selected Reference Plane, but it isn't working. Could anyone help?
My code:

 

		public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
		{
			UIApplication uiapp = commandData.Application;
			UIDocument uidoc = uiapp.ActiveUIDocument;
			Document doc = uidoc.Document;

			Reference reference=pickGridsExtent(uidoc);

			var refPlane = doc.GetElement(reference.ElementId) as ReferencePlane;
			Curve refCurve = refPlane.Curve;

			return Result.Succeeded; 
		}

Code from pickGridsExtent(uidoc):

		public Reference pickGridsExtent(UIDocument uidoc)
		{
			ISelectionFilter selFilter = new SelectionFilter.SelFilterRefPlane(); //Selection Filter of Reference Planes
			Reference reference = uidoc.Selection.PickObject(ObjectType.Element, selFilter);

			return reference;
		}

 

1,650 Views
9 Replies
Replies (9)
Message 2 of 10

Omar_Amen
Advocate
Advocate

Hi @diogo.vieiraBCKUL,
a fast simple way I use when I want to get any elements (childs) that depends on another element (parent) is:
doc.Delete(ElementId parantID ); 
it returns a list of deleted elements (parant + childs), I call it inside a transaction then after retrieve and store the list of deleted elements, I rollback the transaction
may you give it a try, it may help!

0 Likes
Message 3 of 10

diogo.vieiraBCKUL
Contributor
Contributor
Uhm, I only want to get a curve from a Reference Plane...
0 Likes
Message 4 of 10

jeremy_tammik
Alumni
Alumni

What curve are you expecting to get?

 

You can place any number of curves in a reference plane.

 

Furthermore, I see no method or property named `Curve` on the ReferencePlane class, so I do not see how you can compile your sample code snippet, or what you expect that statement to return.

  

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

Omar_Amen
Advocate
Advocate

Dear @diogo.vieiraBCKUL ,
I snooped a reference plane using Revit lookup Add-in and found those 2 points of the referencePlane curve

rp.png


so you can get the 2 points and if you need a curve you may create a line-curve using the points
try this code : 

            public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
            {
                UIApplication uiapp = commandData.Application;
                UIDocument uidoc = uiapp.ActiveUIDocument;
                Document doc = uidoc.Document;

                Reference reference = pickGridsExtent(uidoc);

                var refPlane = doc.GetElement(reference.ElementId) as ReferencePlane;
                XYZ sp = refPlane.BubbleEnd;
                XYZ ep = refPlane.FreeEnd;
                Curve c = Line.CreateBound(sp, ep) as Curve;

                return Result.Succeeded;
            }



0 Likes
Message 6 of 10

diogo.vieiraBCKUL
Contributor
Contributor
I would like to transform Reference Plane into a curve or at least, make it assum Curve properties, so I could use SetCurveInView.
0 Likes
Message 7 of 10

Omar_Amen
Advocate
Advocate

Hi Jeremy, I think he means the curve of creation of the reference plane!

0 Likes
Message 8 of 10

diogo.vieiraBCKUL
Contributor
Contributor

Thank you for replying, I ended up using your code, like this:

			UIApplication uiapp = commandData.Application;
			UIDocument uidoc = uiapp.ActiveUIDocument;
			Document doc = uidoc.Document;

			Reference reference=pickGridsExtent(uidoc);

			IList<Reference> rList = pickDesiredGrids(uidoc);
			var refPlane = doc.GetElement(reference.ElementId) as ReferencePlane;
			XYZ sp = refPlane.BubbleEnd;
			XYZ ep = refPlane.FreeEnd;
			Curve c = Line.CreateBound(sp, ep);

			using (Transaction trans = new Transaction(doc, "Move Bubbles"))
			{
				trans.Start();

				foreach (var item in rList)
				{
					var grid = doc.GetElement(item.ElementId) as Grid;

					grid.SetCurveInView(DatumExtentType.ViewSpecific, doc.ActiveView, c);
				}

				trans.Commit();
			}

And I get this error:

diogovieiraBCKUL_0-1633349694502.png

Thank you once again @Omar_Amen.

0 Likes
Message 9 of 10

Omar_Amen
Advocate
Advocate

Dear @diogo.vieiraBCKUL ,
I've just tried it on a sample file and it gives the same error even with the original grid curve!
I made some search for this exception error and found some topic that had a solution for it, may you check the links:
-https://forums.autodesk.com/t5/revit-api-forum/grids-off-axis/td-p/7129065 
-https://forum.dynamobim.com/t/grid-extents-alignment-based-on-crop-region/55538 
I hope that will help!

0 Likes
Message 10 of 10

guillain.jolivet
Contributor
Contributor

I'm using something like this to create a detail line from curve from a reference plan

 

public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
    UIApplication uiapp = commandData.Application;
    UIDocument uidoc = uiapp.ActiveUIDocument;
    Document doc = uidoc.Document;

    // Get the reference
    Reference reference = pickGridsExtent(uidoc);

    // Get the plane from reference
    Plane plan = SketchPlane.Create(doc, reference).GetPlane();

    // Get the curve from the plane
    Curve curve = Line.CreateBound(plan.Origin, plan.Origin + 1*plan.XVec); // (or plan.YVec)

    // Create detail line in the model
    DetailCurve line = doc.Create.NewDetailCurve(doc.ActiveView, curve);
    return Result.Succeeded;
}