Author Topic: Setting XRecord  (Read 5133 times)

0 Members and 1 Guest are viewing this topic.

MP

  • Seagull
  • Posts: 17446
Re: Setting XRecord
« Reply #15 on: July 18, 2006, 11:47:07 AM »
Alternative ...

Code: [Select]
Function AddXRec(ByRef XrecName As String, _
                 DataType       As Variant, _
                 Data           As Variant) as AcadXRecord

    Dim dict As AcadDictionary, _
        xrec As AcadXRecord
   
    Set dict = ThisDrawing.Dictionaries.Add("VBAtoLisp")
    Set xrec = dict.AddXRecord(xrecName)
   
    Call xrec.SetXRecordData(dataType, data)

    Set AddXRec = xrec

End Function

Code: [Select]
Sub Test ( )

    Dim xrecName As String, _
        dataType As Variant, _
        data     As Variant, _
        result   As AcadXRecord
   
    ReDim dataType(0 To 0) As Integer
    ReDim data(0 To 0) As Variant
   
    xrecName    = "Test"
    dataType(0) = 1
    data(0)     = "asd"
   
    Set result = AddXRec(xrecName, dataType, data)
   
    ''  do other stuff with result ...   
   
End Sub

Edit: Fixed the return value.
« Last Edit: July 18, 2006, 11:52:36 AM by MP »
\|// Set goal. Experiment tirelessly until
|Oo| practice has become expertise.  Loop.
|- | LinkedIn | Dropbox

MP

  • Seagull
  • Posts: 17446
Re: Setting XRecord
« Reply #16 on: July 18, 2006, 11:51:03 AM »
You could even go as concise as this, tho I probably would use the previous variant --

Code: [Select]
Function AddXRec(ByRef xrecName As String, _
                 dataType       As Variant, _
                 data           As Variant) As AcadXRecord

    Dim xrec As AcadXRecord
   
    Set xrec = ThisDrawing.Dictionaries.Add("VBAtoLisp").AddXRecord(xrecName)
   
    Call xrec.SetXRecordData(dataType, data)

    Set AddXRec = xrec

End Function
\|// Set goal. Experiment tirelessly until
|Oo| practice has become expertise.  Loop.
|- | LinkedIn | Dropbox

T.Willey

  • Needs a day job
  • Posts: 5218
Re: Setting XRecord
« Reply #17 on: July 18, 2006, 12:06:54 PM »
Thanks Michael.  Your code worked, now I'm lost why it does and mine doesn't.  Even if I change my to call out the DictCol variable to be and AcadDictionary like yours does.  Do you/anyone know why?
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

Jeff_M

  • King Gator
  • Posts: 3944
  • C3D user & customizer
Re: Setting XRecord
« Reply #18 on: July 18, 2006, 12:07:32 PM »
Well, Michael beat me to it, but since I was going to post it I still will :-)
Code: [Select]
Option Explicit

Public Sub AddXRec(ByRef XrecName As String, DataType() As Integer, Data() As Variant)

Dim DictCol As AcadDictionaries
Dim MyDict As AcadDictionary
Dim Xrec As AcadXRecord

Set DictCol = ThisDrawing.Dictionaries
Set MyDict = DictCol.Add("VBAtoLisp")
Set Xrec = MyDict.AddXRecord(XrecName)
Xrec.SetXRecordData DataType, Data


End Sub
Public Sub Main(ByRef Str1 As String, Str2 As String)

Dim DataType(1) As Integer
Dim Data(1) As Variant

Data(0) = Str1
Data(1) = Str2
DataType(0) = 1
DataType(1) = 2

AddXRec "VBAtoLisp", DataType, Data

End Sub

Sub test()
Main "MyString1", "MyString2"
End Sub

T.Willey

  • Needs a day job
  • Posts: 5218
Re: Setting XRecord
« Reply #19 on: July 18, 2006, 12:12:59 PM »
My code was wrong from the very beginning.  I wrote this line wrong, it could have saved us all a lot of problems, but as it is I learened alot.  Thanks to all.

