Author Topic: "Wblock Layers", saving the contents of each layer to a separate file  (Read 11478 times)

0 Members and 1 Guest are viewing this topic.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: "Wblock Layers", saving the contents of each layer to a separate file
« Reply #15 on: October 21, 2010, 05:23:45 AM »
< .. >
You'll also notice I'm not using any error checking either - shame on me.

Naughty, naughty.

not sure what to recommend as punishment   :|

masochist says 'whip me', sadist answers 'no' ...
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Glenn R

  • Guest
Re: "Wblock Layers", saving the contents of each layer to a separate file
« Reply #16 on: October 21, 2010, 05:40:04 AM »
hehe...oldy but a goody. Actually, wouldn't the sadist say 'maybe' :D

G'day Kerry.

kaefer

  • Guest
Re: "Wblock Layers", saving the contents of each layer to a separate file
« Reply #17 on: October 21, 2010, 06:30:47 AM »
You'll also notice I'm not using any error checking either - shame on me.

Not at all. What could possibly go wrong?

And even if anything does go wrong, either the .NET unhandled exception handler kicks in and informs you that an "unhandled exception has occurred in a component in your application", or you're toast anyway. Wrapping the code in a try-catch block doesn't really buy anything.

Now checking for error codes, status indications and the like is an entirely different matter.

Cheers, Thorsten

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: "Wblock Layers", saving the contents of each layer to a separate file
« Reply #18 on: November 20, 2010, 04:32:40 PM »
Hi,

I'm still trying to understand some F# so I read the old threads where I can find some understandable code (for me).

This one make me think about a way to avoid using the Autodesk.AutoCAD.Interop to get the Template path by readin in the registry.
So I tried to write a little function.

Code: [Select]
let GetTemplatePath() = 
    let openKey key = Registry.CurrentUser.OpenSubKey(key)
    let getPath sub next key = key + "\\" + (openKey(key).GetValue(sub) :?> string) + next   
    ("Software\\Autodesk\\AutoCAD"
    |> getPath "CurVer" ""
    |> getPath "CurVer" "\\Profiles"
    |> getPath "" "\\General"
    |> openKey).GetValue("TemplatePath") :?> string

Or, more 'generic'

Code: [Select]
let CurProfileRegKey() =
    let openKey key = Registry.CurrentUser.OpenSubKey(key)
    let getPath sub key = key + "\\" + (openKey(key).GetValue(sub) :?> string)
    ("Software\\Autodesk\\AutoCAD" |> getPath "CurVer" |> getPath "CurVer") + "\\Profiles"
    |> getPath "" |> openKey

CurProfileRegKey().OpenSubKey("General").GetValue("TemplatePath")
« Last Edit: November 20, 2010, 05:50:16 PM by gile »
Speaking English as a French Frog

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: "Wblock Layers", saving the contents of each layer to a separate file
« Reply #19 on: November 21, 2010, 04:11:46 AM »
May be no need to build so many functions.

Code: [Select]
let sTemplatePath =
    let getPath sub key =
        key + "\\" + (Registry.CurrentUser.OpenSubKey(key).GetValue(sub) :?> string)   
    ((("Software\\Autodesk\\AutoCAD" |> getPath "CurVer" |> getPath "CurVer") + "\\Profiles"
    |> getPath "") + "\\General"
    |> Registry.CurrentUser.OpenSubKey).GetValue("TemplatePath") :?> string + "\\acadiso.dwt"
Speaking English as a French Frog

kaefer

  • Guest
Re: "Wblock Layers", saving the contents of each layer to a separate file
« Reply #20 on: November 21, 2010, 05:34:15 AM »
May be no need to build so many functions.

The head hurts and there's fierce need...

You could get around the downcasts to string by supplying an explicit type parameter, which is resolved by inference.
Code: [Select]
module Reg =
    let substKey<'T> sub key = (Microsoft.Win32.Registry.CurrentUser.OpenSubKey key).GetValue sub :?> 'T
    let getPath sub key = key + "\\" + substKey<_> sub key

let curVer = "Software\\Autodesk\\AutoCAD" |> Reg.getPath "CurVer" |> Reg.getPath "CurVer"
let sTemplatePath =
    ((curVer + "\\Profiles" |> Reg.getPath "") + "\\General" |> Reg.substKey<_> "TemplatePath") + "\\acadiso.dwt"

Or if you're planning to do this a lot, go the whole mile and define custom operators. These here have the same precedence and associativity as to get rid of the ugly parentheses.
Code: [Select]
let openKey = Microsoft.Win32.Registry.CurrentUser.OpenSubKey
let (+&) key sub = (openKey key).GetValue sub
let (+/) key sub = key + "\\" + (key +& sub :?> string)
let templatePath() =
    "Software\\Autodesk\\AutoCAD"
    +/ "CurVer"
    +/ "CurVer"
    + "\\Profiles"
    +/ ""
    + "\\General"
    +& "TemplatePath"
    :?> string
    + "\\acadiso.dwt"

Take care, Thorsten

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: "Wblock Layers", saving the contents of each layer to a separate file
« Reply #21 on: November 21, 2010, 07:11:11 AM »
Thank you very much kaefer.
I'll study all this...

Quote
the ugly parentheses
I'am comming from LISP, parentheses reassure me.
« Last Edit: November 21, 2010, 07:16:28 AM by gile »
Speaking English as a French Frog