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?