passing late bound variant array to group

passing late bound variant array to group

Anonymous
Not applicable
498 Views
0 Replies
Message 1 of 1

passing late bound variant array to group

Anonymous
Not applicable

I have some code that needs to late bind to AutoCAD ActiveX from VB Net (so that it works over many AutoCAD versions)

 

Most of the code works OK, but I am having difficulty adding entities to a group
I believe the problem is in the marshaling of the variant array.

Any suggestions on how to get this working?

 

'works correctly when using  early binding

Dim mygroup as AcadGroup
Dim mylist() as AcadEntity

mygroup = GroupColl.Add("Test 1")

redim mylist(0)
mylist(0) =   ActiveDocument.ModelSpace.AddLine(New Double() {0, 0, 0}, New Double() {1, 1, 1})

mygroup.AppendItems(mylist)

 


'fails using late binding, with error at AppendItems of "Invalid object array"

Dim mygroup as Object
Dim mylist() as Object         ' or Dim mylist as Object

mygroup = GroupColl.Add("Test 1")

redim mylist(0)
mylist(0) =   ActiveDocument.ModelSpace.AddLine(New Double() {0, 0, 0}, New Double() {1, 1, 0})

mygroup.AppendItems(mylist)


'have also tried  (following suggestions from MLeslie00 on this forum)

 

mygroup.AppendItems(MarshalVariantArray (mylist))

 

Public Function MarshalVariantStringArray(ByVal ObjIn AsObject) _
               As <Runtime.InteropServices.MarshalAsAttribute( _
                                   Runtime.InteropServices.UnmanagedType.SafeArray, _
                                   SafeArraySubType:=Runtime.InteropServices.VarEnum.VT_VARIANT)> Object

       ReturnObjIn
End Function

0 Likes
499 Views
0 Replies
Replies (0)