ID:
PW:

     0 ºÐ
     24 ºÐ

¿£Áö´Ï¾î µ¹Á¾
  dolljong
ÇÁ·Î±×·¡¹Ö Tips
ÇÁ·Î±×·¡¹Ö¿¡ °üÇÑ TipÀ» °øÀ¯ÇÏ´Â °÷ÀÔ´Ï´Ù.


(¿£Áö´Ï¾î¸¦ À§ÇÑ) ÆÄÀ̽㠽ÃÀÛÇϱâ[16] ÆÄÀ̽ã ijµå ¿¬µ¿ 2/2(win32com)
À̼®Á¾  2023-01-03 09:09:58, Á¶È¸ : 1,469, Ãßõ : 171
- Download #1 : engpython16.png (37.0 KB), Download : 34


(¿£Áö´Ï¾î¸¦ À§ÇÑ) ÆÄÀ̽㠽ÃÀÛÇϱâ[16]

 

³»¿ë : ÆÄÀ̽ã-CAD ¿¬µ¿-2/2 (win32com)

ÂüÁ¶ :

https://pypi.org/project/pywin32/ Python for Window Extensions

https://wikidocs.net/135798 Win32com (pywin32)

https://thgeomacademy.wordpress.com/python-autocad-selectionsets/

https://www.supplychaindataanalytics.com/selectionset-object-in-autocad-with-python/#

 

 

0.½ÃÀÛÇϸç

¾ÕÀÇ ÆÄÀ̽ã-ijµå¿¬µ¿ 1/2¿¡¼­´Â pyautocad¸¦ À§ÁÖ·Î ¼Ò°³Çß´Ù. pyautocad´Â MicroSoftÀÇ COM±â¼úÀ» ½±°Ô ¾µ ¼ö ÀÖµµ·Ï Á¤¸®ÇÑ ¶óÀ̺귯¸®´Ù. µû¶ó¼­ COM±â¼úÀÇ ¸ðµç ±â´ÉÀÌ ´ã°ÜÀÖÁö´Â ¾Ê´Ù. ±×·¡¼­ ÆÄÀ̽ãÀ¸·Î COM±â¼úÀ» Á÷Á¢ »ç¿ëÇÏ¸é ±¸ÇöÇÒ ¼ö Àִ ijµå ±â´ÉµéÀÌ ´õ ¸¹¾ÆÁø´Ù. À̹ø ½Ã°£¿¡´Â win32com(pywin32)¸¦ ÀÌ¿ëÇؼ­ ijµå¸¦ ÅëÁ¦ÇÏ´Â °ÍÀ» ¼Ò°³ÇÏ°Ú´Ù. ºñ½ÁÇÑ ±â´ÉÀ» ÇÏ´Â ÆÄÀ̽ã ÆÐÅ°Áö·Î comtypes°¡ Àִµ¥ win32comÀ» »ç¿ëÇÏ´Â »ç·Ê°¡ ´õ ¸¹¾Æ win32comÀÇ »ç¿ë¿¡ ´ëÇØ ÁøÇàÇÏ°íÀÚ ÇÑ´Ù. 

 

1. win32com(pywin32)

win32comÀº ÆÄÀ̽ãÀ¸·Î COMÀ» Áö¿øÇÑ´Ù. COMÀº ¸¶ÀÌÅ©·Î¼ÒÇÁÆ®ÀÇ ±â¼ú·Î ÇÁ·Î±×·¥°£ÀÇ ¼ÒÅëÀ» Áö¿øÇÏ´Â ±â¼úÀÌ´Ù. win32comÀº anaconda¸¦ ¼³Ä¡Çß´Ù¸é ÄÄÇ»ÅÍ¿¡ ¼³Ä¡µÇ¾îÀÖ´Ù. jupyter notebook, xlwings µîÀÌ win32comÀ» »ç¿ëÇϱ⠶§¹®ÀÌ´Ù. win32comÀº AutoCAD»Ó ¾Æ´Ï¶ó ¿¢¼¿À̳ª ¿öµå, ÆÄ¿öÆ÷ÀÎÆ® ÇÁ·Î±×·¥µµ Áö¿øÇÑ´Ù. win32comÀ» ¾²´Â ÀÌÀ¯´Â pyautocad¿¡¼­ Áö¿øÇÏÁö ¾Ê´Â ijµå º»¿¬ÀÇ ±â´ÉµéÀ» »ç¿ëÇϱâ À§ÇÑ °ÍÀÌ´Ù.

 

2. pyautocad¿Í Â÷ÀÌ.

pyautocad¿Í win32comÀÇ Â÷À̸¦ ¾Ë¾Æº¸ÀÚ.

 

pyautocad¿¡¼­´Â ¾Æ·¡¿Í °°ÀÌ °´Ã¼¸¦ ¼±ÅÃÇÑ´Ù. Áö³­ ½Ã°£¿¡ ¼Ò°³µÇ¾ú´Ù.

acad.get_selection(¡®¸Þ½ÃÁö¡¯)

 

¹Ý¸é win32com(ActiveX)¿¡¼­´Â ¾Æ·¡¿Í °°ÀÌ °´Ã¼¸¦ ¼±ÅÃÇÑ´Ù. object´Â SelectionSetÀÌ´Ù.

object.Select Mode [, Point1] [, Point2] [, FilterType, FilterData]

 

Â÷ÀÌ°¡ ÀÖ´Ù´Â °ÍÀ» ¾Ë ¼ö ÀÖ´Ù. pyautocad¿¡¼­´Â acadÀÇ method·Î get_selection()°¡ Á¸ÀçÇÏÁö¸¸ win32com¿¡¼­´Â SelectionSetÀÇ method·Î Select°¡ Á¸ÀçÇÑ´Ù. ¾Õ¿¡¼­ pyautocad°¡ ActiveX¸¦ Á»´õ ÆíÇÏ°Ô ¾²±â À§Çؼ­ ¸¸µé¾îÁø ¶óÀ̺귯¸®¶ó°í ¼Ò°³Çß¾ú´Ù. ActiveX º»¿¬ÀÇ ÇüÅ´ SelectionSetÀ» ÀÌ¿ëÇÏ´Â °ÍÀ¸·Î µÇ¾îÀÖ´Ù.

