.NET

.NET

Reply
Contributor
waterharbin
Posts: 14
Registered: ‎07-17-2011
Message 1 of 2 (148 Views)

How to select all the lines automatically

148 Views, 1 Replies
08-11-2011 10:30 PM
Hello.How can i create a command to select all lines without darg the cursor to select? the code below can work,but not smart enough.Any one give me a tip? [CommandMethod("AllLines")] public void seletcAllLines() { Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument; Database db = doc.Database; Editor ed = doc.Editor; using (Transaction trans = db.TransactionManager.StartTransaction()) { try { //define the criteria for selecting lines only TypedValue[] tv = new TypedValue[] { new TypedValue((int)DxfCode.Start, "LINE") }; SelectionFilter flt = new SelectionFilter(tv); /*This method needs to drag the cursor,which I think is not smart. I will want to improve it.*/ PromptSelectionOptions optSel = new PromptSelectionOptions(); optSel.MessageForAdding = "You will need to drag this cursor to select."; PromptSelectionResult resSel = ed.GetSelection(optSel,flt); SelectionSet selSet = resSel.Value; ObjectId[] ids = selSet.GetObjectIds(); foreach (ObjectId sSetEntId in ids) { Entity ent = (Entity)trans.GetObject(sSetEntId, OpenMode.ForWrite); if (ent.GetType().Name=="Line") //Is there any better ideal to write the condition,the"typeof(ent) is Line" just gets an error! { Line myLine = (Line)trans.GetObject(sSetEntId, OpenMode.ForWrite); ed.WriteMessage("\n"+myLine.StartPoint.ToString()+ myLine.EndPoint.ToString()); } } trans.Commit(); } catch(System.Exception ex) { ed.WriteMessage(ex.Message + "\n" + ex.StackTrace); } }
Valued Mentor
jeff
Posts: 338
Registered: ‎05-12-2009
Message 2 of 2 (145 Views)

Re: How to select all the lines automatically

08-11-2011 10:46 PM in reply to: waterharbin

already asked and answered

http://www.theswamp.org/index.php?topic=39139.0

You can also find your answers @ TheSwamp
Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Do you have 60 seconds to spare? The Autodesk Community Team is revamping our site ranking system and we want your feedback! Please click here to launch the 5 question survey. As always your input is greatly appreciated.