Code Red > .NET
Create object
feesa:
Hi,
I am a .net Beginner,
I would be highly appericiated if any one Provide me a coding,
I need to creating a object from Geometric center of another object,
we have to ask user to select window, then from that window, I need to create polyline with angle given by the user,
I have attached a dwg for above description.
Thanks & Regards
feesa
gile:
Hi,
Assuming you're a ".net Beginner", you shouldn't start with such a complex task. your goal requires an intermediate AutoCAD .net programming level with 3D geometry.
feesa:
Yes, I agree,
i have made long jump,
Could you pls provide me coding for my query..
I have been planning to join some autocad recognize institute to learn the basics,
If you could also provide me any ideas, links, materials to learn the .net
for autocad would be helpful...
gile:
Hi,
You should first learn the .NET basics and a supportd language (i'd recommend C# which is the most used) outside of AutoCAD, you will fin links in the .NET Getting Started topic.
Then, you can find the official documentation and tutorials for AutoCAD .NET on this page.
Here's a quick and dirty example of what you attempt to do:
--- Code - C#: ---using Autodesk.AutoCAD.ApplicationServices;using Autodesk.AutoCAD.DatabaseServices;using Autodesk.AutoCAD.EditorInput;using Autodesk.AutoCAD.Geometry;using Autodesk.AutoCAD.Runtime;using System; namespace Windows{ public class Commands { [CommandMethod("Test")] public void Test() { Document doc = Application.DocumentManager.MdiActiveDocument; Database db = doc.Database; Editor ed = doc.Editor; // prompt for the window polyline var entOpts = new PromptEntityOptions("\nSelect a window: "); entOpts.SetRejectMessage("\nSelected object must be apolyline."); entOpts.AddAllowedClass(typeof(Polyline), true); var entRes = ed.GetEntity(entOpts); if (entRes.Status != PromptStatus.OK) return; using (Transaction tr = db.TransactionManager.StartTransaction()) { var window = (Polyline)tr.GetObject(entRes.ObjectId, OpenMode.ForRead); // get the window center Extents3d extents = window.GeometricExtents; Point3d center = extents.MinPoint + (extents.MaxPoint - extents.MinPoint) / 2.0; // get the normal of the window plane Point2d pt = new Point2d(center.X, center.Y); Vector3d normal = window.Normal; // check if the window is vertical if (!normal.IsPerpendicularTo(Vector3d.ZAxis)) { ed.WriteMessage("\nThe window is not vertical."); return; } // get the nnormal angle about XY plane var angle0 = normal.AngleOnPlane(new Plane()); // prompt for the first angle var angRes = ed.GetAngle("\nAngle 1: "); if (angRes.Status != PromptStatus.OK) return; var angle1 = angRes.Value; // prompt for the second angle angRes = ed.GetAngle("\nAngle 2: "); if (angRes.Status != PromptStatus.OK) return; var angle2 = angRes.Value; var curSpace = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite); // create the polyline using (var pline = new Polyline(3)) { // add vertices pline.AddVertexAt(0, pt, 0.0, 0.0, 0.0); pline.AddVertexAt(1, Polar(pt, angle0 - angle1, 5000.0), 0.0, 0.0, 0.0); pline.AddVertexAt(2, Polar(pt, angle0 + angle1, 5000.0), 0.0, 0.0, 0.0); pline.Closed = true; // transform the polyline pline.Elevation = center.Z; pline.TransformBy(Matrix3d.Rotation(angle2, normal.CrossProduct(Vector3d.ZAxis), center)); // add the polyline to current space block table record curSpace.AppendEntity(pline); tr.AddNewlyCreatedDBObject(pline, true); } tr.Commit(); } } public Point2d Polar(Point2d basePoint, double angle, double distance) { return new Point2d( basePoint.X + distance * Math.Cos(angle), basePoint.Y + distance * Math.Sin(angle)); } }}
feesa:
Hi,
Many thanks
That's great,
It's working fine,
I need one more help in coding please,
I want to extrude that polyline(which is created from centre of window) in z axis for 5000mm
Could you pls provide me a code..
Navigation
[0] Message Index
[#] Next page
Go to full version