C:\Program Files\Common Files\Autodesk Shared\ko-KR\acadauto.chm ÆÄÀÏÀ» ¿­¾î¼­ AutoCAD Object ModelÀ» È®ÀÎÇغ¸ÀÚ. Document ¾Æ·¡ SelectionSets¿Í SelectionSetÀÌ ÀÖ´Â °ÍÀ» È®ÀÎÇÒ ¼ö ÀÖ´Ù.

 

 

SelectionSetÀ» ´­·¯¼­ µé¾î°¡º¸¸é ¾Æ·¡¿Í °°ÀÌ SelectinSetÀÇ Method, Properties, Event¸¦ º¼ ¼ö ÀÖ´Ù. SelectionSets´Â SelectionSetµéÀÇ ÁýÇÕÀÌ´Ù.

 

¾Õ¿¡¼­ ¿¹½Ã·Î Á¦½ÃÇÑ object.Select ¸Þ¼Òµå¸¦ ¼±ÅÃÇؼ­ ³»¿ëÀ» º¸ÀÚ. VBA ¹®¹ýÀ» º¸¿©ÁØ´Ù. python ¹®¹ýÀÌ ¾Æ´Ï¶ó´Â °ÍÀ» ±â¾ïÇÏÀÚ. ÀÌ VBA±â´ÉÀ» python¿¡¼­ »ç¿ëÇÒ ¼ö ÀÖ°Ô ÇØÁÖ´Â °ÍÀÌ win32com, pyautocad, comtypes µî COM°ü·Ã ÆÐÅ°ÁöµéÀÌ´Ù.

 

Select¸Þ¼Òµå´Â Mode, Point1, Point2, FilterType, FilterData µîÀ» ÀÎÀÚ·Î ÁÖ´Â °ÍÀ» ¾Ë ¼ö ÀÖ´Ù. °¢ ÀÎÀڵ鿡 ´ëÇÑ ¼³¸íÀº ¾Æ·¡ÂÊ¿¡ ³ª¿Í ÀÖ´Ù. ÀÌ ¸Þ¼Òµå´Â ÇÑÁ¡ ¶Ç´Â µÎÁ¡À» ÀÌ¿ëÇϰųª Á¡ ¾øÀÌ CADÀÇ °´Ã¼µéÀ» ¼±ÅÃÇÒ ¼ö ÀÖ´Ù. À̶§ ÇÊÅ͸¦ ÀÌ¿ëÇؼ­ ¼±¸¸ ¼±ÅÃÇѴٵ簡 ·¹ÀÌ¾î ¡°0¡±¿¡ ÀÖ´Â °´Ã¼µé¸¸ ¼±ÅÃÇѴٵ簡 ÀÌ·± ¿É¼ÇÀ» »ç¿ëÇÒ ¼ö ÀÖ´Ù. ÀÚ¼¼ÇÑ °ÍÀº ³ªÁß¿¡ ¾Ë¾Æº¸µµ·Ï ÇÏ°Ú´Ù. 

´Ù¸¥ ¸Þ¼Òµå¸¦ ¾Ë¾Æº¸ÀÚ. SelectOnScreenÀ̶ó´Â °ÍÀÌ ÀÖ´Ù. ÀÌ°ÍÀÌ »ç¿ëÀÚ·Î ÇÏ¿©±Ý ¹°Ã¼¸¦ ¼±ÅÃÇϵµ·Ï ¿ä±¸ÇÏ´Â ¸Þ¼Òµå´Ù. pyautocad¿¡¼­ Á¦°øÇÏ´Â get_selection ¸Þ¼Òµå´Â ÀÌ ±â´ÉÀ» ½±°Ô ¾µ ¼ö ÀÖµµ·Ï Á¤ÀÇµÈ °ÍÀÌ´Ù. SelectOnScreenÀÇ ³»¿ëÀ» º¸ÀÚ. ¹°·Ð VBA¹®¹ýÀÌ´Ù. ÆÄÀ̽㠹®¹ýÀº ³ªÁß¿¡ »ìÆ캼 °ÍÀÌ´Ï °ÆÁ¤ÇÏÁö ¸»ÀÚ. COM±â¼úÀ» »ç¿ëÇÏ·Á¸é ActiveX ¹®¼­¿¡ Àͼ÷ÇØÁ®¾ß ÇÑ´Ù.

 

object.SelectOnScreen [FilterType, FilterData]

 

[ ] ¾ÈÀÇ ³»¿ëÀº µé¾î°¥ ¼öµµ ÀÖ°í ¾Èµé¾î°¡µµ µÈ´Ù. ¿É¼Ç »çÇ×À̶ó´Â °ÍÀÌ´Ù. ¾ÕÀÇ Select ¸Þ¼Òµå¿Í ¸¶Âù°¡Áö·Î ÇÊÅ͸¦ »ç¿ëÇÒ ¼ö ÀÖ´Ù´Â °ÍÀ» ¾Ë ¼ö ÀÖ´Ù. pyautocad¿¡¼­ Á¦°øÇÏ´Â get_selection(¡®¸Þ½ÃÁö¡¯) ÇÔ¼ö´Â ÇÊÅ͸¦ »ç¿ëÇÒ ¼ö ¾ø¾ú´Ù. ÇÊÅÍ¿¡ °üÇÑ ¿É¼ÇÀ» ³ÖÀ» ¼ö ¾ø¾ú´Ù. ÀÌ°ÍÀÌ pyautocad¿Í win32comÀÇ Â÷ÀÌ´Ù. pyautocad´Â ActiveXÀÇ ¸ðµç ±â´ÉÀ» »ç¿ëÇÒ ¼ö ¾ø´Ù. ActiveX±â´ÉÀ» °£ÆíÇÏ°Ô »ç¿ëÇÏ·Á°í ¸¸µç ¶óÀ̺귯¸®À̱⠶§¹®ÀÌ´Ù. ¹Ý¸é win32comÀ¸·Î´Â ActiveX±â´ÉÀ» ¸ðµÎ »ç¿ëÇÒ ¼ö ÀÖ´Ù.

 

 

 

