Author Topic: reading ldata from .NET  (Read 1740 times)

0 Members and 1 Guest are viewing this topic.

jsr

  • Guest
reading ldata from .NET
« on: August 13, 2011, 11:50:33 PM »
Hi all

I am trying to read ldata stored in a block with key "model" and value "48b". By using following code.

Code: [Select]

if (ent.ExtensionDictionary.IsNull)
            {
                Application.ShowAlertDialog("No Dictionary");
            }
            else
            {
                Application.ShowAlertDialog("Dictionary exists");
                DBDictionary dict = (DBDictionary)tr.GetObject(ent.ExtensionDictionary, OpenMode.ForRead);               

                foreach (DBDictionaryEntry entry in dict)
                {
                    Application.ShowAlertDialog(entry.Key.ToString());
                }


By using entry.key I can read the value "model". But using entry.value I get some number which is probably objectId. Furtur I do not know to to use that number to access the value "48b" against the key "model". So Please guide how can I read the value against key. I think that since ldata uses dictionaries it must be readable using .NET

Thanks.

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: reading ldata from .NET
« Reply #1 on: August 14, 2011, 03:12:39 AM »
Hi,

As far as I know, ldatas (LISP datas) can only be acessed from LISP.
This is the main reason why many LISPers avoid to use ldatas, using standard dictionary and xrecords instead.
Speaking English as a French Frog

kaefer

  • Guest
Re: reading ldata from .NET
« Reply #2 on: August 14, 2011, 05:43:49 PM »
As far as I know, ldatas (LISP datas) can only be acessed from LISP.

Does p/invoke entget count as lisp?

Look out for DxfCode.XTextString. SafeNativeMethods snatched from BillZndl. This is in F#, where I like the alternative syntax for extern declarations:

Code: [Select]
[<DllImport("acdb18.dll", CallingConvention = CallingConvention.Cdecl,
    EntryPoint = "?acdbGetAdsName@@YA?AW4ErrorStatus@Acad@@AAY01JVAcDbObjectId@@@Z")>]
let acdbGetAdsName(e: byref<int64>, oid: ObjectId) = ErrorStatus.FileNotFound

[<DllImport("acad.exe", CallingConvention = CallingConvention.Cdecl)>]
let acdbEntGet(e: byref<int64>) = System.IntPtr.Zero

let entGet oid =
    let mutable e = 0L
    if acdbGetAdsName(&e, oid) <> ErrorStatus.OK then None
    else
        let res = acdbEntGet &e
        if res = IntPtr.Zero then None
        else ResultBuffer.Create(res, true) |> Some
   
let test (dic: string) (key: string) =
    let doc = Application.DocumentManager.MdiActiveDocument
    let db = doc.Database
    let ed = doc.Editor
    use tr = db.TransactionManager.StartTransaction()
    let nod = tr.GetObject(db.NamedObjectsDictionaryId, OpenMode.ForRead) :?> DBDictionary
    if nod.Contains dic then
        let ld = tr.GetObject(nod.GetAt dic, OpenMode.ForRead) :?> DBDictionary
        if ld.Contains key then
            entGet(ld.GetAt key)
            |> Option.iter(fun rb ->
                for tv in rb do
                    ed.WriteMessage("\n{0} {1} ", tv.TypeCode, tv.Value)
                rb.Dispose() )
    tr.Commit()
       
[<CommandMethod "TEST">]
let testCmd() =
    let ed = Application.DocumentManager.MdiActiveDocument.Editor
    let psr1 = ed.GetString "dict name"
    if psr1.Status = PromptStatus.OK then
        let psr2 = ed.GetString "key name"
        if psr2.Status = PromptStatus.OK then
            test psr1.StringResult psr2.StringResult 

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: reading ldata from .NET
« Reply #3 on: August 15, 2011, 05:17:27 PM »
Quote
Does p/invoke entget count as lisp?
Sure not  :wink:

As AutoLISP is built from ObjectARX, I think all that is available in LISP should also be as with unmanaged ObjectARX.
But IMO, it is easier to use dictionaries and xrecords in LISP than p/invoke unmanaged ObjectARX methods.
Speaking English as a French Frog