rodrigo_gcmsoft Posted March 21, 2011 Share Posted March 21, 2011 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 Quote Link to comment Share on other sites More sharing options...
SEANT Posted March 21, 2011 Share Posted March 21, 2011 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? Quote Link to comment Share on other sites More sharing options...
rodrigo_gcmsoft Posted March 21, 2011 Author Share Posted March 21, 2011 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: Quote Link to comment Share on other sites More sharing options...
fixo Posted March 21, 2011 Share Posted March 21, 2011 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: 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'~ Quote Link to comment Share on other sites More sharing options...
rodrigo_gcmsoft Posted March 21, 2011 Author Share Posted March 21, 2011 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! Quote Link to comment Share on other sites More sharing options...
fixo Posted March 21, 2011 Share Posted March 21, 2011 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'~ Quote Link to comment Share on other sites More sharing options...
rodrigo_gcmsoft Posted March 21, 2011 Author Share Posted March 21, 2011 I've thought you might be want to pick two points using snap to near along any side of lote at the firstto 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 Quote Link to comment Share on other sites More sharing options...
fixo Posted March 22, 2011 Share Posted March 22, 2011 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'~ Quote Link to comment Share on other sites More sharing options...
SEANT Posted March 22, 2011 Share Posted March 22, 2011 @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. I still think it is important that we try to do our best. Quote Link to comment Share on other sites More sharing options...
fixo Posted March 22, 2011 Share Posted March 22, 2011 @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'~ Quote Link to comment Share on other sites More sharing options...
rodrigo_gcmsoft Posted March 22, 2011 Author Share Posted March 22, 2011 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.