TheSwamp
Code Red => .NET => Topic started by: jsr 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.
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.
-
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.
-
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 (http://www.theswamp.org/index.php?topic=32111.msg375860;topicseen#msg375860). This is in F#, where I like the alternative syntax for extern declarations:
[<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
-
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.