3. win32com ¼³Ä¡È®ÀÎ ¹× ¼³Ä¡

anaconda¸¦ ¼³Ä¡Çß´Ù¸é win32comÀÌ ÀÌ¹Ì ¼³Ä¡ µÇ¾îÀÖÀ» °ÍÀÌ´Ù. ¼³Ä¡È®ÀÎÀ» À§Çؼ­ anaconda prompt¸¦ ½ÇÇàÇÏ°í pip show pywin32¸¦ ÀÔ·ÂÇغ¸ÀÚ. win32comÀÌ ¾Æ´Ï¶ó pywin32ÀÓÀ» ÁÖÀÇÇÏÀÚ. Required-by Ç׸ñ¿¡¼­ jupyter-core,xlwings µî ¾Õ¿¡¼­ °æÇèÇغ» ÆÐÅ°ÁöµéÀÌ win32com(win32com)À» ¾²°í ÀÖ´Ù´Â °ÍÀ» È®ÀÎÇÒ ¼ö ÀÖ´Ù.

 

(base) C:\Users\ysj>pip show pywin32
Name: pywin32
Version:
228
Summary: Python
for Window Extensions
Home-page: https://github.com/mhammond/pywin32
Author: Mark Hammond (et al)
Author-email: mhammond@skippinet.com.au
License: PSF
Location: c:\programdata\anaconda3\lib\site-packages
Requires:
Required-by: jupyter-core, jupyter-server, menuinst, xlwings

 

¸¸ÀÏ pywin32°¡ ¼³Ä¡µÇ¾îÀÖÁö ¾Ê´Ù¸é ¾Æ·¡¿Í °°ÀÌ ¸í·ÉÀ» ³»·Á pywin32¸¦ ¼³Ä¡ÇÏÀÚ.

pip install pywin32

 

 

4. ½ÃÀÛÇϱâ-ÆÄÀ̽ã°ú CAD¿¬°á

win32comÀ» ÀÌ¿ëÇؼ­ CAD¿Í ¿¬°áÇÏ´Â ¹æ¹ýÀ» ¾Ë¾Æº¸ÀÚ. ¾Õ¿¡¼­ »ìÆ캻 pyautocad¿Í ºñ±³Çغ¸¸é¼­ »ìÆ캸µµ·Ï ÇÏ°Ú´Ù.

import win32com.client
acad = win32com.client.Dispatch(
"AutoCAD.Application")
doc = acad.ActiveDocument
acadModel = doc.ModelSpace
doc.Utility.Prompt(
"Hello, Autocad from Python\n")
print(doc.Name)

 

 

from pyautocad import Autocad
acad = Autocad()
acad.prompt(
"Hello, Autocad from Python\n")

print(acad.doc.Name)

 

pyautocad¿Í ºñ±³Çغ¸ÀÚ. pyautocad°¡ Á¶±Ý ´õ Æí¸®ÇÏ°Ô »ç¿ëÇÒ ¼ö ÀÖµµ·Ï µÇ¾îÀÖ´Ù´Â °ÍÀ» ¾Ë ¼ö ÀÖ´Ù. pyautocad¿¡¼­´Â acad=Autocad()·Î AutoCADÇÁ·Î±×·¥¿¡ Á¢±ÙÇßÁö¸¸ win32com¿¡¼­´Â acad=win32com.client.Dispatch(¡°AutoCAD.Application¡±)À¸·Î Á¢±ÙÇß´Ù. ¶ÇÇÑ pyautocad¿¡¼­´Â ijµåÀÇ ¸í·Éâ¿¡ ÅؽºÆ®¸¦ Ãâ·ÂÇÏ´Â prompt°¡ acadÀÇ ¸Þ¼ÒµåÀÌÁö¸¸ win32com¿¡¼­´Â acadÀÇ ÇÏÀ§ÀÎ ActiveDocumentÀÇ ¾Æ·¡ ÀÖ´Â UtilityÀÇ ÇÏÀ§ ¸Þ¼Òµå·Î Á¸ÀçÇÑ´Ù.½ÇÁ¦·Î prompt°¡ AutoCAD Object Mode¿¡¼­´Â ¾îµð¿¡ À§Ä¡ÇÏ´Â °ÍÀÎÁö È®ÀÎÇغ¸ÀÚ.

C:\Program Files\Common Files\Autodesk Shared\ko-KR\acadauto.chm ¸¦ ¿­°í prompt¸¦ °Ë»öÇغ¸¸é ¾Æ·¡¿Í °°Àº È­¸éÀ» º¼ ¼ö ÀÖ´Ù.prompt´Â UtilityÀÇ ¸Þ¼ÒµåÀÓÀ» ¾Ë ¼ö ÀÖ´Ù.

 

UtilityÀÇ À§Ä¡¸¦ AutoCAD Object Model¿¡¼­ »ìÆ캸¸é ¾Æ·¡¿Í °°ÀÌ DocumentÀÇ ÇÏÀ§¿¡ ÀÖ´Â °ÍÀ» È®ÀÎÇÒ ¼ö ÀÖ´Ù.