Code: [Select]
Set DictCol = This.Drawing.Dictionaries
should be (without the period between This Drawing)
Code: [Select]
Set DictCol = ThisDrawing.Dictionaries
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

T.Willey

  • Needs a day job
  • Posts: 5218
Re: Setting XRecord
« Reply #20 on: July 18, 2006, 12:16:07 PM »
That wasn't the only problem now that I test it.  I guess you need to be as specific when declaring what the type of variables you are using, like you guys had.

Thanks again.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

DaveW

  • Guest
Re: Setting XRecord
« Reply #21 on: July 18, 2006, 01:07:23 PM »
Just as an FYI.

My understanding is that you can also use xrecord at the entity level, not just the drawing level. I am not sure how it is done, and I hear few use it, but it can be good way to get around the size limitations of xdata and assists in hiding data. I am not familar with the code that does this or I would have shared it.

T.Willey

  • Needs a day job
  • Posts: 5218
Re: Setting XRecord
« Reply #22 on: July 18, 2006, 01:10:26 PM »
Just as an FYI.

My understanding is that you can also use xrecord at the entity level, not just the drawing level. I am not sure how it is done, and I hear few use it, but it can be good way to get around the size limitations of xdata and assists in hiding data. I am not familar with the code that does this or I would have shared it.
I have done one code (lisp) that uses the entity's dictionary.  I used the GetExtentionDictionary method on the object.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

MP

  • Seagull
  • Posts: 17446
Re: Setting XRecord
« Reply #23 on: July 18, 2006, 01:15:26 PM »
I have done one code (lisp) that uses the entity's dictionary.  I used the GetExtentionDictionary method on the object.

Yep / Agreed, and there are other objects (i.e. non graphical) you can use as xdictionary hosts as well.

An aside, if you want the xdictionary to survive purging / wblocking et al. make it hard owned, as noted here (sorry, written in LISP).

:)
\|// Set goal. Experiment tirelessly until
|Oo| practice has become expertise.  Loop.
|- | LinkedIn | Dropbox

T.Willey

  • Needs a day job
  • Posts: 5218
Re: Setting XRecord
« Reply #24 on: July 18, 2006, 01:28:42 PM »
This might be the problem:
Quote
Set DictCol = This.Drawing.Dictionaries

should be

Code: [Select]
Set DictCol = ThisDrawing.Dictionaries



That was one, but others were found after reading how the others coded theirs.  Thanks, you should have chimed in sooner.   :wink: :roll:


(no offsense intended)
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

Chuck Gabriel

  • Guest
Re: Setting XRecord
« Reply #25 on: July 18, 2006, 01:37:05 PM »
This might be the problem:
Quote
Set DictCol = This.Drawing.Dictionaries

should be

Code: [Select]
Set DictCol = ThisDrawing.Dictionaries



That was one, but others were found after reading how the others coded theirs.  Thanks, you should have chimed in sooner.   :wink: :roll:


(no offsense intended)

You were too fast for me. :-)  I posted that, not realizing the discussion continued beyond page one, and then deleted it about 15 seconds later (which appears to have been about 14 seconds too late).


T.Willey

  • Needs a day job
  • Posts: 5218
Re: Setting XRecord
« Reply #26 on: July 18, 2006, 01:48:42 PM »
This might be the problem:
Quote
Set DictCol = This.Drawing.Dictionaries

should be

Code: [Select]
Set DictCol = ThisDrawing.Dictionaries



That was one, but others were found after reading how the others coded theirs.  Thanks, you should have chimed in sooner.   :wink: :roll:


(no offsense intended)

You were too fast for me. :-)  I posted that, not realizing the discussion continued beyond page one, and then deleted it about 15 seconds later (which appears to have been about 14 seconds too late).


If it's a thread I start, I try to keep an eye on it, :wink: and as I'm just learning, all post are welcomed.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.