dbroada Posted February 20, 2013 Share Posted February 20, 2013 I want to make a block of a triangle using vb.net I know my geometry to be a 3 sided polygon circumscribed about a 3,5 rasdius circle but I can't find the polygon object. Does it exist in VB.Net? I know I can construct my triangle in other ways but I thought a polygon would be easier. Quote Link to comment Share on other sites More sharing options...
Tyke Posted February 20, 2013 Share Posted February 20, 2013 Dave, are you doing this in VB or C#? Have a look in your Jerry Winters book Chapter 14. He deals with drawing polygons there. Basically you have a function that takes a centre point, the number of sides and the radius and then returns the points required to draw polygon. Then use DatabaseServices.Poly3DType.SimplePoly, PointsIn, True Hope that helps. Quote Link to comment Share on other sites More sharing options...
BlackBox Posted February 20, 2013 Share Posted February 20, 2013 (edited) If I am understanding you correctly, you're after either the Polyline2d, or Polyline3d type found under Autodesk.AutoCAD.DatabaseServices in Object Browser. Edited February 20, 2013 by BlackBox Quote Link to comment Share on other sites More sharing options...
Tyke Posted February 20, 2013 Share Posted February 20, 2013 At last I beat RenderMan to the draw Quote Link to comment Share on other sites More sharing options...
BlackBox Posted February 20, 2013 Share Posted February 20, 2013 At last I beat RenderMan to the draw ... Quote Link to comment Share on other sites More sharing options...
BlackBox Posted February 20, 2013 Share Posted February 20, 2013 Dave, there are several ways to accomplish this task. For example, you could register an ObjectAppended, and CommandEnded Event handler, and invoke the POLYGON Command, such that when the ObjectAppended Event is raised, you can store the Polyline* typed object's ObjectId (the one just added to the Database) to an internal Property object, so that when the CommandEnded Event is raised you can then modify said ObjectId. Quote Link to comment Share on other sites More sharing options...
BlackBox Posted February 20, 2013 Share Posted February 20, 2013 Also... So that this code is not always processing every Object appended to the Database, you might consider registering a CommandWillStart Event handler, to filter for the POLYGON Command, and conditionally register the ObjectAppended Event handler... Just be mindful to unregister the ObjectAppended Event handler via the CommandCancelled, CommandEnded, or CommandFailed Events (you can use the same Method for all three if you like). In this manor, only when the user invokes the built-in POLYGON Command is your code 'watching' for Polyline* typed objects being appended to the Database, and programmatically acting on said object once successfully created. The alternative is to filter each-and-every object appended to the Database for PolyLine* typed objects, but even then, how to distinguish a generic polyline from the polyline created via the POLYGON Command? Just a thought. Quote Link to comment Share on other sites More sharing options...
dbroada Posted February 20, 2013 Author Share Posted February 20, 2013 (edited) Thanks for the answers. One thing I didn't state was that I was just about to leave work until Friday so won't be able t examine answers in detail. To be honest, I didn't expect any answers! Dave, are you doing this in VB or C#? Have a look in your Jerry Winters book Chapter 14. He deals with drawing polygons there. Basically you have a function that takes a centre point, the number of sides and the radius and then returns the points required to draw polygon. Then use DatabaseServices.Poly3DType.SimplePoly, PointsIn, True Hope that helps. Thanks Tyke, I had a quick look through the book but couldn't find anything. I'll look again when I get to work on Friday. Edited February 20, 2013 by dbroada typed inside the quotes! DOH!! Quote Link to comment Share on other sites More sharing options...
BlackBox Posted February 20, 2013 Share Posted February 20, 2013 For when you come back, here's a quickly written, working framework (in C#) for what I've outlined above... In this pseudo-code, I simply change the ColorIndex Property to 1 (Red) for each 'polygon' the user adds to the Database via the POLYGON Command: using Autodesk.AutoCAD.ApplicationServices; using Autodesk.AutoCAD.DatabaseServices; using Autodesk.AutoCAD.EditorInput; using Autodesk.AutoCAD.Internal; using Autodesk.AutoCAD.Runtime; using acApp = Autodesk.AutoCAD.ApplicationServices.Application; using System; using System.IO; using System.Reflection; [assembly: ExtensionApplication(typeof(CADTutor.Sample.AllPolygonsRed))] namespace CADTutor.Sample { class AllPolygonsRed : IExtensionApplication { #region Properties public static ObjectId Polygon { get; internal set; } #endregion #region Initialization void IExtensionApplication.Initialize() { DocumentCollection acDocs = acApp.DocumentManager; Document doc = acDocs.MdiActiveDocument; Editor ed = doc.Editor; acDocs.DocumentCreated += OnDocumentCreated; doc.CommandWillStart += OnCommandWillStart; ed.WriteMessage("\n** " + Path.GetFileNameWithoutExtension(Assembly.GetExecutingAssembly().Location) + " loaded ** \n"); } void IExtensionApplication.Terminate() { } #endregion #region Methods public static void OnCommandEnded(object sender, CommandEventArgs e) { Document doc = acApp.DocumentManager.MdiActiveDocument; Editor ed = doc.Editor; UnRegisterEvents(doc); try { using (DocumentLock docLock = doc.LockDocument()) { using (Transaction trans = doc.Database.TransactionManager.StartOpenCloseTransaction()) { if (Polygon != null) { Entity entity = trans.GetObject(Polygon, OpenMode.ForWrite) as Entity; if (entity != null) entity.ColorIndex = 1; ed.WriteMessage("** Polygon entity color changed to red ** \n"); } trans.Commit(); } } } catch (System.Exception ex) { ed.WriteMessage("\nSystem.Exception error: " + ex.Message); } } public static void OnCommandWillStart(object sender, CommandEventArgs e) { string cmd = e.GlobalCommandName.ToString().ToUpper(); if (cmd != null && Utils.WcMatch(cmd, "*POLYGON")) RegisterEvents(acApp.DocumentManager.MdiActiveDocument); } public static void OnDocumentCreated(Object sender, DocumentCollectionEventArgs e) { Document doc = e.Document; if (doc != null) doc.CommandWillStart += OnCommandWillStart; } public static void OnObjectAppended(object sender, ObjectEventArgs e) { ObjectId id = e.DBObject.ObjectId; if (id != null) Polygon = id; } public static void RegisterEvents(Document doc) { if (doc != null) { Editor ed = doc.Editor; // command events doc.CommandCancelled += OnCommandEnded; doc.CommandEnded += OnCommandEnded; doc.CommandFailed += OnCommandEnded; // database events doc.Database.ObjectAppended += OnObjectAppended; ed.WriteMessage("\n** Polygon events registered ** \n"); } } public static void UnRegisterEvents(Document doc) { if (doc != null) { Editor ed = doc.Editor; // command events doc.CommandCancelled -= OnCommandEnded; doc.CommandEnded -= OnCommandEnded; doc.CommandFailed -= OnCommandEnded; // database events doc.Database.ObjectAppended -= OnObjectAppended; ed.WriteMessage("\n** Polygon events unregistered ** \n"); } } #endregion } } 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.