0 Members and 1 Guest are viewing this topic.
<CommandMethod("GL")> _ Public Sub GL() Dim db As Database = HostApplicationServices.WorkingDatabase Dim ed As Editor = DocumentManager.MdiActiveDocument.Editor Using tr As Transaction = db.TransactionManager.StartTransaction Dim tv() As TypedValue = {(New TypedValue(DxfCode.Start, "LINE"))} Dim sf As New SelectionFilter(tv) Dim psr As PromptSelectionResult = ed.GetSelection(sf) If psr.Status = PromptStatus.OK Then ed.WriteMessage(String.Format("{0}{1} lines Selected{2}", vbCrLf, psr.Value.Count, vbCrLf)) Dim shortLines = Aggregate ll In psr.Value.GetObjectIds _ Let f = CType(ll.GetObject(OpenMode.ForRead), Line) _ Where f.Length < 500 And f.Layer = "0" _ Select obid = f.ObjectId, lgh = f.Length _ Into tl = Sum(lgh) ed.WriteMessage(String.Format("{0} total Length", shortLines)) End If tr.Commit() End Using End Sub
Mainly I was wanting to see what others would postI ran across this in a file and I think I posted on another site for someone. This filters all lines that are less 500 on layer 0 and adds all of thier lengths together
open Autodesk.AutoCAD.DatabaseServicesopen Autodesk.AutoCAD.EditorInputopen Autodesk.AutoCAD.Runtime type acApp = Autodesk.AutoCAD.ApplicationServices.Application[<CommandMethod "GL">]let GL() = let db = HostApplicationServices.WorkingDatabase let ed = acApp.DocumentManager.MdiActiveDocument.Editor use tr = db.TransactionManager.StartTransaction() let psr = new SelectionFilter [| new TypedValue(int DxfCode.Start, "LINE") |] |> ed.GetSelection if psr.Status = PromptStatus.OK then ed.WriteMessage("\n{0} lines Selected\n", psr.Value.Count) let shortLines = psr.Value.GetObjectIds() |> Seq.map (fun ll -> ll.GetObject(OpenMode.ForRead) :?> Line) |> Seq.filter (fun f -> f.Length < 500. && f.Layer = "0") |> Seq.sumBy (fun f -> f.Length) ed.WriteMessage("{0} total Length", shortLines) tr.Commit()