Hi On Tue, Jul 8, 2008 at 9:18 PM, Kelie <[EMAIL PROTECTED]> wrote: > Hello group, > > I posted the following question on Python Tutor mailing list and haven't been > able to solve the problem. This is probably a more appropriate list for my > question: > > I'm trying to translate the following VB code into Python and not sure how to > create an array of variants. > > Thanks for your help! > > VB Code: > Sub SetXdata() > Dim lineObj As AcadLine > Set lineObj = ThisDrawing.ModelSpace.Item(0) > > Dim DataType(0 To 1) As Integer > Dim Data(0 To 1) As Variant > > DataType(0) = 1001: Data(0) = "Test_Application" > DataType(1) = 1070: Data(1) = 600 > > lineObj.SetXdata DataType, Data > End Sub > > Python code: > import array > import comtypes.client > > def SetXData(): > activedoc = > comtypes.client.GetActiveObject("AutoCAD.Application").ActiveDocument > line = activedoc.ModelSpace.Item(0) > > dataType = array.array('i', [1001, 1070]) > dataValue = array.array('?', ['Test_Application', 600]) #What should I use > for the type code here? > > line.SetXData(dataType, dataValue) > > if __name__ == "__main__": > SetXData() > AFAIK comtypes automatically converts lists to COM arrays and you can get variant using following statement: from comtypes.automation import VARIANT
So following should work line.SetXData([1001, 1070], [VARIANT('Test_Application'), VARIANT(600)]) I have found comtypes very intelligent when it comes to data types. You should also try above statement without VARIANT and see if it works. Regards, Suraj ------------------------------------------------------------------------- Sponsored by: SourceForge.net Community Choice Awards: VOTE NOW! Studies have shown that voting for your favorite open source project, along with a healthy diet, reduces your potential for chronic lameness and boredom. Vote Now at http://www.sourceforge.net/community/cca08 _______________________________________________ comtypes-users mailing list comtypes-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/comtypes-users