Author Topic: ( Challenge ) How fast can you convert these?  (Read 26720 times)

0 Members and 1 Guest are viewing this topic.

pkohut

  • Guest
Re: ( Challenge ) How fast can you convert these?
« Reply #75 on: December 08, 2008, 05:05:32 PM »
Would that be with a guitar or keyboard?

Guitar Hero, of course  :-)

Bobby C. Jones

  • Swamp Rat
  • Posts: 516
  • Cry havoc and let loose the dogs of war.
Re: ( Challenge ) How fast can you convert these?
« Reply #76 on: September 16, 2009, 01:38:54 PM »
I was thinking about coding one in F# ... but real work and sleep keep getting in the way ...

//kdub

Sorry to dredge up old posts, but I was bored over lunch.  I don't imagine this will run much different than the C# versions.

Code: [Select]
module Acad

open System
open Autodesk.AutoCAD.ApplicationServices
open Autodesk.AutoCAD.DatabaseServices
open Autodesk.AutoCAD.Geometry
open Autodesk.AutoCAD.Runtime


let GetActiveDoc () =
  Application.DocumentManager.MdiActiveDocument
 
 
let GetPoints () =
  let db = GetActiveDoc().Database
  use trans = db.TransactionManager.StartTransaction()
  let blocks = trans.GetObject(db.BlockTableId, OpenMode.ForRead) :?> BlockTable
  let modelSpace = trans.GetObject(blocks.[BlockTableRecord.ModelSpace], OpenMode.ForWrite) :?> BlockTableRecord

  for id in modelSpace do
    let dbObj = trans.GetObject(id, OpenMode.ForWrite)
    match dbObj with
    | :? DBPoint as pnt->
      let circ = new Circle(pnt.Position, Vector3d.ZAxis, 4.0)
      modelSpace.AppendEntity(circ) |> ignore
      trans.AddNewlyCreatedDBObject(circ, true)
      pnt.Erase()
    | _ -> ()
 
  trans.Commit()
   
 
let Timer f =
  let timer = new System.Diagnostics.Stopwatch()
  timer.Start()
  f()
  timer.Stop()
  timer.Elapsed.TotalSeconds
 
 
let Print x =
  GetActiveDoc().Editor.WriteMessage("\n" + x.ToString())
 
 
[<CommandMethod("pts")>]
let pts () =
  Timer GetPoints
  |> Print

0.4217323
Bobby C. Jones