Anda di halaman 1dari 1

public static void PerpendicularLines()

{
Document doc = Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Editor ed = doc.Editor;
using (Transaction tr = db.TransactionManager.StartTransaction())
{
PromptEntityOptions op = new PromptEntityOptions("\nSelect polyl
ine :");
op.SetRejectMessage("Must be Polyline");
op.AddAllowedClass(typeof(Polyline), true);
op.AllowNone = false;
PromptEntityResult s = ed.GetEntity(op);
if (s.Status == PromptStatus.OK)
{
Polyline ent = (Polyline)tr.GetObject(s.ObjectId, OpenMode.F
orRead);
Line drawLine = new Line();
double length = ent.Length;
double gap = length / 15.0;
double dis = gap;
//int run = ((int)gap); <- this is wrong and unusefull
var curSpace = (BlockTableRecord)tr.GetObject(db.CurrentSpac
eId, OpenMode.ForWrite);
for (int i = 0; i < 14; i++)
{
Point3d p1 = ent.GetPointAtDist(dis);
Vector3d ang = ent.GetFirstDerivative(ent.GetParameterAt
Point(p1));
// scale the vector by 5.0 (so that it's 5 units length)
ang = ang.GetNormal() * 5.0;
// rotate the vector
ang = ang.TransformBy(Matrix3d.Rotation(Math.PI / 2.0, e
nt.Normal, Point3d.Origin));
// create a line by substracting and adding the vector t
o the point (displacing the point)
Line line = new Line(p1 - ang, p1 + ang);
curSpace.AppendEntity(line);
tr.AddNewlyCreatedDBObject(line, true);
dis = dis + gap;
}
}
tr.Commit();
}
}

Anda mungkin juga menyukai