pyautocad¿Í win32comÀÇ Â÷À̸¦ ¾Ë°í ÀÖ´Â °ÍÀÌ CADÇÁ·Î±×·¥À» Çϴµ¥ µµ¿òÀÌ µÈ´Ù. pyautocad°¡ Áö¿øÇÏ´Â ±â´ÉÀº pyautocad¸¦ ÀÌ¿ëÇÏ°í pyautocad°¡ Áö¿øÇÏÁö ¾Ê´Â ±â´ÉµéÀº win32comÀ» ÀÌ¿ëÇØ¾ß ÇÏ´Â °æ¿ì°¡ ÀÖÀ» ¼ö ÀÖ´Ù. win32comÀ» ÀÌ¿ëÇÏ·Á¸é AutoCAD Object ModelÀ» Àß ÀÌÇØÇÏ°í ÀÖ´Â °ÍÀÌ Áß¿äÇÏ´Ù.

 

5. °´Ã¼ Ãß°¡

win32comÀ¸·Î AutoCAD °´Ã¼¸¦ Ãß°¡ÇÏ´Â ¹æ¹ýÀ» ¾Ë¾Æº¸ÀÚ. °´Ã¼¸¦ Ãß°¡Çϱâ À§Çؼ­´Â ÁÂÇ¥°¡ ÇÊ¿äÇÏ°í pyautocad¿¡¼­µµ Apoint¸¦ ÀÌ¿ëÇßµíÀÌ win32com¿¡¼­µµ Apoint¸¦ ÀÌ¿ëÇÑ´Ù. ´ë½Å ApointÇÔ¼ö¸¦ Á¤ÀÇÇÏ°í ÀÌ¿ëÇÑ´Ù. ApointÇÔ¼öÀÇ ¿ªÇÒÀº ÆÄÀ̽㿡¼­ ÀÔ·ÂÇÏ´Â ÁÂÇ¥¸¦ AutoCAD°¡ ÀνÄÇÒ ¼ö ÀÖ´Â Çü½ÄÀ¸·Î º¯È¯ÇØÁÖ´Â ÄÚµå¶ó°í »ý°¢ÇÏ¸é µÇ°Ú´Ù. APointÇÔ¼ö¿¡¼­ pythoncomÀ» ÀÌ¿ëÇ߱⠶§¹®¿¡ pythoncomÀ» Ãß°¡·Î importÇÑ °ÍÀ» º¼ ¼ö ÀÖ´Ù.

import win32com.client
import pythoncom

acad = win32com.client.Dispatch(
"AutoCAD.Application")
doc = acad.ActiveDocument
acadModel = doc.ModelSpace

def APoint(x, y, z = 0):
   
return win32com.client.VARIANT(pythoncom.VT_ARRAY | pythoncom.VT_R8, (x, y, z))
   
l1 = acadModel.AddLine(APoint(
0, 0, 0),APoint(1000, 1000, 0))
l2 = acadModel.AddLine(APoint(
1000, 1000, 0),APoint(2000, 0, 0))

c1 = acadModel.AddCircle(APoint(
0, 0, 0),500.0)

 

°´Ã¼¸¦ Ãß°¡ÇÏ´Â ¸Þ¼Òµå´Â AutoCAD Object ModelÀ» ÂüÁ¶ÇÏ¸é µÇ°Ú´Ù. À§ Äڵ忡¼­´Â ¼±°ú ¿øÀ» Ãß°¡ÇÑ ¿¹¸¦ º¸¿´´Ù.

 

 

-        Text Ãß°¡Çϱâ(AddText)

»ç¿ë¹ý : doc.ModelSpace.AddText(¹®ÀÚ¿­, »ðÀÔÁ¡, ÅؽºÆ®³ôÀÌ)

return : Text °´Ã¼

ÀÌ ¸Þ¼Òµå´Â ÅؽºÆ®¸¦ ±×¸®°í ÅؽºÆ® °´Ã¼¸¦ µ¹·ÁÁØ´Ù. ¸Þ¼Òµå ÀÚü´Â pyautocad¿Í µ¿ÀÏÇÏ´Ù. ÇÏÁö¸¸ pyautocadÀÇ °æ¿ì acad.model.AddText¿Í °°ÀÌ modelÀÌ acadÀÇ ¼Ó¼ºÀÎ °Í¿¡ ºñÇØ wim32com¿¡¼­´Â ModelSpace°¡ DocumentÀÇ ¼Ó¼ºÀÌ´Ù. ¾Õ¿¡¼­ ¼³¸íÇÑ °Íó·³ pyautocad°¡ »ç¿ëÇϱâ ÆíÇÏ°Ô ÇÏ·Á°í ÇÑ ´Ü°è¸¦ ÁÙÀÎ °ÍÀ¸·Î º¸¸é µÇ°Ú´Ù. win32comÀº ActiveXÀÇ ¸ðµ¨À» Ãæ½ÇÈ÷ µû¸¥´Ù´Â °ÍÀ» ±â¾ïÇÏÀÚ.

 

ÅؽºÆ®ÀÇ Á¤·Ä, »ö»ó µîÀº »ý¼ºµÈ °´Ã¼ÀÇ ¼Ó¼ºÀ» ¹Ù²ãÁÖ´Â ¹æ¹ýÀ¸·Î º¯°æÇÒ ¼ö ÀÖ´Ù. À§ÀÇ Äڵ忡¼­ »ý¼ºµÈ ÅؽºÆ® t1, ¼± l1, ¿ø c1ÀÇ »öÀ» °¢°¢ 1,2,3À¸·Î ¼öÁ¤ÇÏ´Â ÄÚµå´Ù. 

t1.Color=1
l1.Color=
2
c1.Color=
3

 

 

 

-        Polyline Ãß°¡Çϱâ

pyautocad¿¡¼­ polylineÀ» Ãß°¡ÇÏ´Â ¹æ¹ý°ú ´Ù¸£Áö ¾Ê´Ù. pyautocad¿¡¼­´Â ÁÂÇ¥¸¦ 1Â÷¿ø ¸®½ºÆ®·Î ¸¸µé°í ´Ü ´ÙÀ½ array.array¸¦ ÀÌ¿ëÇؼ­ ijµå°¡ ÀνÄÇÒ ¼ö ÀÖ´Â Çü½ÄÀ¸·Î º¯È¯Çß¾ú´Ù. win32com¿¡¼­´Â array ´ë½Å aDoubleÇÔ¼ö¸¦ Á¤ÀÇÇؼ­ º¯È¯ÇÑ´Ù. ¾ÕÀÇ Äڵ忡 À§ÀÇ ³»¿ëÀ» Ãß°¡Çؼ­ ½ÇÇàÇÏ¸é ¾Æ·¡¿Í °°ÀÌ lwpolylineÀÌ Ãß°¡µÇ´Â °ÍÀ» È®ÀÎÇÒ ¼ö ÀÖ´Ù.

