python对 CAD图斑面积的统计及标注
import win32com.client
import pythoncom
import tkinter as tk
from tkinter import filedialog, messagebox
import numpy
from tkinter import ttk'''打开选择文件夹对话框'''
window = tk.Tk()
window.title("CAD标注及面积统计 by: 放放风")
window.geometry('720x300+800+200') # 290 160为窗口大小,+1000 +10 定义窗口弹出时的默认展示位置window.resizable( 0, 0 )
window['background'] = 'DimGray'r_value = tk.IntVar()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)def list_format_conversion(old_list, step=2, deduction=None):new_list = []for counte in range(0, len(old_list), step):new_list.append(list(old_list[counte:counte + step])[:deduction])return new_listdef rrd(point, f):if f == 0:point = str(int(point))elif f > 0:SP = str(numpy.around(point, f))sy = SP.split(".")n = len(sy[1])if n < f:sj = f - npoint = sy[0] + "." + sy[1] + "0" * sjelse:point = SPelif f < 0:tk.messagebox.showinfo('提示', "取位不可为负")return pointclass Extract:def __init__(self):self.face_properties = []self.r = Nonedef r_print(self): # 获取单选框值self.r = r_value.get()def Select_element(self):acad = win32com.client.Dispatch("AutoCAD.Application")doc = acad.ActiveDocumentdoc.Utility.Prompt("\n醉后不知天在水\n满船清梦压星河\n")mp = doc.ModelSpace # 模型空间tk.messagebox.showinfo('提示', "请在屏幕拾取图元,以Enter键结束")polyline_name = text1_var.get()polyline_number = text2_var.get()polyline_mm_round = text3_var.get() # 平方米保留位数polyline_mu_round = text4_var.get() # 亩保留位数font_size = text5_var.get()font_height = text6_var.get()mm_Company = text7_var.get()Mu_Company = text8_var.get()while True:try:doc.SelectionSets.Item("SS1").Delete()except:tk.messagebox.showinfo('警告', "Delete selection failed")slt = doc.SelectionSets.Add("SS1")slt.SelectOnScreen()Text_point = doc.Utility.GetPoint() # 获取屏幕指定坐标Text_point_number = vtpnt(Text_point[0], Text_point[1]) # 转为cad坐标格式,编号坐标Text_point_area = vtpnt(Text_point[0], Text_point[1] - font_height) # 平方米/亩标注坐标for x in slt:if x.ObjectName == "AcDbPolyline":Polygon_area = x.Area # 多边形面积Polygon_Mu_area = Polygon_area / 666.6666666667Polygon_area = str(rrd(Polygon_area, polyline_mm_round)) + mm_Company #Polygon_Mu_area = str(rrd(Polygon_Mu_area, polyline_mu_round)) + Mu_Company #polyline_text_number = polyline_name + str(polyline_number) # 前缀+编号tree.insert("", "end", text=polyline_number,values=(polyline_text_number, Polygon_area, Polygon_Mu_area))self.face_properties.append([polyline_text_number, "\t", Polygon_area, "\t", Polygon_Mu_area, "\n"]) # {编号:多边形平方米面积}mp.AddText(polyline_text_number, Text_point_number, font_size) # 添加编号注记if self.r == 2:mp.AddText(Polygon_area, Text_point_area, font_size) # 添加平方米注记elif self.r == 3:mp.AddText(Polygon_Mu_area, Text_point_area, font_size) # 添加亩注记polyline_number += 1def save_text(self):Save_path = filedialog.askdirectory()new_filer = open(Save_path + "/面积汇总.txt", "w")new_lines = ["地块编号", "\t", "平方米", "\t", "亩", "\n"]new_filer.writelines(new_lines)for items in self.face_properties:new_filer.writelines(items)new_filer.close()messagebox.showinfo("提示", "成功")objectA = Extract()
tk.Button(window, text="拾取及标注", width=15, height=1, command=objectA.Select_element, bg="Silver").grid(row=8, column=3)
tk.Button(window, text="导出文本", width=15, height=1, command=objectA.save_text, bg="Silver").grid(row=8, column=4)tree = ttk.Treeview(window, height=12, show="headings")
tree.grid(row=0, column=3, rowspan=8, columnspan=2)
tree["columns"] = ("Num", "Area(m2)", "Area(Mu)")tree.column("Num", width=150)
tree.column("Area(m2)", width=150)
tree.column("Area(Mu)", width=150)tree.heading("Num", text="编号")
tree.heading("Area(m2)", text="面积(m²)")
tree.heading("Area(Mu)", text="面积(Mu)")lable0 = tk.Label(window, text="[ 文本属性 ]", width=38).grid(row=0, column=0, columnspan=2)lable1 = tk.Label(window, text="[ 编号前缀 ]", width=15).grid(row=1, column=0)text1_var = tk.StringVar() # 获取text_1输入的值
text1_var.set("地块")
text1 = tk.Entry(window, textvariable=text1_var, bd=5).grid(row=1, column=1)lable2 = tk.Label(window, text="[编号起始位置]", width=15).grid(row=2, column=0)
text2_var = tk.IntVar() # 获取text_2输入的值
text2_var.set("1")
text2 = tk.Entry(window, textvariable=text2_var, bd=5).grid(row=2, column=1)tk.Radiobutton(window, text='[平方米]', variable=r_value, value=2, command=objectA.r_print, width=12).grid(row=3, column=0)
lable3 = tk.Label(window, text="[保留位数]", width=15).grid(row=4, column=0)
text3_var = tk.IntVar() # 获取text_3输入的值
text3_var.set("2")
text3 = tk.Entry(window, textvariable=text3_var, bd=5).grid(row=4, column=1)text7_var = tk.StringVar() # 获取text_3输入的值
text7_var.set(r"平方米")
text7 = tk.Entry(window, textvariable=text7_var, bd=5).grid(row=3, column=1)tk.Radiobutton(window, text='[ 亩 ]', variable=r_value, value=3, command=objectA.r_print, width=12).grid(row=5,column=0)
lable4 = tk.Label(window, text="[保留位数]", width=15).grid(row=6, column=0)
text4_var = tk.IntVar() # 获取text_3输入的值
text4_var.set("3")
text4 = tk.Entry(window, textvariable=text4_var, bd=5).grid(row=6, column=1)text8_var = tk.StringVar() # 获取text_3输入的值
text8_var.set(r"亩")
text8 = tk.Entry(window, textvariable=text8_var, bd=5).grid(row=5, column=1)lable5 = tk.Label(window, text="[注记大小]", width=15).grid(row=7, column=0)
text5_var = tk.IntVar() # 获取text_3输入的值
text5_var.set("1.5")
text5 = tk.Entry(window, textvariable=text5_var, bd=5).grid(row=7, column=1)lable6 = tk.Label(window, text="[注记间隔]", width=15).grid(row=8, column=0)
text6_var = tk.IntVar() # 获取text_3输入的值
text6_var.set("2.5")
text6 = tk.Entry(window, textvariable=text6_var, bd=5).grid(row=8, column=1)window.mainloop()
python对 CAD图斑面积的统计及标注相关推荐
- python 给CAD图形标注面积,可批量
python 给CAD图形标注面积,可批量 ########################## import win32com.client as win32#输出dwg文件 import nump ...
- 划痕实验 迁移面积自动统计_从Jupyter迁移到合作实验室
划痕实验 迁移面积自动统计 If you want to use Google Colaboratory to perform your data analysis, for building dat ...
- arcmap中图斑面积代表_【干货】ArcGIS四种计算图斑面积的方法
用精细的过程管理模式提供优质的服务 用先进的地理信息技术推动社会的发展 ArcGIS中有多种方法可计算出图斑面积 本文总结了四种方法 01 计算几何 本人认为这是最适合非专业人士的方法,直接利用Arc ...
- arcmap中图斑面积代表_使用Arcgis计算土地利用现状图图斑面积
使用 Arcgis 计算土地利用现状图图斑面积步骤 一. CAD 图形处理 处理原则:所画地类界线与外围范围线能够围成闭合的区域,每个区域内均包 含一个地类符号或地类名称 将 .dwg 文件导入到 A ...
- python写cad命令_pyautocad 的一些简单操作指令
最近一段时间在学习使用python控制autocad的一些简单指令 通过一些资料的查阅 整理了一些简单的命令及简单的绘图指令 基础设置 连接cad from pyautocad import Auto ...
- python 图表_Python入门学习系列——使用Python调用Web API实现图表统计
使用Python调用Web API实现图表统计 Web API:Web应用编程接口,用于URL请求特定信息的程序交互,请求的数据大多以非常易于处理的格式返回,比如JSON或CSV等. 本文将使用Pyt ...
- Python使用matplotlib可视化面积图(Area Chart)、通过给坐标轴和曲线之间的区域着色可视化面积图、在面积图的指定区域添加箭头和数值标签
Python使用matplotlib可视化面积图(Area Chart).通过给坐标轴和曲线之间的区域着色可视化面积图.在面积图的指定区域添加箭头和数值标签 目录
- Python:利用collections库实现统计单个字或单个字母的频率统计并进行降序输出、统计一个列表内重复元素并以字典形式输出
Python:利用collections库实现统计单个字或单个字母的频率统计并进行降序输出.统计一个列表内重复元素并以字典形式输出 目录 利用collections库实现统计单个字或单个字母的频率统计 ...
- python提取cad坐标到excel_使用python来操作autocad,并且将坐标点转换成cad可见对象...
由于工作需要,在项目中遇到一个棘手的问题,如何将(mssql)数据库中的BLOB文件转成cad可见图形 (可能每个项目需求不一样,解决方式不同) 第一步 . 需要转换的图形类型 第二步 . 那我们先查 ...
最新文章
- Operations Manager 2007 R2系列之单台性能视图
- 第五周项目一-三角形类雏形(1)
- POI的入门:加载解析Excel
- [剑指offer]面试题8:旋转数组的最小数字
- 字符设备驱动基础篇2——用开发板来调试驱动模块的步骤
- 【面试】c++单例模式
- centos7 安装mysql8
- 二分图匹配的判断+p1322+二分图最大匹配+tyvj1035
- Django后端项目----restful framework 认证源码流程
- Careercup - Microsoft面试题 - 5680049562845184
- 《码出高效:Java开发手册》百度网盘下载
- java 依赖倒置_Java设计原则—依赖倒置原则(转)
- 【斗鱼直播源】浏览器抓取真实直播源地址(纯前端JS PHP解析源码)
- PHPstudy mysql secure_file_priv 设置
- python文本字词分割及词库云
- Router接口及连接
- Crow search algorithm(乌鸦搜索算法)
- 常见bootloader介绍
- 电脑计算器所有快捷键
- 手机网站开发必修课[1]:手机浏览器