Jump to content

Dimensioning polylines


rodrigo_gcmsoft

Recommended Posts

Hello for all, I am Rodrigo and posting from Brazil.

Please somebody help me, i'm a newbie in autocad.net.

how to create polylines sizing using c #. net?

I have ObjectId of the entitys but i don't know apply dimensions.

Tanks!

Rodrigo

Link to comment
Share on other sites

I imagine the AlignedDimension object will come into

play. Stepping through the polyline's

vertexes, and using those points for the dimensions constructor may possibly be

a solution.

 

“Dimensioning polylines” has a lot of possible implications,

though, and a routine that accounted for all of them would be fairly

complex. Do you have a sample drawing

that the newsgroup could look at to see the parameters that need

to be addressed?

Link to comment
Share on other sites

Sorry for asking so widespread. I'm still new to autocad, my experience is with c #. I'm from Brazil and do not speak much English, use the google translator to use the forum. I need to do the simplest type of scaling. I already have the objectid of the polyline selected, only takes a share (quota) from every node.

Thank you for your help!

Rodrigo

 

Example:

exemplof.th.jpg

Link to comment
Share on other sites

Sorry for asking so widespread. I'm still new to autocad, my experience is with c #. I'm from Brazil and do not speak much English, use the google translator to use the forum. I need to do the simplest type of scaling. I already have the objectid of the polyline selected, only takes a share (quota) from every node.

Thank you for your help!

Rodrigo

 

Example:

exemplof.th.jpg

 

Something like this may helps:

 
[CommandMethod("Dimlotes")]
public static void PlineDimensioning()
{
//this.Hide();
Database db = HostApplicationServices.WorkingDatabase;
Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
Editor ed = doc.Editor;
 
Transaction tr = db.TransactionManager.StartTransaction();
using (tr)
{
try
{
BlockTableRecord btr= (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite) as BlockTableRecord;
Plane plan= new Plane(Point3d.Origin,ed.CurrentUserCoordinateSystem.CoordinateSystem3d.Zaxis);
TypedValue[] filList = new TypedValue[3]
{ new TypedValue((int)DxfCode.Start, "LWPOLYLINE"), 
new TypedValue(70, 1), 
new TypedValue(90, 4)
};
SelectionFilter filter = new SelectionFilter(filList);
PromptSelectionResult sres = ed.GetSelection(filter);
if (sres.Status != PromptStatus.OK)
return;
SelectionSet selSet = sres.Value;
if (selSet.Count == 0)
{
//MessageBox.Show("Nothing selected");
return;
}
 
 
ObjectId[] ids = selSet.GetObjectIds();
foreach (ObjectId id in ids)
{
Polyline poly = (Polyline)tr.GetObject(id, OpenMode.ForRead,false);
double parea = poly.Area;
string strarea = string.Format("Area = " + @"\H1.2x;{0:f2} m\H0.7x;\S2^;", parea);//<-- {0:f2} is precision 2 decimals
//Mtext
MText mt = new MText();
mt.SetDatabaseDefaults();
mt.Annotative = AnnotativeStates.False;

mt.TextHeight = db.Dimtxt;
mt.Width = db.Dimtxt * 15;
mt.Contents = strarea;
mt.Attachment=AttachmentPoint.MiddleCenter;
mt.Location = PseudoCenter(poly);
mt.Normal = ed.GetCurrentView().ViewDirection.GetNormal();
btr.AppendEntity(mt);
tr.AddNewlyCreatedDBObject(mt, true);
//Dimensioning
for (int i = 0; i < poly.NumberOfVertices; i++)
{
LineSegment3d seg = poly.GetLineSegmentAt(i);
Point3d p1 = seg.StartPoint;
Point3d p2 = seg.EndPoint;
double ang = p1.GetVectorTo(p2).AngleOnPlane(plan);
//Or:
//RotatedDimension dim = new RotatedDimension(ang, p1, p2, p1, "", db.Dimstyle);

AlignedDimension dim = new AlignedDimension(p1, p2, p1, "", db.Dimstyle);
//Or:
//RotatedDimension dim = new RotatedDimension(ang, p1, p2, p1, "", db.Dimstyle);
dim.TextRotation = ang;
dim.Dimdec = 2;//precision 2 decimals

btr.AppendEntity(dim);
tr.AddNewlyCreatedDBObject(dim, true);
}


}

tr.Commit();
}
catch (System.Exception ex)
{
ed.WriteMessage("{0}\n{1}", ex.Message, ex.StackTrace);
}
}
}
private static Point3d PseudoCenter(Polyline poly)
{
Point3d p;
Extents3d ex = poly.GeometricExtents;
Point3d p1 = ex.MinPoint;
Point3d p2 = ex.MaxPoint;
p = p1 + (p2 - p1)/2;
return p;
}

 

