Daniel,
I've tested a prerelease version of pywin32 that contains the new
win32com.client.VARIANT class and it works well with AutoCAD. Once
released, you can write something like this:
import win32com.client
import pythoncom
def POINT(x,y,z):
return win32com.client.VARIANT(pythoncom.VT_ARRAY | pythoncom.VT_R8,
(x,y,z))
acad = win32com.client.Dispatch('AutoCAD.Application')
ms = acad.ActiveDocument.ModelSpace
ms.AddLine(POINT(0,0,0), POINT(1,1,0))
Additional information in Mark's original post on win32com.client.VARIANT:
http://mail.python.org/pipermail/python-win32/2011-October/011844.html
-drg
On Wed, Feb 1, 2012 at 5:29 PM, DANIEL POSE <[email protected]> wrote:
> I have used array module because it worked with comtypes module. If I use
> simple list it doesn't work with comtypes nor pywin32.
> If I use:
>
> pt1 = [0.0,0.0,0.0]
> pt2 =[1.0,1.0,0.0]
>
> Then Python responds:
>
> <code>
>
> Traceback (most recent call last):
> File "<ipython console>", line 1, in <module>
> File
> "C:\Python27\lib\site-packages\spyderlib\widgets\externalshell\startup.py",
> line 128, in runfile
> execfile(filename, glbs)
> File "C:\Documents and Settings\Administrador\Mis
> documentos\DropboxDani\Dropbox\PYTHON\PruebaAutoCADLinea.py", line 16, in
> <module>
> line = ms.AddLine(pt1, pt2)
>
> File "<COMObject <unknown>>", line 3, in AddLine
> com_error: (-2147352567, 'Ocurri\xf3 una excepci\xf3n.', (0, None, None,
> None, 0, -2147024809), None)
>
> </code>
>
>
> 2012/2/1 Mark Hammond <[email protected]>
>
>> Re-added the python-win32 list - please keep replies on list.
>>
>> Your code uses:
>>
>>
>> > pt1 = array.array('d', [0.0,0.0,0.0])
>> > pt2=array.array('d',[1.0,1.0,_**_0.0])
>>
>> But these aren't supported by pywin32 in the way you expect - what
>> happens if you change this to:
>>
>> pt1 = [0.0,0.0,0.0]
>> pt2 =[1.0,1.0,0.0]
>>
>> ?
>>
>> Mark
>>
>>
>>
>> On 2/02/2012 7:12 AM, DANIEL POSE wrote:
>>
>>> Hello Mark,
>>>
>>> I understand the AutoCAD problem, but in my profession it is the most
>>> extended software for CAD. In my opinion it justify the efford to make
>>> automation tools.
>>> Here I post the answer from Python when I try to draw a line using
>>> win32com.client code in my last mail:
>>>
>>> Traceback (most recent call last):
>>> File "<ipython console>", line 1, in <module>
>>> File
>>> "C:\Python27\lib\site-**packages\spyderlib\widgets\**
>>> externalshell\startup.py",
>>> line 128, in runfile
>>> execfile(filename, glbs)
>>> File "C:\Documents and Settings\Usuario\Escritorio\**borrar.py", line
>>> 15, in <module>
>>> line = ms.AddLine(pt1, pt2) #This draw a line in AutoCAD
>>> File "<COMObject <unknown>>", line 3, in AddLine
>>> com_error: (-2147352567, 'Ocurri\xf3 una excepci\xf3n.', (0, None, None,
>>> None, 0, -2147024809), None)
>>>
>>> Thank you in advance,
>>> Daniel Pose.
>>>
>>> 2012/2/1 Mark Hammond <[email protected]
>>> <mailto:skippy.hammond@gmail.**com <[email protected]>>>
>>>
>>>
>>> Sadly not many people have access to autocad so it is hard to test.
>>> What errors do you get using win32com?
>>>
>>> Mark
>>>
>>>
>>> On 1/02/2012 5:11 AM, DANIEL POSE wrote:
>>>
>>> Hello,
>>>
>>> Recently I try to write some code to automate AutoCAD from
>>> Python. I
>>> have to draw lines from Python using win32com.client module, but I
>>> obtain error. By other hand I solved the problem using comtypes
>>> module.
>>> However, If I try to obtain block attributes information, comtypes
>>> doesn't work but win32com.client work properly.
>>>
>>> AutoCAD attributes working code (work for win32com.client but no
>>> for
>>> comtypes):
>>> [code]
>>> import win32com.client
>>> acad= win32com.client.Dispatch("__**AutoCAD.Application")
>>> doc = acad.ActiveDocument
>>> seleccion=doc.SelectionSets.__**Add('selection1')
>>>
>>> seleccion.SelectOnScreen()
>>> for objeto in seleccion:
>>> if objeto.ObjectName=='__**AcDbBlockReference':
>>> bloque=objeto.GetAttributes()
>>> bloque[0].TagString='__**newattributename' #This change
>>>
>>> the name
>>> for the first attribute in the selected block
>>> [/code]
>>>
>>> Draw line (work for comtypes but doesn't work for
>>> win32com.client):
>>> [code]
>>> import comtypes.client
>>> import array
>>> acad = comtypes.client.__**GetActiveObject("AutoCAD.__**
>>> Application")
>>>
>>> doc = acad.ActiveDocument
>>> ms = doc.ModelSpace
>>> pt1 = array.array('d', [0.0,0.0,0.0])
>>> pt2=array.array('d',[1.0,1.0,_**_0.0])
>>>
>>> line = ms.AddLine(pt1, pt2) #This draw a line in AutoCAD
>>> [\code]
>>>
>>> My question is: Is posible to fix the problem using win32com to
>>> draw
>>> autocad line in order to avoid comtypes use?
>>> I found on the web several coments to the problem, but no
>>> solution.
>>>
>>> Thanks for help,
>>> Daniel Pose.
>>>
>>>
>>> ______________________________**___________________
>>> python-win32 mailing list
>>> [email protected]
>>> <mailto:python-win32@python.**org<[email protected]>
>>> >
>>>
>>> http://mail.python.org/__**mailman/listinfo/python-win32<http://mail.python.org/__mailman/listinfo/python-win32>
>>>
>>> <http://mail.python.org/**mailman/listinfo/python-win32<http://mail.python.org/mailman/listinfo/python-win32>
>>> >
>>>
>>>
>>>
>>>
>>
>
> _______________________________________________
> python-win32 mailing list
> [email protected]
> http://mail.python.org/mailman/listinfo/python-win32
>
>
_______________________________________________
python-win32 mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-win32