Author Topic: Most done with least amount code  (Read 1830 times)

0 Members and 1 Guest are viewing this topic.

Jeff H

  • Needs a day job
  • Posts: 6150
Most done with least amount code
« on: August 30, 2010, 03:01:15 AM »
Mainly I was wanting to see what others would post

I 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
Code: [Select]

  <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
a
b

Block


« Last Edit: October 28, 2010, 02:24:20 AM by Jeff H »

kaefer

  • Guest
Re: Most done with least amount code
« Reply #1 on: August 30, 2010, 01:23:11 PM »
Mainly I was wanting to see what others would post

I 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
Hi Jeff,
you aren't cheating, are you? I dunno about vb, but somewhere assemblies need to be referenced and/or namespaces to be opened.

I think it's just a funny way to say:
Code: [Select]
open Autodesk.AutoCAD.DatabaseServices
open Autodesk.AutoCAD.EditorInput
open 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()

Jeff H

  • Needs a day job
  • Posts: 6150
Re: Most done with least amount code
« Reply #2 on: August 30, 2010, 02:37:59 PM »
When you create a class library by default it imports the the ones with a check mark
Sorry I thought databaseServies,ApplicationServices, and EditorInput were understood
 
« Last Edit: August 30, 2010, 02:43:32 PM by fro2001 »