~'J'~

Link to comment
Share on other sites

Thanks Fixo!

That was exactly what I needed!

I will study this code to change the style of design, but the routine worked perfect.

Thank you!

Link to comment
Share on other sites

Thanks Fixo!

That was exactly what I needed!

I will study this code to change the style of design, but the routine worked perfect.

Thank you!

 

I've thought you might be want to pick two points using snap to near along any side of lote at the first

to determine mtext rotation angle and also you might be want to suppress dimension lines

so just a dimension text will be visible on screen

Happy computing

 

~'J'~

Link to comment
Share on other sites

I've thought you might be want to pick two points using snap to near along any side of lote at the first

to determine mtext rotation angle and also you might be want to suppress dimension lines

so just a dimension text will be visible on screen

Happy computing

 

~'J'~

 

I need only the values ​​and parallel to each line. I need to see how to let the values ​​inside the objects and not in the middle as it is now. Must also learn to set the font size. I'm still new to autocad, I'm learning slowly. Thank you so much!

Rodrigo

Link to comment
Share on other sites

I need only the values ​​and parallel to each line. I need to see how to let the values ​​inside the objects and not in the middle as it is now. Must also learn to set the font size. I'm still new to autocad, I'm learning slowly. Thank you so much!

Rodrigo

I have slightly edited this code, try again

 

 
[CommandMethod("Dimlotes")]
public static void PlineDimensioning()
{
Database db = HostApplicationServices.WorkingDatabase;

Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
Editor ed = doc.Editor;
PromptDoubleOptions pdo =
new PromptDoubleOptions("\nEnter text height:");
pdo.AllowNone = true;
pdo.UseDefaultValue = true;
pdo.DefaultValue = 2.5;//<-- change default
PromptDoubleResult res;
res = ed.GetDouble(pdo);
if (res.Status != PromptStatus.OK)
return;
double hgt = res.Value;
ed.WriteMessage("\nDouble Entered\t{0}",
hgt);
Transaction tr = db.TransactionManager.StartTransaction();
using (tr)
{
try
{
BlockTableRecord btr = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite) as BlockTableRecord;
Plane plan = new Plane(Point3d.Origin, ed.CurrentUserCoordinateSystem.CoordinateSystem3d.Zaxis);
TypedValue[] filList = new TypedValue[3]
{ new TypedValue((int)DxfCode.Start, "LWPOLYLINE"), 
new TypedValue(70, 1), 
new TypedValue(90, 4)
};
SelectionFilter filter = new SelectionFilter(filList);
PromptSelectionResult sres = ed.GetSelection(filter);
if (sres.Status != PromptStatus.OK)
return;
SelectionSet selSet = sres.Value;
if (selSet.Count == 0)//<-- more than one selected
{
//MessageBox.Show("Nothing selected");
return;
}
 
 
ObjectId[] ids = selSet.GetObjectIds();
foreach (ObjectId id in ids)
{
Polyline poly = (Polyline)tr.GetObject(id, OpenMode.ForRead, false);
Point3d center = PseudoCenter(poly);
double parea = poly.Area;
string strarea = string.Format("Area = " + @"\H1.2x;{0:f2} m\H0.7x;\S2^;", parea);//<-- {0::f2} is precision 2 decimals
//Mtext
MText mt = new MText();
mt.SetDatabaseDefaults();
mt.Annotative = AnnotativeStates.False;
mt.TextHeight = hgt*3;
mt.Width = hgt * 45;
mt.Contents = strarea;
mt.Attachment = AttachmentPoint.MiddleCenter;
mt.Location = center;
mt.Normal = ed.GetCurrentView().ViewDirection.GetNormal();
btr.AppendEntity(mt);
tr.AddNewlyCreatedDBObject(mt, true);
//Dimensioning
for (int i = 0; i < poly.NumberOfVertices; i++)
{
LineSegment3d seg = poly.GetLineSegmentAt(i);
Point3d p1 = seg.StartPoint;
Point3d p2 = seg.EndPoint;
double ang = p1.GetVectorTo(p2).AngleOnPlane(plan);
Point3d cp = seg.MidPoint;
double dirang = cp.GetVectorTo(center).AngleOnPlane(plan);
Point3d txp = PolarPoint(cp, dirang, hgt * 1.5);
double leng = seg.Length;
///add text
DBText txt = new DBText();
txt.SetDatabaseDefaults();
txt.Height = hgt;
txt.TextString = string.Format("{0:f2}", leng);
txt.Rotation = dirang - Math.PI / 2;
txt.HorizontalMode = TextHorizontalMode.TextCenter;
txt.VerticalMode = TextVerticalMode.TextVerticalMid;
txt.AlignmentPoint = txp;
txt.Position = txp;
txt.TextStyle = db.Textstyle;
//Or:
//RotatedDimension dim = new RotatedDimension(ang, p1, p2, p1, "", db.Dimstyle);
//AlignedDimension dim = new AlignedDimension(p1, p2, p1, "", db.Dimstyle);
//Or:
//RotatedDimension dim = new RotatedDimension(ang, p1, p2, p1, "", db.Dimstyle);
//dim.TextRotation = ang;
//dim.Dimdec = 2;//precision 2 decimals
btr.AppendEntity(txt);
tr.AddNewlyCreatedDBObject(txt, true);
}
 
}
tr.Commit();
}
catch (System.Exception ex)
{
ed.WriteMessage("{0}\n{1}", ex.Message, ex.StackTrace);
}
}
}
private static Point3d PseudoCenter(Polyline poly)
{
Point3d p;
Extents3d ex = poly.GeometricExtents;
Point3d p1 = ex.MinPoint;
Point3d p2 = ex.MaxPoint;
p = p1 + (p2 - p1) / 2;
return p;
}

public static Point3d PolarPoint(Point3d basepoint, double angle, double distance)
{
// credits to Tony Tanzillo
returnnew Point3d(
basepoint.X + (distance * Math.Cos(angle)),
basepoint.Y + (distance * Math.Sin(angle)),
basepoint.Z);
}

 

~'J'~

Link to comment
Share on other sites

@Fixo

 

 

Oleg, nicely done.

 

I intended to write a sample routine but it would have taken a day or

two. It is good to see a more timely

reply to this thread.

 

I never was a particularly fast programmer.

Quite often, an original poster (OP) has moved on to other things by the

time I’ve prepped a sample. This leaves a lot of my contributions languishing without comment. :ouch:

 

I still think it is important that we try to do our best. :)

Link to comment
Share on other sites

@SEANT

 

Thanks so much, Sean

I just gathered some pieces of code from my existing programs

In fact I'm typing very slowly using my only lonely fat finger :)

 

Have a nice all,

 

Many regards, friend

 

~'J'~

Link to comment
Share on other sites

I am most grateful for the help.

Even I'm starting to understand the structure of autocad and this forum has been important, thanks to colleagues like you.

Thank you very much.

Rodrigo

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...