def aDouble(xyz):
   
return win32com.client.VARIANT(pythoncom.VT_ARRAY | pythoncom.VT_R8, (xyz))
points_2d = [
0, 0, 1000, 2000, 2000, 2000]
pl=acadModel.AddLightWeightPolyline(aDouble(points_2d))

 

 

6. Á¡ ÀԷ¹ޱâ

ijµå ÀÚµ¿È­¿¡¼­ »ç¿ëÀڷκÎÅÍ Á¡À» ÀԷ¹޴ ±â´ÉÀÌ ÇÊ¿äÇÏ´Ù. ÇÏÁö¸¸ pyautocad¿¡¼­´Â Áö¿øÇÏÁö ¾Ê´Â ±â´ÉÀÌ´Ù. ActiveX¿¡´Â Utility¾Æ·¡ GetPoint ¸Þ¼Òµå°¡ ÀÖ´Ù. AutoCAD Object Model¿¡¼­ GetPoint¸¦ ã¾Æº¸¸é ¾Æ·¡¿Í °°Àº ³»¿ëÀ» È®ÀÎÇÒ ¼ö ÀÖ´Ù.

 

VBA:

 

RetVal = object.GetPoint([Point [, Prompt]])

 

object

Type: Utility

The object this method applies to.

Point

Access: Input-only; optional

Type: Variant (three-element array of doubles)

The 3D WCS coordinates specifying the relative base point.

Prompt

Access: Input-only; optional

Type: Variant (string)

The text used to prompt the user for input.

 

point¿Í prompt¸¦ ÁÙ ¼ö Àִµ¥ »ý·«ÀÌ °¡´ÉÇÏ´Ù. point¸¦ ÁÖ¸é ±× Á¡ÀÌ base point°¡ µÈ´Ù.

prompt´Â »ç¿ëÀÚ¿¡°Ô º¸¿©Áö´Â ¸Þ½ÃÁö´Ù.

 

µÎÁ¡À» ÀÔ·Â ¹Þ¾Æ¼­ ¼±À» ±×¸®´Â ±â´ÉÀ» ¸¸µé¾îº¸ÀÚ. Getpoint¸¦ µÎ¹ø »ç¿ëÇÏ¸é µÈ´Ù. ù¹ø° È£ÃâÇÒ ¶§´Â Point ¾øÀÌ Prompt¸¸ ÁöÁ¤ÇÏ°í µÎ¹ø° È£ÃâÇÒ ¶§´Â ù¹ø° È£Ãâ¿¡¼­ ¸®ÅϹÞÀº Á¡(pnt11)À» Point·Î ÁÖ¸é ù¹ø° Á¡À» base point·Î º¸¿©ÁØ´Ù. Å×½ºÆ®Çغ» °á°ú ù¹ø° Á¡ ÀԷ¹ÞÀ» ¶§ Prompt°¡ ³ªÅ¸³ªÁö ¾Ê¾Ò´Ù. ¹ö±× °°´Ù. ±×·¡¼­ ¾Õ¿¡ ÀÓÀÇ·Î Prompt ¸Þ¼Òµå¸¦ »ç¿ëÇß´Ù. ÀÌ Äڵ带 ½ÇÇàÇϸé ijµå ¸í·Éâ¿¡ promptµéÀÌ Ãâ·ÂµÇ¸é¼­ 2Á¡À» ÀԷ¹ÞÀ» ¼ö ÀÖ´Ù.

doc.Utility.Prompt(u"Pick first point: ")
pnt11 = doc.Utility.GetPoint( Prompt =
u"\nPick first point: ")
pnt22 = doc.Utility.GetPoint( Prompt =
u"\nPick second point: ", Point=aDouble(pnt11))

LineObj = acadModel.AddLine(aDouble(pnt11), aDouble(pnt22))

 

ÁÖÀÇÇÒ Á¡Àº GetPoint·Î ÀԷ¹ÞÀº Á¡À» aDouble·Î º¯È¯ÇØÁà¾ß ÇÑ´Ù´Â °ÍÀÌ´Ù. ÀԷ¹ÞÀº pnt11À» º¯È¯ÇÏÁö ¾Ê°í Á÷Á¢ »ç¿ëÇϸé pywintypes.com_error¶ó´Â ¿À·ù°¡ ¹ß»ýÇÑ´Ù.

 

7. °´Ã¼ ¼±ÅÃ

pyautocad¿¡¼­´Â get_selection()¸¦ ÀÌ¿ëÇؼ­ °´Ã¼¸¦ ¼±ÅÃÇß´Ù. selection setÀ» ¸¸µé ÇÊ¿ä ¾ø¾ú´Ù. win32com¿¡¼­´Â selection setÀ» ¸¸µç ´ÙÀ½ selection setÀÇ ÇÏÀ§ ¸Þ¼ÒµåµéÀ» ÀÌ¿ëÇؼ­ °´Ã¼¸¦ ¼±ÅÃÇÒ ¼ö ÀÖ´Ù.

selection setÀ» Ãß°¡ÇÏ´Â ¹æ¹ýÀº ¾Æ·¡¿Í °°´Ù. ¡°SS1¡±Àº selection set À̸§À¸·Î ÀÓÀÇÀÇ À̸§À¸·Î ÁÙ ¼ö ÀÖ´Ù.

slcn = doc.SelectionSets.Add("SS1")

