栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

python 用ezdxf制作简易cad

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

python 用ezdxf制作简易cad

import matplotlib.pyplot as plt
import ezdxf
from ezdxf.addons.drawing import RenderContext, Frontend
from ezdxf.addons.drawing.matplotlib import MatplotlibBackend
import re
doc = ezdxf.new('R2010')  # create a new DXF R2010 drawing, official DXF version name: 'AC1024'
msp = doc.modelspace()  # add new entities to the modelspace
# 画直线
msp.add_line((0, 0), (10, 0))  # add a LINE entity
# 画粗线
points = [(0, 10, 0, .05), (3, 10, .1, .2, -.5), (6, 10, .1, .05), (9, 0)]
msp.add_lwpolyline(points)
# 画曲线
fit_points = [(0, 0, 0), (7.5, 5.0, 0), (17.5, 5.0, 0), (22.5, 12.5, 0)]
msp = doc.modelspace()
spline = msp.add_spline(fit_points)


# 图像显示
default_img_format = '.png'
default_img_res = 100
default_bg_color = '#000000'  # Black
name="temp.dxf"
msp = doc.modelspace()
# Recommended: audit & repair DXF document before rendering
auditor = doc.audit()
# The auditor.errors attribute stores severe errors,
# which *may* raise exceptions when rendering.
if len(auditor.errors) != 0:
    raise Exception("The DXF document is damaged and can't be converted!")
else:
    fig = plt.figure()
    ax = fig.add_axes([0, 0, 1, 1])
    ctx = RenderContext(doc)
    ctx.set_current_layout(msp)
    ezdxf.addons.drawing.properties.MODEL_SPACE_BG_COLOR = default_bg_color
    out = MatplotlibBackend(ax)
    Frontend(ctx, out).draw_layout(msp, finalize=True)
    plt.show()
    # 图像保存
    # img_name = re.findall("(S+).", name)  # select the image name that is the same as the dxf file name
    # first_param = ''.join(img_name) + default_img_format  # concatenate list and string
    # fig.savefig(first_param, dpi=default_img_res)

    print(name, " Converted Successfully")

 参考:python:ezdxf——教程_face丶的博客-CSDN博客_ezdxf

Python将DXF文件转换为PDF或PNG或JPEG-python黑洞网

GitHub - Hamza442004/DXF2img: A tool to convert dxf files to images

Insert — ezdxf 0.18b4 documentation

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/929556.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号