Hello,
I got this source code here
This code is create in C#, I don't have an experience in C# so, Can anyone help me how to make this in vb.net?
It will be really helpful to finish my task.
Code:
// Get the geometry from a dimension entity
// translated on C# from article by Augusto Goncalves:
// http://adndevblog.typepad.com/autocad/2013/01/get-the-geometry-from-a-dimension-entity.html
[CommandMethod("dgeom", CommandFlags.UsePickSet)]
public void GetDimensionLinesData()
{
Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
Editor ed = doc.Editor;
Database db = doc.Database;
Transaction tr = doc.TransactionManager.StartOpenCloseTransaction();
using (tr)
{
Dimension diment = null;
PromptEntityOptions peo = new PromptEntityOptions("\nSelect a Dimension>>");
peo.SetRejectMessage("\nSelect Dimension only >>");
peo.AddAllowedClass(typeof(Dimension), false);
PromptEntityResult res;
res = ed.GetEntity(peo);
if (res.Status != PromptStatus.OK)
return;
Entity ent = (Entity)tr.GetObject(res.ObjectId, OpenMode.ForRead);
if (ent == null)
return;
diment = (Dimension)ent as Dimension;
if (diment == null)
{
ed.WriteMessage("\nError: selected entity is not a Dimension");
return;
}
//get current space
BlockTableRecord btr = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
//get dimension block definition
BlockTableRecord dimbtr = tr.GetObject(diment.DimBlockId, OpenMode.ForRead) as BlockTableRecord;
MessageBox.Show(dimbtr.Name);
BlockTableRecordEnumerator iter = dimbtr.GetEnumerator();
Entity obj;
// Iterate every entity stored in the
// block definition of the dimension.
while (iter.MoveNext())
{
obj = tr.GetObject((ObjectId)iter.Current, OpenMode.ForRead) as Entity;
Line ln = obj as Line;
if (ln != null)
{
// Get the start and end point.
Point3d sp, ep;
sp = ln.StartPoint;
ep = ln.EndPoint;
// // Transform the start and end point.
// // Get the transformation matrix.
Matrix3d mat = new Matrix3d();
// Get the axis of the dimension entity.
Vector3d zAxis = diment.Normal;
Vector3d xAxis = zAxis.GetPerpendicularVector();
Vector3d yAxis = zAxis.CrossProduct(xAxis);
// Build the transformation matrix.
mat = Matrix3d.AlignCoordinateSystem(Point3d.Origin, new Vector3d(1.0, 0.0, 0.0),
new Vector3d(0.0, 1.0, 0.0),
new Vector3d(0.0, 0.0, 1.0),
Point3d.Origin,
xAxis, yAxis, zAxis);
// To test this matrix create a new line
// using the start and endpoint of the line
// from the block definition, and transform
// the line using the calculated transformation matrix.
Line newln = new Line(sp, ep);
newln.TransformBy(mat);
Point3d nptStart, nptEnd;
nptStart = newln.StartPoint;
nptEnd = newln.EndPoint;
newln.ColorIndex = 4;
// Append the new line to the model space and close it.
// The new line should be at the location
// of the dimension entity.
btr.AppendEntity(newln);
tr.AddNewlyCreatedDBObject(newln, true);
}
tr.Commit();
}
}
}
Thanks in advance,
thenndral.