autocad支持python吗_pyautocad是否需要运行的autoCad软件?

这是我运行的脚本。使用此库pyautocad是否需要运行autocadfrom __future__ import print_function

from os.path import join, dirname, abspath

from xlutils.copy import copy

import xlrd

import xlwt

from pyautocad import Autocad, APoint

import os

import win32com.client

from pyautocad import Autocad, APoint

from pyautocad.contrib.tables import Table

#Create workbook

book = xlwt.Workbook()

ws = book.add_sheet("ExportedData")

book.save("Exported.xls")

#Open the workbook

xl_workbook = xlrd.open_workbook("Exported.xls")

sheet_names = xl_workbook.sheet_names()

xl_sheet = xl_workbook.sheet_by_name(sheet_names[0])

wb = copy(xl_workbook)

sheet = wb.get_sheet(0)

dwgfiles = filter(os.path.isfile, os.listdir( os.curdir ) )

cwd = os.path.abspath(os.path.curdir) #current working dir

for f in dwgfiles:

print(f)

if f.endswith(".dwg"):

print("sdaasdas")

""" open Document"""

acad = Autocad()

print(cwd)

acad.doc.Open(cwd + "/" + f)

print (acad.doc.Name)

num_cols = xl_sheet.ncols # Number of columns

idx = 1

acad = win32com.client.Dispatch("AutoCAD.Application")

doc = acad.ActiveDocument # Document object

print ("MODEL SPACE")

for entity in acad.ActiveDocument.ModelSpace:

name = entity.EntityName

print(name)

if name == 'AcDbText':

sheet.row(idx).write(0,entity.TextString)

sheet.row(idx).write(1,entity.ObjectID)

sheet.row(idx).write(2,cwd + "/" + f)

idx = idx + 1

if name == 'AcDbBlockReference':

HasAttributes = entity.HasAttributes

if HasAttributes:

# print(entity.Name)

# print(entity.Layer)

# print(entity.ObjectID)

for attrib in entity.GetAttributes():

if attrib.TagString != "DATA":

sheet.row(idx).write(0,attrib.TextString )

sheet.row(idx).write(1,entity.ObjectID)

sheet.row(idx).write(2,cwd + "/" + f)

idx = idx + 1

print ("PAPER SPACE")

for entity in acad.ActiveDocument.PaperSpace:

name = entity.EntityName

if name == 'AcDbText':

sheet.row(idx).write(0,entity.TextString)

sheet.row(idx).write(1,entity.ObjectID)

sheet.row(idx).write(2,cwd + "/" + f)

idx = idx + 1

if name == 'AcDbBlockReference':

HasAttributes = entity.HasAttributes

if HasAttributes:

# print(entity.Name)

# print(entity.Layer)

# print(entity.ObjectID)

for attrib in entity.GetAttributes():

if attrib.TagString != "DATA":

sheet.row(idx).write(0,attrib.TextString )

sheet.row(idx).write(1,entity.ObjectID)

sheet.row(idx).write(2,cwd + "/" + f)

idx = idx + 1

doc.Close(False)

acad = None

wb.save("Exported.xls")

当我运行这个脚本时,我得到的是

^{pr2}$

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值