Showing posts with label autocad. Show all posts
Showing posts with label autocad. Show all posts

Thursday, October 15, 2009

Get 3D Polyline Vertices in AutoCAD .Net


using AcadApp = Autodesk.AutoCAD.ApplicationServices.Application;

public void Get3DPolylinesVertices()

{

Document doc = AcadApp.DocumentManager.MdiActiveDocument;

Database db = doc.Database;

Transaction tr = db.TransactionManager.StartTransaction();

using (tr)

{

BlockTable bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead);

BlockTableRecord btr = (BlockTableRecord)tr.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite);

foreach (ObjectId id in btr)

{

Entity ent = (Entity) tr.GetObject(id, OpenMode.ForRead);

if (ent is Polyline3d)

{

Polyline3d polyline3d = ent as Polyline3d;

foreach (ObjectId vertexId in polyline3d)

{

PolylineVertex3d vertex3d =

(PolylineVertex3d)tr.GetObject(vertexId, Autodesk.AutoCAD.DatabaseServices.OpenMode.ForRead);

vertex3d.Position // This is one vertices of 3d polyline...

}

}

}

tr.Commit();

}

}

Angle between 2 points in AutoCAD .Net

public static double AngleFromXY(Point3d pt1, Point3d pt2, Editor ed)

{

Matrix3d ucsmtx = ed.CurrentUserCoordinateSystem;

CoordinateSystem3d ucs = ucsmtx.CoordinateSystem3d;

Plane ucsplane = new Plane(ucs.Origin, ucs.Xaxis, ucs.Yaxis);

Vector3d vec = pt2 - pt1;

double ang = vec.AngleOnPlane(ucsplane);

return ang;

}