<output id="qn6qe"></output>

    1. <output id="qn6qe"><tt id="qn6qe"></tt></output>
    2. <strike id="qn6qe"></strike>

      亚洲 日本 欧洲 欧美 视频,日韩中文字幕有码av,一本一道av中文字幕无码,国产线播放免费人成视频播放,人妻少妇偷人无码视频,日夜啪啪一区二区三区,国产尤物精品自在拍视频首页,久热这里只有精品12

      PyComCAD介紹及開發(fā)方法

      中文版本介紹

      **項目地址:https://github.com/JohnYang1210/PycomCAD **

      PyComCAD介紹及開發(fā)方法

      1.綜述

      ? 提到Autocad在工業(yè)界的二次開發(fā),VB或者Lisp可能作為常用的傳統(tǒng)的編程語言。但是,Python語言簡潔,優(yōu)雅,學(xué)習(xí)門檻低,理應(yīng)在Autocad二次開發(fā)中占有一席之地,加上Python豐富而強大的第三方庫,更讓Python對于Autocad二次開發(fā)任務(wù)如虎添翼,使得快速開發(fā)出符合工程師自身需求的功能成為可能。Pycomcad恰恰就是獲取Autocad API的接口庫。

      ? Pycomcad的底層庫是win32compythoncom,其中,win32com負責獲取Autocad的接口,包括一些枚舉值,pythoncom主要負責進行數(shù)據(jù)類型轉(zhuǎn)換。Pycomcad設(shè)計理念非常的簡單,就是把win32com中多層調(diào)用的函數(shù)或者屬性包裹為一個函數(shù),用以方便記憶調(diào)用以及減少敲碼次數(shù),而不用每次都按照AutoCAD對象模型樹一層一層的調(diào)用。

      ? 當涉及到Autocad中特定對象的方法或者屬性,比如已創(chuàng)建的圓,塊對象有哪些屬性及方法?可以查看本倉庫下的acadauto.chm文件。

      2.底層庫安裝

      pip install pywin32將會安裝win32com和pythoncom庫。

      3.簡單小例子

      #準備工作
      import sys
      import win32com.client
      import math
      sys.path.append(r'D:\programming\pycomcad\PycomCAD') #這里填寫pycomcad.py所在的文件夾
      from pycomcad import *
      acad=Autocad()  #打開Autocad,如果已有打開的Autocad,則對該Autocad進行連接
      if not acad.IsEarlyBind: #判斷是否是EarlyBind,如果不是則打開Earlybind模式
          acad.TurnOnEarlyBind() 
      acad.ShowLineweight(True)   #設(shè)置打開線寬
      #進行繪制
      line=acad.AddLine(Apoint(0,0),Apoint(100,0)) #繪制線
      circle=acad.AddCircle(Apoint(100,0),10)  #繪制圓
      circleBig=acad.AddCircle(Apoint(0,0),110)
      circleInner=acad.AddCircle(Apoint(0,0),90)
      for i in range(15):
          angle=math.radians(24)
          line.Copy()
          circle.Copy()
          line.Rotate(Apoint(0,0),angle)  #對線和圓進行復(fù)制并旋轉(zhuǎn)
          circle.Rotate(Apoint(0,0),angle)
      text=acad.AddText('Code makes a better world!',Apoint(0,0),20)  #繪制文字
      text.Alignment=win32com.client.constants.acAlignmentTopCenter  #設(shè)置文字的alignment方向
      text.Move(Apoint(0,0),Apoint(0,-150)) #移動文字
      underLine=acad.AddLine(Apoint(-175,-180),Apoint(175,-180)) #繪制下劃線
      underLine.Lineweight=win32com.client.constants.acLnWt030 
      underLine.Copy()
      underLine.Offset(5) #向上偏移下劃線
      # 保存文件
      acad.SaveAsFile(r'pycomcad.dwg')
      

      繪制出如下圖形:

      image-20210226220032506

      4.Pycomcad的基本架構(gòu)

      4.1 指定特定版本

      ? 如果個人電腦上裝有多個版本的Autocad,我們想針對特定版本的Autocad進行二次開發(fā),只需要修改pycomcad.pywin32com.client.Dsipatch函數(shù)中的ProgID就可以了(比如要指定Autocad2016版本,只需要修改為self.acad=win32com.client.Dispatch('AutoCAD.Application.20'),本倉庫默認為Autocad.Application:

      class Autocad:
      	def __init__(self):
      		try:
      			self.acad=win32com.client.Dispatch(`ProgID`)  #修改此處的ProgID
      			self.acad.Visible=True 
      		except:
      			Autocad.__init__(self)
      

      Autocad版本號與ProgID對應(yīng)關(guān)系表如下:

      AutoCAD Production ProgID
      AutoCAD 2004 AutoCAD.Application.16
      AutoCAD 2005 AutoCAD.Application.16.1
      AutoCAD 2006 AutoCAD.Application.16.2
      AutoCAD 2007 AutoCAD.Application.17
      AutoCAD 2008 AutoCAD.Application.17.1
      AutoCAD 2009 AutoCAD.Application.17.2
      AutoCAD 2010 AutoCAD.Application.18
      AutoCAD 2011 AutoCAD.Application.18.1
      AutoCAD2014 AutoCAD.Application.19
      AutoCAD2016 AutoCAD.Application.20

      4.2 模塊級函數(shù)

      • Apoint :點函數(shù),傳入x,y,z(可選,默認為0),其返回值作為其他函數(shù)的輸入值。如在上面的例子中,AddLineAddCircle方法均需輸入Apoint函數(shù)的返回值
      • ArrayTransform:將任何型式的數(shù)組轉(zhuǎn)換為所需要的實數(shù)型數(shù)組,多用于pycomcad模塊內(nèi)部使用
      • VtVertex:將分散的數(shù)據(jù)轉(zhuǎn)換為實數(shù)型數(shù)組,多用于pycomcad模塊內(nèi)部使用
      • VtFloat:將僅有數(shù)字的列表轉(zhuǎn)換為實數(shù)型列表
      • VtInt:將僅有整數(shù)的列表轉(zhuǎn)換為整數(shù)型列表
      • VtVariant:將變量型列表轉(zhuǎn)換為變量型列表
      • AngleDtoR:將°轉(zhuǎn)換為radian,也可以用math.radians
      • AngleRtoD:將radian轉(zhuǎn)換為°,也可以用math.degrees
      • FilterType,F(xiàn)ilterData,過濾規(guī)則中將DXF碼傳入,也可以用VtInt(ft),VtVariant(fd),詳細參見GetSelectionSets方法說明

      有關(guān)數(shù)據(jù)轉(zhuǎn)換更詳細的信息見: http://www.rzrgm.cn/johnyang/p/12617881.html .

      4.3 Early-bind模式還是Lazy-bind模式

      ? 在上面例子中,我們用到了acad.IsEarlybind屬性,以及acad.TurnOnEarlyBind方法,那么什么是early-bind模式,什么是lazy-bind模式呢?

      ? 默認地,pycomcad是lazy-bind模式,意思就是pycomcad對于特定的對象,比如線,圓等的方法,屬性,以及常量枚舉值,事先是不知道的,而early-bind模式下,pycomcad就提前知道了特定的對象的類型,方法,屬性。實際上,這對于我們進行二次開發(fā)是有比較大的影響的,因為有時候我們需要知道選中的對象到底是什么樣的類型,然后根據(jù)其類型,進行不同的操作。比如,對于early-bind模式,pycomcad能識別win32com.client.constants.acRed枚舉值,而lazy-bind模式下,不能對其進行識別。建議把early-bind模式打開。

      ? Autocad對象,比如它是acad,它的IsEarlyBind屬性可以判斷目前Autocad的模式是哪一種,如果是early-bind模式,則返回True,否則返回False,如果是lazy-bind,那么可以調(diào)用TrunOnEarlyBind()方法來轉(zhuǎn)變?yōu)镋arly-bind模式。

      ? 有關(guān)Early-bind和Lazy-bind模式的信息,詳見我的博文:http://www.rzrgm.cn/johnyang/p/12521301.html

      4.4 模塊的主要方法及屬性


      • 系統(tǒng)變量
      方法 作用
      SetVariable 設(shè)置系統(tǒng)變量
      GetVariable 獲取系統(tǒng)變量

      • version
      屬性 作用
      Version 返回打開AutoCAD的版本,如'AutoCAD2007'
      • Registered Application
      屬性 作用
      RAppNames 返回圖形對象的Registered Application對象集合所包含所有對象的名字
      RApps 返回圖形對象的Registered Applications對象集合
      方法 作用
      SetXData 為實體/非實體添加XData
      • 文件處理
      方法 作用
      OpenFile 打開文件
      CreateNewFile 新建文件
      SaveFile 保存
      SaveAsFile 將文件保存至設(shè)定路徑下
      Close 關(guān)閉文件
      PurgeAll Purge文件
      Regen Regen文件
      GetOpenedFile 返回指定的已經(jīng)打開的文件
      ActivateFile 指定已經(jīng)打開的文件為當前工作文件
      DeepClone 跨文件間復(fù)制對象
      屬性 作用
      OpenedFilenames 返回已經(jīng)打開的所有文件列表
      OpenedFilenumbers 返回已經(jīng)打開的文件的數(shù)量
      CurrentFilename 返回當前文件名
      FilePath 返回當前文件路徑
      IsSaved 如果當前文件保存了,則返回True,否則False

      • 精細繪圖設(shè)置
      方法 作用
      ZoomExtents 極限放大
      ZoomAll 顯示整個圖形
      GridOn 打開/關(guān)閉柵格
      SnapOn 打開/關(guān)閉捕捉狀態(tài)

      • 創(chuàng)建實體
      方法 作用
      AddPoint 創(chuàng)建點
      AddLine 創(chuàng)建線
      AddLwpline 創(chuàng)建LightWeight多段線
      AddCircle 創(chuàng)建圓
      AddArc 創(chuàng)建圓弧
      AddTable 創(chuàng)建表
      AddSpline 創(chuàng)建擬合曲線
      AddEllipse 創(chuàng)建橢圓
      AddHatch 創(chuàng)建填充
      AddSolid 創(chuàng)建實心面

      • 引用及選擇
      方法 作用
      Handle2Object 通過實體引用的Handle值獲取實體本身
      GetEntityByItem 通過實體的索引來獲取實體
      GetSelectionSets 獲取選擇集(選擇及過濾機制詳見http://www.rzrgm.cn/johnyang/p/12934674.html)

      • 圖層
      方法 作用
      CreateLayer 創(chuàng)建圖層
      ActivateLayer 激活圖層
      GetLayer 獲取圖層對象
      屬性 作用
      LayerNumbers 返回圖層的總數(shù)
      LayerNames 返回圖層名列表
      Layers 返回圖層集
      ActiveLayer 返回當前圖層

      • 線型
      方法 作用
      LoadLinetype 加載線型
      ActivateLinetype 激活線型
      ShowLineweight 顯示/關(guān)閉線型
      屬性 作用
      Linetypes 返回線型集

      方法 作用
      CreateBlock 創(chuàng)建塊
      InsertBlock 插入塊

      • 用戶坐標系
      方法 作用
      CreateUCS 創(chuàng)建用戶坐標系
      ActivateUCS 激活用戶坐標系
      GetCurrentUCS 獲取當前用戶坐標系
      ShowUCSIcon 顯示/關(guān)閉用戶坐標系圖標

      • 文字
      方法 作用
      CreateTextStyle 創(chuàng)建文字樣式
      ActivateTextStyle 激活文字樣式
      GetActiveFontInfo 獲取活動字體信息
      SetActiveFontFile 設(shè)定活動字體文件
      AddText 創(chuàng)建單行文字
      AddMText 創(chuàng)建多行文字

      • 尺寸與標注
      方法 作用
      AddDimAligned 創(chuàng)建平行尺寸標注對象
      AddDimRotated 創(chuàng)建之地那個角度標注對象
      AddDimRadial 創(chuàng)建半徑型尺寸標注對象
      AddDimDiametric 創(chuàng)建直徑型尺寸標注對象
      AddDimAngular 創(chuàng)建角度型尺寸標注對象
      AddDimOrdinate 創(chuàng)建坐標型尺寸標注
      AddLeader 創(chuàng)建導(dǎo)線型標注
      CreateDimStyle 創(chuàng)建標注樣式
      GetDimStyle 獲取標注樣式
      ActivateDimStyle 激活標注樣式
      屬性 作用
      DimStyleNumbers 返回標注樣式數(shù)量
      DimStyleNames 返回標注樣式名列表
      DimStyle0 返回index為0的標注樣式對象
      DimStyles 返回標注樣式集體
      ActiveDimStyle 返回當前標注樣式

      • Utility方法

      Utility實際上就是與用戶交互,比如用戶輸入字母,數(shù)字,做出選擇等。

      方法 作用
      GetString 獲取字符串
      AngleFromXAxis 獲取線與X軸的夾角
      GetPoint 獲取空間一點的位置
      GetDistance 獲取兩點距離
      InitializeUserInput 初始化用戶輸入選項
      GetKeyword 獲取用戶做出的選擇
      GetEnity 點選實體
      GetReal 獲取用戶輸入的實數(shù)
      GetInteger 獲取用戶輸入的整數(shù)
      Prompt 給出提示

      ? 以上各種方法的詳細用法,可以通過help命令查詢,或者直接在源碼中查詢,不再贅述。

      4.5 打印

      ? 打印目前沒有直接納入pycomcad中Autocad類方法,通過pycomcad來實現(xiàn)打印功能的用法詳見博文:http://www.rzrgm.cn/johnyang/p/14359725.html

      5 與Pycomcad一起使用的第三方庫

      ? Python具備豐富而強大的第三方庫,這也使快速開發(fā)出符合特定需求功能的Autocad二次開發(fā)程序成為可能。理論上,我們無法完全窮舉出所有與Pycomcad一起使用的第三方庫,因為特定需求本身就蘊含了無限可能,面對同一需求,實現(xiàn)的方法也不盡相同,使用的其他第三方庫也不一樣,下面列舉出我自己在實際開發(fā)工作中常用到的其他第三方庫,僅供參考。

      第三方庫 作用
      sys 剛需,將pycomcad所在路徑添加到python搜索路徑中,否則需要將pycomcad所在路徑手動添加到環(huán)境變量,以使得python可以搜索到pycomcad.py
      os 在操作系統(tǒng)下進行的操作,如路徑,文件的查詢,添加等。
      shutil 更高級的文件操作庫
      math 簡單的數(shù)學(xué)運算
      numpy 向量化數(shù)值計算,避免了層層的for循環(huán),在繪制不同比例的圖形,非常有用
      pandas 與excel,csv交互,比如用excel上的數(shù)據(jù)來繪圖,或者收集,儲存圖中的數(shù)據(jù)
      tkinter 圖形界面化二次開發(fā)程序
      PyQt5 同tkinter,但比tkinter更為強大
      itertools 創(chuàng)建特定循環(huán)迭代器的函數(shù)集,比如數(shù)學(xué)上的排列,組合
      docx 與docx文件進行交互

      6 從Autocad中調(diào)用二次開發(fā)程序

      ? 當我們通過pycomcad實現(xiàn)了某些自動化/自定義工作的功能后,如果需要頻繁使用該程序,那么每次都直接運行腳本,顯然有些繁瑣,那么有沒有辦法可以從Autocad中直接調(diào)用寫號的二次開發(fā)程序呢?

      ? 答案是有的,目前可以通過打包程序為exe文件(Pyinstaller的簡單使用可參考我的博文:http://www.rzrgm.cn/johnyang/p/10868863.html ),然后用lsp文件來調(diào)用打包的exe文件(不需要掌握lsp,很簡單的一個語句),最后在Autocad中通過命令來調(diào)用該lsp文件就可以了。詳見我的博文:http://www.rzrgm.cn/johnyang/p/14415515.html

      7 實戰(zhàn)開發(fā)案例及不斷升級...

      ? 隨著實際工作中遇到的開發(fā)需求越來越多,PycomCAD也在不斷的升級中。如果你對該項目有任何的興趣,可以clone它,嘗試將它應(yīng)用到實際工作中去,給本項目打個star。如果你發(fā)現(xiàn)有價值的功能需要被添加到PycomCAD中,可以pull request它,或者通過郵箱聯(lián)系我:1574891843@qq.com。讓我們一起攜手,把PycomCAD打造的更為健壯,強大!

      ? 實戰(zhàn)開發(fā)程序可參考 https://github.com/JohnYang1210/DesignWorkTask.

      8 打賞及鳴謝

      ? 維護項目不易,如果您覺得該項目有幫到您,可以請博主喝杯咖啡~

      微信二維碼

      微信圖片_20210227104225

      ?


      支付寶二維碼

      微信圖片_20210227104410

      ?

      English version of Introduction:

      Introduction and development manual of PyComCAD

      1.Overview

      In terms of the secondary development of Autocad in Engineering field, VB or Lisp may be choosen as the common and traditional programming language.However,Python shall play an important role as for this task with the power of easy-to-write and the elegance of conciseness, and Pycomcad exactly acts as an convenient way to get the API of Autocad.

      The base modules of Pycomcad are win32com and pythoncom,and win32com is responsible for getting the interface of Autocad including some constant values in the module level,pythoncom deals with the data type conversion.The methodology of Pycomcad is very easy and that is wrapping up calling functions of the multilayers to be single class methods or properties so that makes API function easier to memory and save your keystroke.

      When refering to the methods or properties of specific created entity in Autocad,It's better to look up acadauto.chm provided in this repository.

      2.Base module installation

      pip install pywin32 will install both win32com and pythoncom.

      3.Basic structure of Pycomcad

      3.1 Module-level functions

      These functions are used to convert data type.Details about data type convertion can be referred to http://www.rzrgm.cn/johnyang/p/12617881.html .

      3.2 Early-bind mode Or Lazy-bind mode

      This blog(http://www.rzrgm.cn/johnyang/p/12521301.html) written by myself may be consulted to learn about topics related to early-bind and lazy-bind mode.

      By default,pycomcad is lazy-bind mode and that means pycomcad knows nothing about the method or property of specified entity,even the type of the entity itself.And actually, this has a huge impact on programming because we shall know clearly the type of entities in Autocad in order to do something different according to the type of selected entity.For example, as for EarlyBind mode,pycomcad will recognize win32com.client.constants.acRed,which is a constant value, while LazyBind mode will not recognize it.

      Autocad object,assuming to acad, in Pycomcad has two properties to examin whether the module is earlybind or not and turn on earlybind mode if it is not,and they are acad.IsEarlyBind and acad.TurnOnEarlyBind.

      Please note that,if there are multi-version Autocad on your PC, whether the Autocad object in pycomcad is EarlyBind or not will depend on the specific version of opened Autocad.So it's recommended to turn on all version's EarlyBind mode.

      3.3 Major structure of module

      • System variable
      • File processing
      • Precise drawing setting
      • Entity creation
      • Refer and select entity
      • Layer
      • Linetype
      • Block
      • User-defined coordinate system
      • Text
      • Dimension and tolerance
      • Utility object

      Detailed information can be found in pycomcad.py and acadauto.chm.

      4.Practical case and updating ...

      Some actual application of pycomcad in my practical work can reffer to https://github.com/JohnYang1210/DesignWorkTask. With the increasing requirement encountered in daily work and for the integrity of module, pycomcad shall be evolving up to date constantly.
      If you have any interest in this project,clone it,see the source and apply it to the real work.There are still so many function to add or update, once you find it,pull request it or contact with me through email:1574891843@qq.com, Let's work together to make Pycomcad more robust,integrated,concise and more powerful!

      5 Donation

      ? It's not easy for maintaining this project, and if you find it is useful , you can donate me a cup of caffee!

      WeChat QR Code

      微信圖片_20210227104225

      ?


      ? Alipay QR Code

      微信圖片_20210227104410

      ?

      posted @ 2021-02-27 18:32  JohnYang819  閱讀(5115)  評論(1)    收藏  舉報
      主站蜘蛛池模板: 影音先锋AV成人资源站在线播放| 一区二区三区岛国av毛片| 亚洲精选av一区二区| 97人妻蜜臀中文字幕| 久久精品国产99国产精品严洲| 精品一区二区三区女性色| 日韩人妻精品中文字幕| 亚洲欧美色综合影院| 风韵丰满熟妇啪啪区老熟熟女| 国产视频一区二区在线看| 午夜精品一区二区三区在线观看| 国产精品不卡一二三区| 久久综合色之久久综合色 | 国产精品午夜福利片国产| 日韩亚洲精品中文字幕| 1000部拍拍拍18勿入免费视频下载| 成人永久性免费在线视频| 自拍偷自拍亚洲精品熟妇人| 亚洲AV日韩AV高清在线观看| 55大东北熟女啪啪嗷嗷叫| 18禁黄无遮挡网站免费| 日本久久精品一区二区三区| 亚洲最大日韩精品一区| 亚洲高清国产自产拍av| 中文字幕亚洲无线码一区女同| 成人免费无遮挡在线播放| 97国产揄拍国产精品人妻| 国产SUV精品一区二区四| 性高湖久久久久久久久| 国产成人无码av大片大片在线观看| 中文国产成人精品久久不卡| 强奷乱码中文字幕| 国产精品一区二区传媒蜜臀| 制服 丝袜 亚洲 中文 综合| 免费观看性行为视频的网站| 久久热这里只有精品99| 亚洲人成网线在线播放VA| 欧美自拍嘿咻内射在线观看| 国产精品熟女一区二区三区| 国产精品久久蜜臀av| 最近2019中文字幕大全第二页|