autocad支持python吗_使用Python自动化AutoCAD

1586010002-jmsa.png

I'm very new to Python and AutoCAD so please bear with me. I'm trying to use Python to automate a design cycle in AutoCAD. So far I am able to add points and lines in AutoCAD via Python but I want to be able to change the linetype to a dotted line. I understand that this can be done in the command bar in AutoCAD with a few simple commands but I can't work out how to do it through Python.

import array

from _ast import If

import comtypes.client

import pyautocad

#Get running instance of the AutoCAD application

acad = comtypes.client.GetActiveObject("AutoCAD.Application")

# Document object

doc = acad.ActiveDocument

#Get the ModelSpace object

ms = doc.ModelSpace

#In ModelSpace

#Set up A4 Space

pt1 = array.array('d', [0.0, 0.0, 0])

pt2 = array.array('d', [210.0, 0.0, 0])

pt3 = array.array('d', [210.0, 297.0, 0])

pt4 = array.array('d', [0.0, 297.0, 0])

line1 = ms.AddLine(pt1, pt2)

line2 = ms.AddLine(pt2, pt3)

line3 = ms.AddLine(pt3, pt4)

line4 = ms.AddLine(pt4, pt1)

#Add central fold

pt5 = array.array('d', [105.0, 0.0, 0])

pt6 = array.array('d', [105.0, 297.0, 0])

line5 = ms.AddLine(pt5, pt6)

print("Done.")

This produces an A4 sized rectangle with a solid dividing line, but I want a dotted line. Any idea where I can find some information on using Python with AutoCAD? Any help is greatly appreciated!

解决方案

Try doing this to change the line type of line5:

line5.linetype = 'dot'

Please make sure to add (load) the line type used (i.e. DOT in this case) in the list of linetype manager.

You can change the linetype scale by:

line5.linetypescale = '0.01'

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值