Sundar Posted January 11, 2012 Share Posted January 11, 2012 Hi All, I just registered in this forum and this is my first thread.Hope i will get what i want from you all masters.. I just want to trim the poly lines within the boundary selected by user.Lines to be trimmed exactly at the intersection of line and the rectangle.... Quote Link to comment Share on other sites More sharing options...
Dadgad Posted January 11, 2012 Share Posted January 11, 2012 Use the TRIM command, as follows. TRIM > ENTER > ENTER > make your selection with a crossing box (starting from right and moving to the left). I am not sure if you are wondering how to do this, or are looking for coding help. Quote Link to comment Share on other sites More sharing options...
Sundar Posted January 11, 2012 Author Share Posted January 11, 2012 I need to do this through VBA coding.all the lines outside of the selected boundary should be deleted. Quote Link to comment Share on other sites More sharing options...
Dadgad Posted January 11, 2012 Share Posted January 11, 2012 I need to do this through VBA coding.all the lines outside of the selected boundary should be deleted. Never mind then, as it was your first post I thought you might have put it in the wrong forum. Sorry I can't help you with VBA. Quote Link to comment Share on other sites More sharing options...
Sundar Posted January 11, 2012 Author Share Posted January 11, 2012 I think i have put in correct forum as its under VBA.if not could u pls direct me to the correct forum? Quote Link to comment Share on other sites More sharing options...
Dadgad Posted January 11, 2012 Share Posted January 11, 2012 I think i have put in correct forum as its under VBA.if not could u pls direct me to the correct forum? No, you have not made a mistake, I did. Your post is right where it should be. Where have I heard that before? Quote Link to comment Share on other sites More sharing options...
SEANT Posted January 11, 2012 Share Posted January 11, 2012 Trimming lines/polylines is a fairly complex task from a programming perspective. You would first have to determine which entities intersect with the rectangle (IntersectWith method). Determine the number of intersections. If the polyline has Arcs/Bulges, there may even be more than two intersections. Recreate all the entitles that have a start- or endpoint not within the rectangle, using that exterior point and the correct intersection point on the rectangle. The Start Endpoint direction may be critical if there are any LineType issues. Transfer all properties of the original entity to these new recreations. Delete original entities. Alternatively, you may be able to use TRIM command, perhaps with FENCE option via ThisDrawing.SendCommand. Yet abnother alternative may be to use a WipeOut. Quote Link to comment Share on other sites More sharing options...
SEANT Posted January 11, 2012 Share Posted January 11, 2012 I should also mention the ExpressTool's EXTRIM command. That does the procedure you describe. Quote Link to comment Share on other sites More sharing options...
Sundar Posted January 11, 2012 Author Share Posted January 11, 2012 Thanks SEANT..while i was googling for this i came across the EXTRIM command and i did "thisdrawing.sendcommand("extrim")" thing.it worked fine but what if i want the result to be in a separate layer. i cant process the trimmed objects (from my knowledge)... Quote Link to comment Share on other sites More sharing options...
SEANT Posted January 11, 2012 Share Posted January 11, 2012 (edited) If that is the case then it may be beneficial to iterate - and process - each entity separately. That iteration, though, probably eliminates the SendCommand option due to its asynchronous nature. In my opinion, VBA is a poor programming tool for this task. It does not have a native API for dealing with all of AutoCAD’s available Curve functionality. VBA is also a deprecated programming language. So even if all the necessary functionality were custom built with VBA, it would not be useful for future releases of AutoCAD. The project is much more feasible with managed/unmanaged ARX(VB.NET, for instance), or AutoLisp. Edited January 22, 2012 by SEANT Quote Link to comment Share on other sites More sharing options...
Sundar Posted January 11, 2012 Author Share Posted January 11, 2012 It would be great if u could guide me with autolisp for the same task.. Quote Link to comment Share on other sites More sharing options...
SEANT Posted January 11, 2012 Share Posted January 11, 2012 I don't use AutoLisp: I'm more inclined towards C#.NET. Post the request in the AutoLisp section (http://www.cadtutor.net/forum/forumdisplay.php?21-AutoLISP-Visual-LISP-amp-DCL). There may even be sub-routines available that facilitate the process. Quote Link to comment Share on other sites More sharing options...
Sundar Posted January 12, 2012 Author Share Posted January 12, 2012 ok thanks seant... Quote Link to comment Share on other sites More sharing options...
fixo Posted January 15, 2012 Share Posted January 15, 2012 (edited) You can try to start from this scratch, compare both comands in action [CommandMethod("ipLine")] public void IntersectTestIn() { Database db = HostApplicationServices.WorkingDatabase; Document doc = acadApp.DocumentManager.MdiActiveDocument; Editor ed = doc.Editor; using (Transaction tr = db.TransactionManager.StartTransaction()) { PromptEntityOptions peo = new PromptEntityOptions("\nSelect a Line >>"); peo.SetRejectMessage("\nYou have to select the Line only >>"); peo.AddAllowedClass(typeof(Line), 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; Line line = (Line)ent as Line; if (line == null) return; peo = new PromptEntityOptions("\nSelect a Rectangle: "); peo.SetRejectMessage("\nYou have to select the Polyline only >>"); peo.AddAllowedClass(typeof(Polyline), false); res = ed.GetEntity("\nSelect a Rectangle: "); if (res.Status != PromptStatus.OK) return; ent = (Entity)tr.GetObject(res.ObjectId, OpenMode.ForRead); if (ent == null) return; Polyline pline = (Polyline)ent as Polyline; if (line == null) return; Point3dCollection pts = new Point3dCollection(); pline.IntersectWith(line, Intersect.ExtendArgument, pts, 0, 0); if (pts.Count == 0) return; List<Point3d> points = new List<Point3d>(); points.Add(line.StartPoint); points.Add(line.EndPoint); foreach (Point3d p in pts) points.Add(p); DBObjectCollection objs = line.GetSplitCurves(pts); List<DBObject> lstobj = new List<DBObject>(); foreach (DBObject dbo in objs) lstobj.Add(dbo); points.Sort(delegate(Point3d p1, Point3d p2) { return Convert.ToDouble( Convert.ToDouble(line.GetParameterAtPoint(p1))).CompareTo( Convert.ToDouble(line.GetParameterAtPoint(p2))); } ); BlockTableRecord btr = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite); Line ln0 = lstobj[1] as Line;// middle Line ln1 = new Line(points[0], points[1]); Line ln2 = new Line(points[2], points[3]); if (!ln0.IsWriteEnabled) ln0.UpgradeOpen(); ln0.Dispose(); if (!ln1.IsWriteEnabled) ln1.UpgradeOpen(); btr.AppendEntity(ln1); tr.AddNewlyCreatedDBObject(ln1, true); if (!ln2.IsWriteEnabled) ln2.UpgradeOpen(); btr.AppendEntity(ln2); tr.AddNewlyCreatedDBObject(ln2, true); if (!line.IsWriteEnabled) line.UpgradeOpen(); line.Erase(); line.Dispose(); ed.Regen(); tr.Commit(); } } [CommandMethod("opLine")] public void IntersectTest() { Database db = HostApplicationServices.WorkingDatabase; Document doc = acadApp.DocumentManager.MdiActiveDocument; Editor ed = doc.Editor; using (Transaction tr = db.TransactionManager.StartTransaction()) { PromptEntityOptions peo = new PromptEntityOptions("\nSelect a Line >>"); peo.SetRejectMessage("\nYou have to select the Line only >>"); peo.AddAllowedClass(typeof(Line), 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; Line line = (Line)ent as Line; if (line == null) return; peo = new PromptEntityOptions("\nSelect a Rectangle: "); peo.SetRejectMessage("\nYou have to select the Polyline only >>"); peo.AddAllowedClass(typeof(Polyline), false); res = ed.GetEntity("\nSelect a Rectangle: "); if (res.Status != PromptStatus.OK) return; ent = (Entity)tr.GetObject(res.ObjectId, OpenMode.ForRead); if (ent == null) return; Polyline pline = (Polyline)ent as Polyline; if (line == null) return; Point3dCollection pts = new Point3dCollection(); pline.IntersectWith(line, Intersect.ExtendArgument, pts, 0, 0); if (pts.Count == 0) return; DBObjectCollection lstobj = line.GetSplitCurves(pts); BlockTableRecord btr = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite); Line ln0 = lstobj[1] as Line;// middle Line ln1 = lstobj[0] as Line; Line ln2 = lstobj[2] as Line; if (!ln0.IsWriteEnabled) ln0.UpgradeOpen(); btr.AppendEntity(ln0); tr.AddNewlyCreatedDBObject(ln0, true); if (!ln1.IsWriteEnabled) ln1.UpgradeOpen(); ln1.Dispose(); if (!ln2.IsWriteEnabled) ln2.UpgradeOpen(); ln2.Dispose(); if (!line.IsWriteEnabled) line.UpgradeOpen(); line.Erase(); line.Dispose(); ed.Regen(); tr.Commit(); } } ~'J'~ Edited January 15, 2012 by fixo new code added Quote Link to comment Share on other sites More sharing options...
SEANT Posted January 16, 2012 Share Posted January 16, 2012 Excellent example, Fixo. The original poster will have a good starting point if they plan on implementing a .NET solution. Quote Link to comment Share on other sites More sharing options...
fixo Posted January 16, 2012 Share Posted January 16, 2012 Glad you like it Regards, Quote Link to comment Share on other sites More sharing options...
Sundar Posted January 19, 2012 Author Share Posted January 19, 2012 thanks for your code.solved almost all reference missing issues.But couldn't solve for Documentmanager. Got error on this line : Document doc = acadApp.DocumentManager.MdiActiveDocument; Error is : Error 1 'Autodesk.AutoCAD.Interop.AcadApplication' does not contain a definition for 'DocumentManager' and no extension method 'DocumentManager' accepting a first argument of type 'Autodesk.AutoCAD.Interop.AcadApplication' could be found (are you missing a using directive or an assembly reference?) D:\Users\Sundar\Visual Studio 2008\NewTrim\NewTrim\Class1.cs 23 27 NewTrim Please suggest which reference im missing.. Quote Link to comment Share on other sites More sharing options...
fixo Posted January 19, 2012 Share Posted January 19, 2012 This code did not use Interop you have to add references to acdbmgd.dll and acmgd.dll and set property 'Copy to Local' = False for both of them Quote Link to comment Share on other sites More sharing options...
Sundar Posted January 19, 2012 Author Share Posted January 19, 2012 I have added those references and set the property 'Copy to Local'=False..But still get the same error.. Quote Link to comment Share on other sites More sharing options...
SEANT Posted January 19, 2012 Share Posted January 19, 2012 Similar to the setup in this post: http://www.cadtutor.net/forum/showthread.php?42125-Expand-a-text-routine-to-include-MTEXT-DIM&p=284047&viewfull=1#post284047 The using statements section of the routine should include this line: using acadApp = Autodesk.AutoCAD.ApplicationServices.Application; 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.