Reputation: 1389
I need to find a selected text object's coordinates in Autocad with python. For this purpose, i use comtypes. But all i found on the net was about getting the line and polyline objects' coordinates. Can you please supply me with the method i can use for this purpose? or in general, is there any source that i can learn about all attributes of an Autocad object and how i can benefit from them?
Many thanks in advance.
Upvotes: 2
Views: 4142
Reputation: 1342
I'm an old-time AutoCAD user, and I think I can help you with this. It really helps if you have access to AutoCAD. But I think there is a reference somewhere. Try my blog posts:
http://tomsthird.blogspot.com/2009/07/autocad-and-python-part-2.html
http://tomsthird.blogspot.com/2009/07/accessing-autocad-civil-3d-object-model.html
http://tomsthird.blogspot.com/2009/07/autocad-civil-3d-activex-object-model.html
In one of those posts, it looks like I have a link to a reference that's a chm file that comes with AutoCAD. There ought to be better.
Here's how I did it in Visual LISP:
(VLAX-GET-PROPERTY
(VLAX-INVOKE
(VLAX-GET-PROPERTY
(VLAX-GET-PROPERTY (VLAX-GET-ACAD-OBJECT) 'ACTIVEDOCUMENT)
'ACTIVESELECTIONSET
)
'ITEM
0
)
'INSERTIONPOINT
)
I assume that in something like Python you would want to do this:
import win32com.client
acad = win32com.client.Dispatch("AutoCAD.Application")
doc = acad.ActiveDocument
inspoint = doc.ActiveSelectionSet.Item.0.InsertionPoint
If this doesn't work for you, let me know, and we will work something out. I want to see you succeed, and I'd really appreciate it if you could share your finished code snippet here. As you can see from my blog posts, I, too, am interested in learning how to automate AutoCAD using Python. Maybe you can contact me and we can work together.
Upvotes: 5