keafer,
Studying your code, I learned some of the Seq module (higher order) functions today, I'll have a look around the LazyList later.
Here's what I'm able to write now:
let duplicate (b: BlockReference) =
b.Name,
b.OwnerId,
Math.Round(b.Position.X, 6),
Math.Round(b.Position.Y, 6),
Math.Round(b.Position.Z, 6),
b.Layer,
Math.Round(b.Rotation, 6),
Math.Round(b.ScaleFactors.X, 6),
Math.Round(b.ScaleFactors.Y, 6),
Math.Round(b.ScaleFactors.Z, 6)
let deleteDuplicatedBlockRef() =
let db = HostApplicationServices.WorkingDatabase
use tr = db.TransactionManager.StartTransaction()
let getRefs btrId =
let btr = tr.GetObject(btrId, OpenMode.ForRead) :?> BlockTableRecord
btr.GetBlockReferenceIds(true, false)
|> Seq.cast<_>
let openRefs brefId =
tr.GetObject(brefId, OpenMode.ForRead) :?> BlockReference
let cnt = tr.GetObject(db.BlockTableId, OpenMode.ForRead) :?> BlockTable
|> Seq.cast<_>
|> Seq.collect getRefs
|> Seq.map openRefs
|> Seq.groupBy duplicate
|> Seq.collect (fun x -> snd x |> Seq.skip 1)
|> Seq.fold (fun cnt bref ->
bref.UpgradeOpen()
bref.Erase()
cnt + 1 ) 0
tr.Commit()
cnt
More and more, I think I like this language...