¸¸µé¾îÁø selection set °´Ã¼ÀÎ slcnÀ» ÀÌ¿ëÇؼ­ ´Ù¾çÇÑ ¼±Åà ¸Þ¼ÒµåµéÀ» ÀÌ¿ëÇÒ ¼ö ÀÖ´Ù. ¾Õ¿¡¼­ ´Ù¾çÇÑ select¹æ¹ýÀ» ¾Ë¾Æº¸¾Ò¾ú´Ù.

 

Select                    object.Select Mode [, Point1] [, Point2] [, FilterType, FilterData]

SelectAtPoint          object.SelectAtPoint Point, FilterType, FilterData

SelectByPolygon       object.SelectByPolygon Mode, PointsList [, FilterType, FilterData]

SelectOnScreen        object.SelectOnScreen [FilterType, FilterData]

 

Select ¸Þ¼ÒµåÀÇ Mode´Â ¾Æ·¡¿Í °°´Ù. ÀÌÀü pyautocad Æí¿¡¼­ ¼³¸íÇÑ °Íó·³ AutoCADÀÇ »ó¼ö¸¦ »ç¿ëÇÏ·Á¸é pyautocadÀÇ ACAD¸¦ importÇØ¾ß ÇÑ´Ù. ACAD¸¦ importÇϱ⠽ȴٸé Á÷Á¢ °ªÀ» »ç¿ëÇÏ¸é µÈ´Ù. ´ë½Å ¿øÇÏ´Â modeÀÇ °ªÀ» ¾Ë°í ÀÖ¾î¾ß ÇÑ´Ù.

¡Ü      acSelectionSetWindow        0

¡Ü      acSelectionSetCrossing        1

¡Ü      acSelectionSetPrevious        3

¡Ü      acSelectionSetLast             4       

¡Ü      acSelectionSetAll               5

SelectByPolygon ¸Þ¼ÒµåÀÇ Mode´Â ´ÙÀ½°ú °°´Ù. °¢ »ó¼öÀÇ °ªÀ» Á¦½ÃÇß´Ù.

¡Ü      acSelectionSetFence                    2

¡Ü      acSelectionSetWindowPolygon       6       

¡Ü      acSelectionSetCrossingPolygon      7

AutoCAD Object Model¿¡¼­ Á¦½ÃµÈ »ó¼öÀÇ °ªÀ» ¾Ë°í ½Í´Ù¸é ¾Æ³ªÄÜ´Ù Äֿܼ¡¼­ pythonÀ» ½ÇÇà½ÃÅ°°í from pyautocad import ACAD¸¦ ½ÇÇàÇÑ ´ÙÀ½ ACAD.acSelectionSetFence ¿Í °°ÀÌ Á÷Á¢ »ó¼ö¸íÀ» Ãâ·ÂÇغ¸´Â °ÍÀÌ °¡Àå È®½ÇÇÑ ¹æ¹ýÀÌ´Ù. ¹°·Ð Äڵ忡 ACAD¸¦ importÇÑ °æ¿ì¿¡´Â »ó¼ö¸íÀ» Á÷Á¢ »ç¿ëÇÏ¸é µÈ´Ù.

¾Æ·¡ÀÇ Äڵ带 º¸ÀÚ. ijµåÈ­¸é¿¡ ¼±,¿ø,È£,Ÿ¿øÀ» ±×¸®°í selection setÀ» ¸¸µç ´ÙÀ½ µÎ Á¡À» ÀÌ¿ëÇؼ­ À©µµ¿ì ¹Ú½º·Î °´Ã¼¸¦ ¼±ÅÃÇؼ­ °´Ã¼ À̸§À» Ãâ·ÂÇØÁÖ´Â ÄÚµå´Ù.

 ¿©±â¼­ vtpt¿Í vtobj ÇÔ¼ö ¼±¾ðÀ» ÁÖ¸ñÇÏÀÚ. °´Ã¼¸¦ ¼±ÅÃÇÒ ¶§ ÇÊÅ͸¦ »ç¿ëÇϱâ À§Çؼ­ ÇÊ¿äÇÑ ÇÔ¼ö¼±¾ðÀÌ´Ù. ÇÊÅÍ »ç¿ë¹ýÀº ftypº¯¼ö¿Í ftdtº¯¼ö¿¡ Ç׸ñ°ú °ªÀ» ÁöÁ¤ÇÑ´Ù. ftyp¿¡ [0,8]ÀÌ ÁöÁ¤µÇ¾îÀִµ¥ 0Àº °´Ã¼Çü½ÄÀ» ÀǹÌÇÏ´Â °ÍÀÌ°í 8Àº layer¸¦ ÀǹÌÇÏ´Â °ÍÀÌ´Ù. ftdtº¯¼ö¿¡ [¡°Line¡±,¡±0¡¯]ÀÌ ÁöÁ¤µÇ¾îÀִµ¥ ¾ÕÀÇ ftyp¿¡ ÇØ´çÇÏ´Â °ªÀÌ´Ù. Áï 0(°´Ã¼Çü½Ä)Àº ¡°Line¡±, 8(layer)Àº ¡°0¡±ÀÎ °´Ã¼¸¸ ¼±ÅÃÇÏ°Ú´Ù´Â ¶æÀÌ´Ù. ftyp°ú ftdt¸¦ Çüº¯È¯ÇØ¾ß ÇÔÀ» ÀØÁö ¸»ÀÚ.

0ÀÌ °´Ã¼Çü½ÄÀÌ°í, 8ÀÏ ·¹À̾î¶ó´Â Àǹ̴ DXF code¶ó°í ÇÑ´Ù. ±¸±Û¿¡¼­ dxf code¶ó°í °Ë»öÇÏ¸é ½±°Ô ã¾Æº¼ ¼ö ÀÖ´Ù. ¾Æ·¡ÀÇ ¸µÅ©´Â Autodesk ¹®¼­´Ù. http://docs.autodesk.com/ACAD_E/2012/ENU/filesDXF/WS1a9193826455f5ff18cb41610ec0a2e719-7a62.htm

