pyautocad_hatch

在这里插入图片描述

#!/usr/bin/env python
# -*- coding: utf-8 -*-
import pythoncom
import win32com.client
wincad = win32com.client.Dispatch("AutoCAD.Application.23")
doc = wincad.ActiveDocument
doc.Utility.Prompt("Hello! AutoCAD from pywin32.")
msp = doc.ModelSpace
print(doc.Name)
def vtobj(obj):
    return win32com.client.VARIANT(pythoncom.VT_ARRAY | pythoncom.VT_DISPATCH, obj)

def vtfloat(lst):
    return win32com.client.VARIANT(pythoncom.VT_ARRAY | pythoncom.VT_R8, lst)

[ptnName, ptnType, bAss] = ["ANSI31", 1, True]

pnts = [100, -50, 0, 100, 50, 0, -100, 50, 0, -100, -50, 0]
pnts = vtfloat(pnts)

plineObj = msp.AddPolyLine(pnts)
plineObj.Closed = True

outerLoop = []
outerLoop.append(plineObj)
outerLoop = vtobj(outerLoop)

hatchObj = msp.AddHatch(ptnType, ptnName, bAss)
hatchObj.AppendOuterLoop(outerLoop)
hatchObj.Evaluate()  # 填充,图案吻合于边界。

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

#!/usr/bin/env python
# -*- coding: utf-8 -*-
import pythoncom
import win32com.client
from openpyxl import load_workbook
# 建立连接
wincad = win32com.client.Dispatch("AutoCAD.Application.23")
doc = wincad.ActiveDocument
mp=doc.ModelSpace
print(doc.Name)
# 读取表格数据集
wb=load_workbook("shuju.xlsx")
ws=wb.get_sheet_by_name('Sheet1')
pnts=[ws.cell(row=i+4,column=j+3).value for i in range(25) for j in range(3)]
print(pnts)

# 绘制
pnts=win32com.client.VARIANT(pythoncom.VT_ARRAY | pythoncom.VT_R8,pnts) #转化为浮点数"""
pline_obj=mp.AddPolyLine(pnts)
outerLoop=win32com.client.VARIANT(pythoncom.VT_ARRAY|pythoncom.VT_DISPATCH,[pline_obj])#"""转化为对象数组"""

hatchobj=mp.AddHatch(2,"SOLID",True)
hatchobj.AppendOuterLoop(outerLoop)
hatchobj.Evaluate()
pline_obj.Delete()

clr=doc.Application.GetInterfaceObject("AutoCAD.AcCmColor.23")
clr.SetRGB(0,155,155)
hatchobj.TrueColor=clr

# 数据转换,python数据类型--定义相对简单,进行数据转化是必要的
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)

在这里插入图片描述
在这里插入图片描述

#!/usr/bin/env python
# -*- coding: utf-8 -*-
import pythoncom
import win32com.client
from openpyxl import load_workbook
# 建立连接
wincad = win32com.client.Dispatch("AutoCAD.Application.23")
doc = wincad.ActiveDocument
mp=doc.ModelSpace
print(doc.Name)
# 读取表格数据集
wb=load_workbook("shuju.xlsx")
ws=wb.get_sheet_by_name('Sheet1')

def vtFloat(list):
    """列表转化为浮点数"""
    return win32com.client.VARIANT(pythoncom.VT_ARRAY | pythoncom.VT_R8, list)
def draw_line():
    p1=[ws.cell(row=i+4,column=j+8).value for i in range(1) for j in range(3)]
    print(p1)
    p2 = [ws.cell(row=i + 5, column=j + 8).value for i in range(1) for j in range(3)]
    print(p2)
    # 绘制
    pnts1=win32com.client.VARIANT(pythoncom.VT_ARRAY | pythoncom.VT_R8,p1) #转化为浮点数"""\
    print(pnts1)
    pnts2 = win32com.client.VARIANT(pythoncom.VT_ARRAY | pythoncom.VT_R8, p2)  # 转化为浮点数"""
    # 数据转换,python数据类型--定义相对简单,进行数据转化是必要的


    startPntCoords =vtFloat(p1)# startPntCoords = vtpnt(5, 5)
    startPoint = mp.AddPoint(startPntCoords)#画点

    endPntCoords = vtFloat(p2)
    endPoint = mp.AddPoint(endPntCoords)#画点
    lineObj = mp.AddLine(startPntCoords, endPntCoords)

draw_line()
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值