public static void SelectCommand() { using (var tr = new QuickTransaction()) { var set = tr.GetImpliedOrSelect(); if (set == null) { return; } tr.WriteLine($"Count: " + set.Count); tr.SetImpliedSelection(set); tr.StringCommand("C2P "); tr.SetImpliedSelection(set = tr.SelectLast().Value ?? SelectionSet.FromObjectIds(new ObjectId[0])); tr.Commit(); } }
public static void SummarizeLengthsCommand() { using (var tr = new QuickTransaction()) { var set = tr.GetImpliedOrSelect(); double l = 0; if (set == null || set.Count == 0) { return; } var an = new List <string>(); //already announced list.. foreach (SelectedObject o in set) { if (o != null) { var e = tr.GetObject(o.ObjectId, OpenMode.ForWrite) as Entity; string name = null; switch (e) { case null: continue; case Polyline p: l += p.Length; break; case Circle c: l += c.Diameter; break; case Arc a: l += a.Length; break; case Line li: l += li.Length; break; case Spline sp: l += sp.GetLength(); break; case Curve sp: l += sp.GetLength(); break; case Mline mline: if (mline.NumberOfVertices > 1) { for (int i = 1; i < mline.NumberOfVertices; i++) { l += mline.VertexAt(i - 1).DistanceTo(mline.VertexAt(i)); } } break; case BlockReference br: if (br.DynamicBlockReferencePropertyCollection.Count == 0) { if (an.Contains(br.Name)) { break; } an.Add(br.Name); tr.WriteLine($"Name: {br.Name}, {br.BlockName} doesn't have Distance property!"); break; } foreach (var att in br.DynamicBlockReferencePropertyCollection.Cast <DynamicBlockReferenceProperty>()) { if (att.PropertyName.Equals("distance", StringComparison.InvariantCultureIgnoreCase) || att.PropertyName.Equals("length", StringComparison.InvariantCultureIgnoreCase)) { var val = att.Value ?? string.Empty; if (string.IsNullOrEmpty(val.ToString()) == false && double.TryParse(val.ToString(), out double res)) { l += res; goto _br_exit; } else { tr.WriteLine($"{br.Name}, {br.BlockName} with property named {att.PropertyName} has no numeric value."); goto _br_exit; } } } if (an.Contains(br.Name)) { break; } an.Add(br.Name); tr.WriteLine($"{br.Name}, {br.BlockName} doesn't have Distance/Length property!"); _br_exit: break; case DBText _: case MLeader _: case AlignedDimension _: case Wipeout _: name = e.GetType().Name; if (an.Contains(name)) { break; } an.Add(name); tr.WriteLine($"{name} cant be calculated using this method!"); break; default: tr.WriteLine("Unmappped: " + e.GetType().FullName); break; } } } tr.WriteLine($"Length: " + l.ToString("##.000")); } }