¸î°¡Áö DXF Äڵ带 »ìÆ캸¸é ¾Æ·¡¿Í °°´Ù.

0 : entity type

1 : Primary text value for an entity

6 : linetype name

7 : text style name

8 : layer name

62 : color number

 

<selectw32com.py>

import win32com.client
import pythoncom

acad = win32com.client.Dispatch(
"AutoCAD.Application")
doc = acad.ActiveDocument
acadModel = doc.ModelSpace

def APoint(x, y, z = 0):
   
return win32com.client.VARIANT(pythoncom.VT_ARRAY | pythoncom.VT_R8, (x, y, z))

LineObj = acadModel.AddLine(APoint(
40,40) , APoint(500, 500))
CircleObj = acadModel.AddCircle(APoint(
300, 200), 100)
ArcObj = acadModel.AddArc(APoint(
600, 200), 50, 0, 1.57)
EllObj = acadModel.AddEllipse(APoint(
700, 200), APoint(100, 0), 0.5)

doc.Regen(
0)

def vtpt(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)

try:
    doc.SelectionSets.Item(
"SS1").Delete()
except:
    print(
"Delete selection failed")
slcn = doc.SelectionSets.Add(
"SS1")

ftyp = [
0,8]
ftdt=[
"Line","0"]

filterType = win32com.client.VARIANT(pythoncom.VT_ARRAY | pythoncom.VT_I2, ftyp)
filterData = win32com.client.VARIANT(pythoncom.VT_ARRAY | pythoncom.VT_VARIANT, ftdt)
# use filter
#slcn.Select(0, APoint(0,0), APoint(1000, 1000), filterType, filterData)
# no filter
slcn.Select(
0, APoint(0,0), APoint(2000, 2000))

print(slcn.count,
" Selected")
for i in slcn:
    print(i.ObjectName)
    doc.Utility.Prompt(i.ObjectName+
"\n")

 

À§ÀÇ Äڵ带 ½ÇÇàÇϸé ijµåÈ­¸é¿¡ ³×°³ÀÇ °´Ã¼°¡ ±×·ÁÁö°í ÄܼÖâ°ú ijµå¸í·Éâ¿¡ °¢°¢ 4°³ÀÇ °´Ã¼À̸§ÀÌ Ãâ·ÂµÈ´Ù. À§ ÄÚµå´Â ÇÊÅÍ ¾øÀÌ °´Ã¼¸¦ ¼±ÅÃÇÏ´Â °æ¿ìÀÌ°í ¾Æ·¡¿Í °°ÀÌ ÇÊÅÍ󸮸¦ Àû¿ëÇÑ ÁÙÀÇ #À» »èÁ¦ÇÏ°í ÇÊÅ͸¦ Àû¿ëÇÏÁö ¾ÊÀº ÁÙ¿¡ #À» Ãß°¡Çؼ­ ½ÇÇàÇÏ¸é ¼±¸¸ ¼±ÅõȴÙ.

# use filter
slcn.Select(
0, APoint(0,0), APoint(1000, 1000), filterType, filterData)
# no filter
#slcn.Select(0, APoint(0,0), APoint(2000, 2000))

(base) D:\dev\python\pyautocad>python selectw32com.py
4  Selected
AcDbEllipse
AcDbArc
AcDbCircle
AcDbLine

 

°´Ã¼ ¼±Åùæ¹ý Áß¿¡ Select, SelectAtPoint, SelectByPolygon ÀÌ ¼¼°¡Áö ¹æ¹ýÀº »ç¿ëÀÚ°¡ Á÷Á¢ ¼±ÅÃÇÏ´Â °ÍÀÌ ¾Æ´Ï¶ó Äڵ带 ÀÌ¿ëÇؼ­ ¼±ÅÃÇÏ´Â ¹æ¹ýÀÌ´Ù. »ç¿ëÀÚ°¡ Á÷Á¢ ¼±ÅÃÇϵµ·Ï ÇÒ ¶§´Â SelectOnScreenÀ» »ç¿ëÇÑ´Ù. pyautocadÀÇ acad.get_selection ¸Þ¼Òµå´Â ActiveXÀÇ SelectOnScreen¸Þ¼Òµå¸¦ »ç¿ëÇϱâ ÁÁ°Ô ±¸ÇöÇÑ °ÍÀÌ´Ù.

 

½ÇÁ¦·Î pyautocadÀÇ Äڵ带 »ìÆ캸ÀÚ. anaconda°¡ ¼³Ä¡µÈ µð·ºÅ丮 ¾Æ·¡¿¡ pyautocad µð·ºÅ丮¸¦ ã¾Æ°¡ º¸¸é (C:\ProgramData\Anaconda3\Lib\site-packages\pyautocad) api.py ÆÄÀÏÀ» º¼ ¼ö ÀÖ´Ù. ÀÌ ÆÄÀÏÀ» ¿­°í get_selectionÀ¸·Î °Ë»öÇغ¸¸é ¾Æ·¡ÀÇ Äڵ带 º¼ ¼ö ÀÖ´Ù. ³»¿ëÀ» »ìÆ캸¸é ¡°SS1¡±À̶ó´Â À̸§À¸·Î selection setÀ» ¸¸µé°í SelectOnScreen ¸Þ¼Òµå¸¦ ½ÇÇà½ÃÅ°´Â °ÍÀ» È®ÀÎÇÒ ¼ö ÀÖ´Ù.

<api.py>

    def get_selection(self, text="Select objects"):
       
""" Asks user to select objects

        :param text: prompt for selection
        """

        self.prompt(text)
       
try:
            self.doc.SelectionSets.Item(
"SS1").Delete()
       
except Exception:
            logger.debug(
'Delete selection failed')

        selection = self.doc.SelectionSets.Add(
'SS1')
        selection.SelectOnScreen()
       
return selection

 

 

8. ¸ËÀ½¸»

