精华内容
参与话题
问答
  • 1 Autocad安装 ... 2 pyautocad 如果已安装Anaconda,在 Anaconda Prompt 中输入 pip install pyautocad 即可自动完成库的导入。 3tablib 打开cmd,然后输入 python –m pi...

    1 Autocad安装

    https://jingyan.baidu.com/article/e3c78d6466dc873c4c85f58b.html

    2 pyautocad

    如果已安装Anaconda,在 Anaconda Prompt 中输入 pip install pyautocad 即可自动完成库的导入。

    tablib

     打开cmd,然后输入 python –m pip install tablib即可。

    4 pyautocad的简单使用

    (1)连接正在运行的CAD程序。如果cad未运行,那么程序自动启动CAD,这种情况下,CAD文件采用默认的名称:Drawing1。

             在CAD命令行显示"Hello World!!!",用于测试对CAD的控制是否成功。

    代码如下:

    from pyautocad import Autocad
    
    acad = Autocad(create_if_not_exists=True)
    acad.prompt("Hello World !!!")
    # print(acad.doc.Name)

    结果如下:


        

    (2)新建图层:图层名称为“1_Layer”,并且将这个图层设置为当前的图层。图层颜色的设置:颜色索引号取值范围为[0,256]线型设置:为图层指定线型前,需先加载相关线型然后设置图层线型注意:不能重复加载,会报错。设置图层线宽:13。

    from pyautocad import Autocad
    
    acad = Autocad(create_if_not_exists=True)
    LayerObj = acad.ActiveDocument.Layers.Add("1_Layer")
    acad.ActiveDocument.ActiveLayer = LayerObj
    ClrNum = 2
    LayerObj.color = ClrNum
    acad.ActiveDocument.Linetypes.Load("ACAD_ISO08W100", "acadiso.lin")
    LayerObj.Linetype = "ACAD_ISO08W100"
    LayerObj.Lineweight = 13

    结果如下:

    颜色索引号:https://wenku.baidu.com/view/9d458b70195f312b3069a505.html

     

    展开全文
  • start for pyautocad

    2018-08-12 17:09:48
    Getting started Installation If you have pip or easy_install, you can just:...pip install --upgrade pyautocad or: easy_install -U pyautocad Also, you can download Windows installer from PyPI p...

    Getting started

    Installation

    If you have pip or easy_install, you can just:

    pip install --upgrade pyautocad
    

    or:

    easy_install -U pyautocad
    

    Also, you can download Windows installer from PyPI pyautocad page.

    Requirements

    Retrieving AutoCAD ActiveX documentation

    A copy of the AutoCAD ActiveX guide and reference can be found in the help directory of your AutoCAD install.

    • acad_aag.chm - ActiveX and VBA Developer’s Guide
    • acadauto.chm - ActiveX and VBA Reference

    Reference can also be found in C:\Program Files\Common Files\Autodesk Shared\acadauto.chm

    What’s next?

    Read the Usage section, or look for real applications in examples folder of source distribution.

    Note

    Applications in examples are Russian engineering specific, but anyway I hope you’ll find something interesting in that code.

    For more info on features see API documentation and sources

    ---------------------------------------------------------------------------------------------------------------------------------------------------------------------

    译文如下:

    开始

    安装

    如果你有pip或easy_install,你可以:

    pyautocad pip安装,升级

    或者:

    easy_install - u pyautocad

    另外,您可以从PyPI pyautocad页面下载Windows安装程序。

    需求

    comtypes

    请注意

    如果您正在使用pip或easy_install,那么它将被自动安装。否则,您应该手动安装comtypes包。

    可选:xlrd和tablib用于处理表

    检索AutoCAD ActiveX文档

    AutoCAD ActiveX指南和参考的副本可以在AutoCAD安装的帮助目录中找到。

    acad_aag。chm - ActiveX和VBA开发者指南

    acadauto。chm - ActiveX和VBA引用

    引用也可以发现在\ Autodesk共享\ acadauto.chm C:\Program Files\Common文件

    接下来是什么?

    阅读用法部分,或者在源发行版的example文件夹中查找真正的应用程序。

    请注意

    示例中的应用程序是特定于俄罗斯工程的,但无论如何,我希望您能从中发现一些有趣的东西。

    有关特性的更多信息,请参阅API文档和源代码

    展开全文
  • python:pyautocad

    2020-08-13 15:21:01
    from pyautocad import Autocad, APoint 创建AutoCAD应用程序或连接到已经运行的应用程序: acad = Autocad(create_if_not_exists=True) # 在CAD命令行输出内容 acad.prompt("Hello, Autocad from Python\n") # ...

    一、使用

    1、主接口和类型

    导入相关模块

    from pyautocad import Autocad, APoint
    

    创建AutoCAD应用程序或连接到已经运行的应用程序:

    acad = Autocad(create_if_not_exists=True)
    # 在CAD命令行输出内容
    acad.prompt("Hello, Autocad from Python\n")
    # 输出当前图形文件的名称
    print(acad.doc.Name)
    

    在文档中添加对象:

    p1 = APoint(0, 0)
    p2 = APoint(50, 25)
    for i in range(5):
        text = acad.model.AddText(u'Hi %s!' % i, p1, 2.5)
        acad.model.AddLine(p1, p2)
        acad.model.AddCircle(p1, 10)
        p1.y += 10
    

    迭代文档中的Texts, Lines和Circles对象:

    for obj in acad.iter_objects():
        print(obj.ObjectName)
       
    for text in acad.iter_objects('Text'):
        print(text.TextString, text.InsertionPoint)
    
    for obj in acad.iter_objects(['Text', 'Line']):
        print(obj.ObjectName)
    

    在一定条件下找到第一个对象:

    def text_contains_3(text_obj):
        return '3' in text_obj.TextString
    
    text = acad.find_one('Text', predicate=text_contains_3)
    print(text.TextString)
    

    通过ACAD查找对象并修改属性:

    from pyautocad import ACAD
    
    for text in acad.iter_objects('Text'):
        old_insertion_point = APoint(text.InsertionPoint)
        text.Alignment = ACAD.acAlignmentRight
        text.TextAlignmentPoint = old_insertion_point
    

    更改对象位置:

    for line in acad.iter_objects('Line'):
        p1 = APoint(line.StartPoint)
        line.EndPoint = p1 - APoint(20, 0)
    

    2、处理表

    添加对象并保存到EXCEL中:

    from pyautocad import Autocad, APoint
    from pyautocad.contrib.tables import Table
    
    acad = Autocad()
    p1 = APoint(0, 0)
    for i in range(5):
        obj = acad.model.AddText(u'Hi %s!' % i, p1, 2.5)
        p1.y += 10
    
    table = Table()
    for obj in acad.iter_objects('Text'):
        x, y, z = obj.InsertionPoint
        table.writerow([obj.TextString, x, y, z])
    table.save('C:/Users/liuzhi/Desktop/data.xls', 'xls')
    

    提高AutoCAD表格操作的速度:

    table = acad.model.AddTable(pos, rows, columns, row_height, col_width)
    with suppressed_regeneration_of(table):
        table.SetAlignment(ACAD.acDataRow, ACAD.acMiddleCenter)
        for row in range(rows):
            for col in range(columns):
                table.SetText(row, col, '%s %s' % (row, col))
    

    二、API

    1、AutoCAD主接口

    class pyautocad.api.Autocad(create_if_not_exists=False, visible=True)
    

    参数:
    创建if_NOT_存在-如果AutoCAD不运行,那么新的实例化将被装箱
    可见-如果是True(默认),新的AutoCAD实例将是可见的。

    prompt(文本)
    

    在控制台和AutoCAD提示符

    get_selection(Text=“SelectObjects”)
    

    要求用户选择对象

    pyautocad.types.distance(P1, P2)
    

    返回两点之间的距离P1和P2

    pyautocad.types.aDouble(*seq)
    

    回报array.array为传递到AutoCAD的双倍代码(‘d’代码),对于3D点使用APoint相反。

    pyautocad.types.aInt(*seq)
    

    回报array.array用于传递到AutoCAD的INTS(‘l’代码)

    pyautocad.types.aShort(*seq)
    

    回报array.array传递到AutoCAD的简写(h‘代码)

    展开全文
  • 主要介绍了Python使用pyautocad+openpyxl处理cad文件,结合实例形式分析了Python使用pyautocad与openpyxl模块读写cad文件相关应用操作技巧,需要的朋友可以参考下
  • pyautocad-api

    千次阅读 2018-08-12 17:14:17
    api - Main Autocad ...class pyautocad.api.Autocad(create_if_not_exists=False, visible=True)[source] Main AutoCAD Automation object Parameters: create_if_not_exists – if AutoCAD doesn’...

    api - Main Autocad interface

    class pyautocad.api.Autocad(create_if_not_exists=False, visible=True)[source]

    Main AutoCAD Automation object

    Parameters:
    • create_if_not_exists – if AutoCAD doesn’t run, then new instanse will be crated
    • visible – new AutoCAD instance will be visible if True (default)

    app

    Returns active AutoCAD.Application

    if Autocad was created with create_if_not_exists=True, it will create AutoCAD.Application if there is no active one

    doc

    Returns ActiveDocument of current Application

    ActiveDocument

    Same as doc

    Application

    Same as app

    model

    ModelSpace from active document

    iter_layouts(doc=None, skip_model=True)[source]

    Iterate layouts from doc

    Parameters:
    • doc – document to iterate layouts from if doc=None (default), ActiveDocument is used
    • skip_model – don’t include ModelSpace if True

    iter_objects(object_name_or_list=None, block=None, limit=None, dont_cast=False)[source]

    Iterate objects from block

    Parameters:
    • object_name_or_list – part of object type name, or list of it
    • block – Autocad block, default - ActiveDocument.ActiveLayout.Block
    • limit – max number of objects to return, default infinite
    • dont_cast – don’t retrieve best interface for object, may speedup iteration. Returned objects should be casted by caller

    iter_objects_fast(object_name_or_list=None, container=None, limit=None)[source]

    Shortcut for iter_objects(dont_cast=True)

    Shouldn’t be used in normal situations

    find_one(object_name_or_list, container=None, predicate=None)[source]

    Returns first occurance of object which match predicate

    Parameters:
    • object_name_or_list – like in iter_objects()
    • container – like in iter_objects()
    • predicate – callable, which accepts object as argument and returns True or False
    Returns:

    Object if found, else None

    best_interface(obj)[source]

    Retrieve best interface for object

    prompt(text)[source]

    Prints text in console and in AutoCAD prompt

    get_selection(text='Select objects')[source]

    Asks user to select objects

    Parameters: text – prompt for selection

    static aDouble(*seq)

    shortcut for pyautocad.types.aDouble()

    static aInt(*seq)

    shortcut for pyautocad.types.aInt()

    static aShort(*seq)

    shortcut for pyautocad.types.aShort()

    pyautocad.api.ACAD

    Constants from AutoCAD type library, for example:

    text.Alignment = ACAD.acAlignmentRight
    

    types - 3D Point and other AutoCAD data types

    class pyautocad.types.APoint[source]

    3D point with basic geometric operations and support for passing as a

    parameter for AutoCAD Automation functions

    Usage:

    >>> p1 = APoint(10, 10)
    >>> p2 = APoint(20, 20)
    >>> p1 + p2
    APoint(30.00, 30.00, 0.00)
    

    Also it supports iterable as parameter:

    >>> APoint([10, 20, 30])
    APoint(10.00, 20.00, 30.00)
    >>> APoint(range(3))
    APoint(0.00, 1.00, 2.00)
    

    Supported math operations: +, -, *, /, +=, -=, *=, /=:

    >>> p = APoint(10, 10)
    >>> p + p
    APoint(20.00, 20.00, 0.00)
    >>> p + 10
    APoint(20.00, 20.00, 10.00)
    >>> p * 2
    APoint(20.00, 20.00, 0.00)
    >>> p -= 1
    >>> p
    APoint(9.00, 9.00, -1.00)
    

    It can be converted to tuple or list:

    >>> tuple(APoint(1, 1, 1))
    (1.0, 1.0, 1.0)
    

    x

    x coordinate of 3D point

    y

    y coordinate of 3D point

    z

    z coordinate of 3D point

    distance_to(other)[source]

    Returns distance to other point

    Parameters: otherAPoint instance or any sequence of 3 coordinates

    pyautocad.types.distance(p1, p2)[source]

    Returns distance between two points p1 and p2

    pyautocad.types.aDouble(*seq)[source]

    Returns array.array of doubles (‘d’ code) for passing to AutoCAD

    For 3D points use APoint instead.

    pyautocad.types.aInt(*seq)[source]

    Returns array.array of ints (‘l’ code) for passing to AutoCAD

    pyautocad.types.aShort(*seq)[source]

    Returns array.array of shorts (‘h’ code) for passing to AutoCAD


    utils - Utility functions

    pyautocad.utils.timing(message)[source]

    Context manager for timing execution

    Parameters: message – message to print

    Usage:

    with timing('some operation'):
        do_some_actions()
    

    Will print:

    some operation: 1.000 s  # where 1.000 is actual execution time
    

    pyautocad.utils.suppressed_regeneration_of(table)[source]

    New in version 0.1.2.

    Context manager. Suppresses table regeneration to dramatically speedup table operations

    Parameters: table – table object
    with suppressed_regeneration_of(table):
        populate(table)  # or change its properties
    

    pyautocad.utils.unformat_mtext(s, exclude_list=('P', 'S'))[source]

    Returns string with removed format information

    Parameters:
    • s – string with multitext
    • exclude_list – don’t touch tags from this list. Default (‘P’, ‘S’) for newline and fractions
    >>> text = ur'{\fGOST type A|b0|i0|c204|p34;TEST\fGOST type A|b0|i0|c0|p34;123}'
    >>> unformat_mtext(text)
    u'TEST123'
    

    pyautocad.utils.mtext_to_string(s)[source]

    Returns string with removed format innformation as unformat_mtext() and P (paragraphs) replaced with newlines

    >>> text = ur'{\fGOST type A|b0|i0|c204|p34;TEST\fGOST type A|b0|i0|c0|p34;123}\Ptest321'
    >>> mtext_to_string(text)
    u'TEST123\ntest321'
    

    pyautocad.utils.string_to_mtext(s)[source]

    Returns string in Autocad multitext format

    Replaces newllines \n with \P, etc.

    pyautocad.utils.text_width(text_item)[source]

    Returns width of Autocad Text or MultiText object

    pyautocad.utils.dynamic_print(text)[source]

    Prints text dynamically in one line

    Used for printing something like animations, or progress


    contrib.tables - Import and export tabular data from popular formats

    class pyautocad.contrib.tables.Table[source]

    Represents table with ability to import and export data to following formats:

    • csv
    • xls
    • xlsx (write only)
    • json

    When you need to store some data, it can be done as follows:

    table = Table()
    for i in range(5):
        table.writerow([i, i, i])
    
    table.save('data.xls', 'xls')
    

    To import data from file, use data_from_file():

    data = Table.data_from_file('data.xls')
    

    writerow(row)[source]

    Add row to table

    Parameters: row (list or tuple) – row to add

    append(row)[source]

    Synonym for writerow()

    clear()[source]

    Clear current table

    save(filename, fmt, encoding='cp1251')[source]

    Save data to file

    Parameters:
    • filename – path to file
    • fmt – data format (one of supported, e.g. ‘xls’, ‘csv’
    • encoding – encoding for ‘csv’ format

    convert(fmt)[source]

    Return data, converted to format

    Parameters: fmt – desirable format of data

    Note: to convert to csv format, use to_csv()

    See also available_write_formats()

    to_csv(stream, encoding='cp1251', delimiter=';', **kwargs)[source]

    Writes data in csv format to stream

    Parameters:
    • stream – stream to write data to
    • encoding – output encoding
    • delimiter – csv delimiter
    • kwargs – additional parameters for csv.writer

    static data_from_file(filename, fmt=None, csv_encoding='cp1251', csv_delimiter=';')[source]

    Returns data in desired format from file

    Parameters:
    • filename – path to file with data
    • fmt – format of file, if it’s None, then it tries to guess format from filename extension
    • csv_encoding – encoding for csv data
    • csv_delimiter – delimiter for csv data

    Format should be in available_read_formats()


    cache - Cache all object’s attributes

    New in version 0.1.2.

    class pyautocad.cache.Cached(instance)[source]

    Proxy for caching object attributes.

    Consider external class Foo with expensive property (we can’t change its code):

    class Foo(object):
        @property
        def x(self):
            print 'consuming time'
            time.sleep(1)
            return 42
    

    Cache all attributes and test access:

    foo = Foo()
    cached_foo = Cached(foo)
    for i in range(10):
        print cached_foo.x
    

    Output:

    consuming time
    42
    42
    42
    42
    42
    

    It’s possible to switch caching off with switch_caching() and retrieve original instance with get_original()

    get_original()[source]

    Returns original instance

    switch_caching(is_enabled)[source]

    Switch caching on or off

    Parameters: is_enabled (bool) – caching status True or False
    展开全文
  • 主要介绍了利用python控制Autocad:pyautocad方式,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
  • pyautocad相关操作案例

    千次阅读 2020-04-28 23:06:09
    from pyautocad import Autocad, APoint import math import numpy as np # 与autoCAD创建连接 # 当有正在运行的CAD程序时,则与其建立连接,并始终与活跃中的CAD窗口产生连接 # 当没有时,将启动一个新的CAD程序 ...
  • pyautocad-0.2.0.win32.exe

    2016-11-22 20:27:09
    pyautocad-0.2.0.win32.exe
  • ![图片说明]... 比如第108单元,我想要实现将单元外的多段线修剪,读取多段线的长度,并且从获取多段线头尾的坐标画出直线,读取直线的长度,pyautocad能够实现吗?大致的思路是什么呢?
  • pyautocad python 操作CAD文件

    千次阅读 2019-01-31 15:09:21
    python操作autocad,实现对dwg文件的操作 业务需求:  图纸的文件名存在引用... 使用python+pyautocad   参考文章:  https://blog.csdn.net/Hulunbuir/article/details/83715279   代码:   from ...
  • pyautocad的实例

    千次阅读 2017-02-14 01:06:11
    from pyautocad import Autocad,APoint import sys reload(sys) sys.setdefaultencoding("utf-8") wb=openpyxl.load_workbook("a.xlsx") sheet=wb.get_sheet_by_name("Sheet1") data=[] px=[] py=[]
  • python下用pyautocad小试牛刀

    千次阅读 2018-07-31 22:33:44
    python下用pyautocad小试牛刀 画点,线,圆,文字等, 获取对象,插入点,查找特定文字等 # -*- coding: UTF-8 -*- from pyautocad import Autocad,APoint acad = Autocad(create_if_not_exists=True) acad.prompt(&...
  • 转载的,原文出处... 一、处理AutoCad模块 -pyautocad  1.安装  1 pip install pyautocad  注:1.该操作会自动安装 comtypes模块,如果其他方式安装,请自行安装comtypes模...
  • 在尝试利用pyautocad 操作cad 发现 文档内容比较简陋,但是大概的方法都给出了,要实现某些具体的内容可以结合 ActiveX的帮助文件完成,本文介绍利用pyautocad查询多段线、样条曲线上控制点坐标的方法。 以样条曲线...
  • Python操作AUTOCAD,pyautocad学习笔记

    千次阅读 2018-10-20 19:12:32
    本文章用到了pyautocad这个第三方库,安装如下: python -m pip install pyautocad 安装成功后,即可使用。
  • 利用python控制Autocad:pyautocad

    万次阅读 热门讨论 2015-04-11 20:38:38
    pyautocad模块的使用
  • 转载的第二篇pyautocad教程,关于另存为的。 原文地址 Autocad.doc.SaveAs()  autocad文档如下:   Signatures object.SaveAs FileName, FileType [, SecurityParams] Object Document,MenuGroup ...
  • pyautocad+openpyxl实例二

    千次阅读 2016-12-05 16:08:11
    from pyautocad import Autocad import openpyxl import sys reload(sys) sys.setdefaultencoding('utf-8') wb=openpyxl.load_workbook('./aabb.xlsx') sheet=wb.get_sheet_by_name('Sheet1') data=[] acad=Autoc
  • 对于好久没有触碰autoCAD的笔者来说,利用python实现自动操作autoCAD,学会使用pyautocad库的同时,也想好好把autoCAD的基本使用操作重新捡起来学习,所以这篇博客记录pyautocad库的使用方法的同时也会附带autoCAD的...
  • 基于Python AutoCAD ActiveX 二次开发,pyautocad应用技术

    千次阅读 多人点赞 2019-11-07 06:31:21
    主要库:pyautocad==0.2.0 内容#:基于Python AutoCAD ActiveX 二次开发,学习笔记 更新日期:2019-11-07 写在前面,先感谢 https://blog.csdn.net/Hulunbuir/article/details/8371527...
  • <div><p>I have a new computer with windows 8 (64 bits) and I installAutoCAD 2013. <p>I´ve tried a routine that used to work in windows 7 (32 bits) +...reclosedev/pyautocad</p></div>
  • 在网上找一一篇关于pyautocad的,写的比较详细的教程,备份下 原文地址 首部必须 1 2 #!/usr/bin/env python # -*- coding: utf-8 -*-   导入pyautocad 1 ...
  • 一、关于pyautocad 第一次接触pyaotocad的可以参考这几篇文章(带传送门): 1、Hulunbuir的Python pyautocad库 使用简介 2、Tong_T的Python3操作AutoCAD:利用pyautocad库能够自动化地进行CAD画图 3、bsider的...
  • from pyautocad import Autocad,APoint acad = Autocad(create_if_not_exists = True) acad.prompt("hello, cad\n") p1 = APoint(0,0) acad.model.InsertBlock(p1,"D:\python\MyPyAutoCADProjects\lightingbox.dwg...
  • python小白,想用pyautocad绘制一些图形。但是看不太懂pyautocad和comtypes的文档。 在comtypes里,绘制多段线的命令如下: COMMETHOD([dispid(1564),helpstring('Creates a polyline from a list of ...
  • 发现pyautocad模块:可以用python控制autocad的包。今天把文档中的重点内容摘录出来,以后绘图、计算大工程量、或者识别施工图的时候时候也许可以用到。一、连接cadpyautocad包可以用任何版本的cad进行操作,实际上...
  • 发现pyautocad模块:可以用python控制autocad的包。今天把文档中的重点内容摘录出来,以后绘图、计算大工程量、或者识别施工图的时候时候也许可以用到。一、连接cadpyautocad包可以用任何版本的cad进行操作,实际上...
  • 发现pyautocad模块:可以用python控制autocad的包。今天把文档中的重点内容摘录出来,以后绘图、计算大工程量、或者识别施工图的时候时候也许可以用到。一、连接cadpyautocad包可以用任何版本的cad进行操作,实际上...

空空如也

1 2 3 4 5 6
收藏数 119
精华内容 47
关键字:

pyautocad