用python批量获取cad中线段点组成的凸包 + 面积
效率实在太低,还是用c# 吧
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107import win32com.client import pythoncom import tubao import gelin from tkinter import filedialog import time import numpy def list_change(old_list, step=4, stop=None): # 列表,步长,保留元素到第几个索引位置 new_list = [old_list[x:x + step][:stop] for x in range( 0, len( old_list ), step )] return new_list def vtpnt(x, y, z=0): """坐标点转化为浮点数""" return win32com.client.VARIANT(pythoncom.VT_ARRAY | pythoncom.VT_R8, (x, y, z)) def vtobj(obj): """转化为对象数组""" return win32com.client.VARIANT(pythoncom.VT_ARRAY | pythoncom.VT_DISPATCH, obj) def vtFloat(list): """列表转化为浮点数""" return win32com.client.VARIANT(pythoncom.VT_ARRAY | pythoncom.VT_R8, list) def vtInt(list): """列表转化为整数""" return win32com.client.VARIANT(pythoncom.VT_ARRAY | pythoncom.VT_I2, list) def vtVariant(list): """列表转化为变体""" return win32com.client.VARIANT(pythoncom.VT_ARRAY | pythoncom.VT_VARIANT, list) start =time.clock() f = open( "are.txt", "a+" ) acad = win32com.client.Dispatch( "AutoCAD.Application" ) # doc = acad.ActiveDocument docs = acad.Documents # AutoCAD图形的集合 paths = filedialog.askopenfilenames( filetypes=[("文本", "dwg")], title="选择数据" ) for path in paths: doc = docs.Open( path, False ) # 打开现有图形文件(DWG)并将其设为活动的文档,Document 对象 # count = docs.Count #获取图形集合个数 # doc.AuditInfo(False) # T修复所有图形错误,F不修复所有图形错误 doc.ActiveSelectionSet.Clear() mp = doc.ModelSpace # sd1 = doc.Layers.Add("new_layer") # 添加图层 # # doc.ActiveLayer = sd1 # 激活添加的图层 try: doc.SelectionSets.Item( "ss1" ).Delete() # 删除指定的选择集 except: doc.Utility.Prompt( "n醉后不知天在水n满船清梦压星河n" ) v = doc.SelectionSets.Add( "ss1" ) # 添加名字为sd的选择集 FilterType = vtInt([0]) FData = vtVariant(["TEXT"]) v.Select( 5 ,"","",FilterType,FData) ''' https://blog.csdn.net/zhd18/article/details/78726469/ 全选 acSelectionSetAll = 5 ,tmd AcSelect 常数第五个 FilterType 0 图元类型 8 图层 FDdata 图元类型: 图层名称: ''' # s = v.name #选择集的名称 # point_1 = vtpnt(0,10,0) # point_2 = vtpnt(500,1000,0) # mp.Polyline(point_1,point_2) #添加直线 point_3 = sum( [list_change( x.InsertionPoint , step=3,stop=2 ) for x in v ], [] ) # 所有的coordinates print(point_3) new_poinit_3 = list(dict.fromkeys(point_3)) result = tubao.graham_scan( new_poinit_3 ) #多段线 points = numpy.array([m for n in result for m in n], dtype=numpy.float) # 格式转换 polyline_points = vtFloat(points) retVal = mp.AddLightweightPolyline(polyline_points) #绘制多段线 retVal.Closed = True #多段线闭合 are = gelin.compute_polygon_area( result ) f.writelines( [path, ":", str(are),"n"] ) # doc.SendCommand("PL ") #想cad命令行输入命令,命令后加空格结束命令 # doc.SaveAs(r"C:UsersAdministratorDesktopDrawing3.dwg") #另存 # doc.Save() # 保存 doc.Close( False, path ) # 关闭文档 time.sleep( 5 ) f.close() end = time.clock() print('Running time: %s Seconds'%(end-start))
最后
以上就是无聊狗最近收集整理的关于用python批量获取cad中线段点组成的凸包 + 面积的全部内容,更多相关用python批量获取cad中线段点组成的凸包内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复