À̹ø ½Ã°£¿¡´Â win32comÀ¸·Î autocad¿¡¼­ °´Ã¼¸¦ »ý¼ºÇÏ°í ¼öÁ¤ÇÏ´Â °ÍÀ» ÇغôÙ. ´ëºÎºÐ ÀÌÀü ½Ã°£¿¡ ´Ù·ç¾ú´ø pyautocad¿¡¼­ Áö¿øÇÏ´Â ±â´ÉµéÀ̾ú´Ù. ÇÏÁö¸¸ getpoint´Â pyautocad¿¡¼­ Áö¿øÇÏÁö ¾Ê´Â ±â´ÉÀÌ´Ù. ¾Õ¿¡¼­ ¼³¸íÇßµíÀÌ pyautocad´Â ½±°Ô ActiveX¸¦ »ç¿ëÇÒ ¼ö ÀÖµµ·Ï ¸¸µç ¶óÀ̺귯¸®À̱⠶§¹®¿¡ ÇÑ°è°¡ ÀÖÀ» ¼ö ÀÖ´Ù. ±×·¡¼­ ActiveX ±â´ÉÀ» Á÷Á¢ »ç¿ëÇÏ´Â win32comÀ» ¾Ë¾Æº» °ÍÀÌ´Ù. pyautocad¿Í win32comÀ» µÑ´Ù importÇÏ°í pyautocad°¡ Áö¿øÇÏ´Â ±â´ÉÀº pyautocad¸¦ ÀÌ¿ëÇÏ°í pyautocad°¡ Áö¿øÇÏÁö ¾Ê´Â ±â´ÉÀº win32comÀ» ÀÌ¿ëÇÏ´Â °Íµµ ÁÁÀº ¹æ¹ýÀÏ ¼ö ÀÖ°í, Àüü Äڵ带 win32com¸¸À¸·Î ÀÛ¼ºÇÏ´Â °Íµµ ÇϳªÀÇ ¹æ¹ýÀÏ ¼ö ÀÖ´Ù. Áß¿äÇÑ °ÍÀº AutoCAD Object ModelÀ» ÀÌÇØÇÏ°í ÀÖ´Â °ÍÀÌ Áß¿äÇÏ´Ù. ±×¸®°í Çüº¯È¯¿¡ ½Å°æÀ» ½á¾ßÇÑ´Ù´Â °ÍÀ» ¸í½ÉÇÏÀÚ.

pyautocad¿Í win32comÀ» ºñ±³ÇÏ¸é ¾Æ·¡¿Í °°´Ù.

 

±â´É

pyautocad

win32com

import

from pyautocad import Autocad

import win32com.client

AutocadÁ¢±Ù

acad = Autocad()

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

Document,

ModelspaceÁ¢±Ù

ÇÊ¿ä¾øÀ½.

doc = acad.ActiveDocument
acadModel = doc.ModelSpace

prompt

acad.prompt("Hello, Autocad")

doc.Utility.Prompt(¡°Hello, Autocad")

°´Ã¼ Ãß°¡

acad.model.AddLine(p1, p2)

acadModel.AddLine(p1,p2)

Á¡ÀÔ·Â

¾øÀ½.

doc.Utility.GetPoint([Point [, Prompt]])

°´Ã¼¼±ÅÃ

acad.iter_objects(Á¶°Ç)

acad.get_selection(¡°¸Þ½ÃÁö¡±)

slcn = doc.SelectionSets.Add("SS1")

slcn.Select(mode, APoint1, APoint2)

slcn.SelectOnScreen()

 

 

-³¡-



À̼®Á¾
Select ¸Þ¼Òµå + Filter»ç¿ë ¿¹(Block Insert)
µµ¸é¿¡ »ðÀÔµÈ ºí·°µéÀ» Áß ¿øÇÏ´Â À̸§À» °¡Áø ºí·°µéÀ» ¼±ÅÃÇÏ´Â ¹æ¹ý

ftyp = [0,2,8]
ftdt=["INSERT","ELM","0"]

filterType = win32com.client.VARIANT(pythoncom.VT_ARRAY | pythoncom.VT_I2, ftyp)
filterData = win32com.client.VARIANT(pythoncom.VT_ARRAY | pythoncom.VT_VARIANT, ftdt)

slcn.Select(Mode=5, Point1=vtpt(0,0), Point2=vtpt(2000, 2000), FilterType=filterType, FilterData=filterData)

Mode=5´Â µµ¸é³»ÀÇ ¸ðµÎ¸¦ ´ë»óÀ¸·Î ÀÛµ¿ÇÑ´Ù.
Point1, Point2 : ¸ðµÎ¸¦ ¼±ÅÃÇÒ ¶§´Â ÇÊ¿ä ¾øÁö¸¸ ³Ö¾îÁØ´Ù.
FilterType, FilterData : DXF code 2¹øÀÌ À̸§ÀÌ´Ù.
2 Name (attribute tag, block name, and so on)

¸ðµç °´Ã¼¸¦ ¼±ÅÃÇؼ­ ÇϳªÇϳª ¿øÇÏ´Â °ÍÀ» if¹®À¸·Î ãÀ¸¸é ½Ã°£ÀÌ ²Ï °É¸°´Ù. ¿øÇÏ´Â °´Ã¼¸¦ ¼±ÅÃÇÏ´Â °ÍÀº ÇÊÅ͸¦ Àû´çÈ÷ ½á¼­ ijµå¿¡¼­ Á¦°øÇÏ´Â Select ±â´ÉÀ» ÀÌ¿ëÇÏÀÚ.
2023-01-09
05:18:10

 


  ÃßõÇÏ±â   ¸ñ·Ïº¸±â

Copyright 1999-2024 Zeroboard / skin by zero
±¸Á¶¼³°èÀÇ ¹Ì·¡¸¦ ÁغñÇÏ´Â ¸ðÀÓ [±¸Á¶¼³°è¹Ì·¡Æ÷·³]