Hi,
How do I get all lines connected to a selected line. The lines can cross other lines ,they can share same start or end point or they can share common vertices. In all I mean to say that I want all lines connected/touching/intersecting lines to the selected line.
Thanks & Regards
Sanjay Pandey
Change this code to your needs:
//_____________________________________________________________________// //ads_queueexpr [DllImport("accore.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl, EntryPoint = "ads_queueexpr")] extern static private int ads_queueexpr(byte[] command); [CommandMethod("tJL", CommandFlags.Modal | CommandFlags.UsePickSet)] public void TestConnectedLines() { Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument; Editor ed = doc.Editor; Database db = doc.Database; PromptEntityOptions pso = new PromptEntityOptions("\nPick a single line to join: "); pso.SetRejectMessage("\nObject must be of type Line!"); pso.AddAllowedClass(typeof(Line), false); PromptEntityResult res = ed.GetEntity(pso); if (res.Status != PromptStatus.OK) return; using (DocumentLock doclock = doc.LockDocument()) { using (Transaction tr = db.TransactionManager.StartTransaction()) { Autodesk.AutoCAD.ApplicationServices.Application.SetSystemVariable( "PICKFIRST",1); Autodesk.AutoCAD.ApplicationServices.Application.SetSystemVariable( "PEDITACCEPT",0); BlockTableRecord btr = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForRead) as BlockTableRecord; List<ObjectId> ids = JoinLines(btr, res.ObjectId); ObjectId[] lines = ids.ToArray(); ed.SetImpliedSelection(lines); PromptSelectionResult chres = ed.SelectImplied(); if (chres.Status != PromptStatus.OK) { ed.WriteMessage("\nNothing added in the chain!"); return; } else { ed.WriteMessage(chres.Value.Count.ToString()); } SelectionSet newset = SelectionSet.FromObjectIds(lines); ed.SetImpliedSelection(newset); string handles = ""; foreach (SelectedObject selobj in newset) { Entity subent = tr.GetObject(selobj.ObjectId, OpenMode.ForWrite) as Entity; string hdl=string.Format("(handent \"{0}\")",subent.Handle.ToString()); handles= handles + hdl + " "; } System.Text.UnicodeEncoding uEncode = new System.Text.UnicodeEncoding(); // if PEDITACCEPT is set to 1 enshort the command avoiding "_Y" argument: ads_queueexpr(uEncode.GetBytes("(COMMAND \"_.PEDIT\" \"_M\"" + handles + "\"\"" + "\"_Y\" \"_J\" \"\" \"\")")); tr.Commit(); } } } private void SelectConnectedLines(BlockTableRecord btr, List<ObjectId> ids, ObjectId id) { Entity en = id.GetObject(OpenMode.ForRead, false) as Entity; Line ln = en as Line; if (ln != null) foreach (ObjectId idx in btr) { Entity ex = idx.GetObject(OpenMode.ForRead, false) as Entity; Line lx = ex as Line; if (((ln.StartPoint == lx.StartPoint) || (ln.StartPoint == lx.EndPoint)) || ((ln.EndPoint == lx.StartPoint) || (ln.EndPoint == lx.EndPoint))) if (!ids.Contains(idx)) { ids.Add(idx); SelectConnectedLines(btr, ids, idx); } } } public List<ObjectId> JoinLines(BlockTableRecord btr, ObjectId id) { List<ObjectId> ids = new List<ObjectId>(); SelectConnectedLines(btr, ids, id); return ids; } //_____________________________________________________________________//
Hi,
Try importing: System.Collections.Generic Namespace into the class you are coding.
Gaston Nunez
// if PEDITACCEPT is set to 1 enshort the command avoiding "_Y" argument: ads_queueexpr(uEncode.GetBytes("(COMMAND \"_.PEDIT\" \"_M\"" + handles + "\"\"" + "\"_Y\" \"_J\" \"\" \"\")"));
what is the purpose of the above here?
When I sent to the ojbectarx reference guide to see what ads_queueexpr means i was meant with confusion:
I do not understand much of the above.
Am i doing this right? Any assistance much appreciated.
For anyone reading this perhaps you can make use of the following routine Mr Gilles has kindly provided:
https://www.theswamp.org/index.php?action=post;quote=446965;topic=31865.15;last_msg=565479
it seems to work very quickly - incredibly quickly compared to the algorithm posted above. You will also need the GeometryExtensions Library also kindly provided by Mr Gilles.
good luck.
Here is a direct link to that post :
https://www.theswamp.org/index.php?topic=31865.msg446965#msg446965
// Called Kerry in my other life.
Everything will work just as you expect it to, unless your expectations are incorrect.
class keyThumper<T> : Lazy<T>; another Swamper