Python win32com
- import pythoncom
- import win32com.client
- Cad = win32com.client.Dispatch("AutoCAD.Application")
- Uti = Cad.ActiveDocument.Utility
- def pt(x, y, z=0):
- return win32com.client.VARIANT(pythoncom.VT_ARRAY | pythoncom.VT_R8, (x, y, z))
- def dist(pt1, pt2):
- x1 = pt1[0]; y1 = pt1[1]; x2 = pt2[0]; y2 = pt2[1]
- return ((x2 - x1)**2 + (y2 - y1)**2)**0.5
- dd = 0
- pt1 = Uti.GetPoint(pt(0,0),"First point: ")
- while True:
- pt2 = Uti.GetPoint(pt(pt1[0], pt1[1]), "Next point >>> ")
- dd += dist(pt1, pt2)
- Uti.Prompt("Total Dist= " + str(dd) + "\n\r")
- pt1 = pt2
|