How to get the grid intersection point point?

How to get the grid intersection point point?

Anonymous
Not applicable
3,520 Views
4 Replies
Message 1 of 5

How to get the grid intersection point point?

Anonymous
Not applicable

Hi ! 

There is a way to get the  intersection points about grids?

I wanna put columns on the intersection points!

But they are so many. 

So if you know an easy way to get all intersection points, plz explain that..!

Or I have to calculate points? 

 

0 Likes
3,521 Views
4 Replies
Replies (4)
Message 2 of 5

naveen.kumar.t
Autodesk Support
Autodesk Support

hi @Anonymous ,

This below code will help you to find intersection point

Grid g1;
Curve c1 = g1.Curve;

Grid g2;
Curve c2 = g2.Curve;

private XYZ Intersection(Curve c1,Curve c2) { XYZ p1 = c1.GetEndPoint(0); XYZ q1 = c1.GetEndPoint(1); XYZ p2 = c2.GetEndPoint(0); XYZ q2 = c2.GetEndPoint(1); XYZ v1 = q1 - p1; XYZ v2 = q2 - p2; XYZ w = p2 - p1; double c = (v2.X * w.Y - v2.Y * w.X) / (v2.X * v1.Y - v2.Y * v1.X); double x = p1.X + c * v1.X; double y = p1.Y + c * v1.Y; XYZ p5 = new XYZ(x, y, 0); return p5; }

Naveen Kumar T
Developer Technical Services
Autodesk Developer Network

0 Likes
Message 3 of 5

Anonymous
Not applicable
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            //Get UIDocument
            UIDocument uidoc = commandData.Application.ActiveUIDocument;

            //Get Document
            Document doc = uidoc.Document;

            try
            {
                using (Transaction trans = new Transaction(doc, "Place Family"))
                {
                    trans.Start();

                    XYZ p1 = new XYZ(0, 0, 0);
                    XYZ p2 = new XYZ(30, 0, 0);
                    XYZ p3 = new XYZ(15, 15, 0);
                    XYZ p4 = new XYZ(15, -15, 0);

                    Line line1 = Line.CreateBound(p1, p2);
                    Line line2 = Line.CreateBound(p2, p3);
                    Grid g1 = Grid.Create(doc, line1);
                    Grid g2 = Grid.Create(doc, line2);

                   
                    Curve c1 = g1.Curve;
                    Curve c2 = g2.Curve;

                    XYZ aa = new XYZ();
                    aa= Intersection(c1, c2);





                    trans.Commit();

                    return Result.Succeeded;
                }

            }
            catch (Exception e)
            {
                message = e.Message;
                return Result.Failed;
            }

        }


        private XYZ Intersection(Curve c1, Curve c2)
        {
            XYZ p1 = c1.GetEndPoint(0);
            XYZ q1 = c1.GetEndPoint(1);
            XYZ p2 = c2.GetEndPoint(0);
            XYZ q2 = c2.GetEndPoint(1);

            //벽의 길이
            XYZ v1 = q1 - p1;
            XYZ v2 = q2 - p2;


            XYZ w = p2 - p1;

            double c = (v2.X * w.Y - v2.Y * w.X)
              / (v2.X * v1.Y - v2.Y * v1.X);

            double x = p1.X + c * v1.X;
            double y = p1.Y + c * v1.Y;

            XYZ p5 = new XYZ(x, y, 0);

            return p5;
        }

I runed your code like this. However there's an error massage saying "Object reference not set to an instance of an object." 

What's wrong?

0 Likes
Message 4 of 5

naveen.kumar.t
Autodesk Support
Autodesk Support

Hi @Anonymous ,

are you sure you want to draw a grid line between p1 and p2 and a second line between p2 and p3?

Or you want to draw a grid line between p1 and p2 and a second line between p3 and p4?

 

 


Naveen Kumar T
Developer Technical Services
Autodesk Developer Network

0 Likes
Message 5 of 5

naveen.kumar.t
Autodesk Support
Autodesk Support

Hi @Anonymous ,

Grid elements are created in the document only after the transaction gets completed.

Here the error occurs because you are trying to get the grid element points before the transaction gets completed.

So 

1)Create transaction

2)create Grid elements

3)commit the transaction

4)Create second transaction

5)get the Grid Intersection Points

6)commit the second transaction.

 

If this helped solve your problem please mark it as solution, so other users can get this solutions as wellSmiley Happy


Naveen Kumar T
Developer Technical Services
Autodesk Developer Network

0 Likes