Excel VBA, AutoCAD ActiveX ¸Àº¸±â °ÁÂ(22) |
Model space¿¡ EntityÃß°¡Çϱâ(3)
¾îÁ¦´Â circleÀ» Ãß°¡Çß½À´Ï´Ù. »ç½Ç µµ¸é¿¡ ÇÊ¿äÇÑ °ÍÀº circle,arc,line,textÁ¤µµ¸é ¸ðµç °Íµé Ç¥ÇöÇÒ ¼ö ÀÖÁö ¾ÊÀ»±î¿ä? ¿À´ÃÀº ±×·³ lineÀ» Ãß°¡ÇÏ´Â
¹æ¹ýÀ» ¾Ë¾Æº¸µµ·Ï ÇÏ°Ú½À´Ï´Ù. circleÀ» Ãß°¡ÇÏ´Â ¹æ¹ý°ú µ¿ÀÏÇÏ°ÚÁÒ? model space¸¦ Àâ¾Æ¼ addlineÀ̶õ ¸Þ¼µå¸¦ »ç¿ëÇؼ Ãß°¡ÇØÁÖ¸é µÇ°Ú½À´Ï´Ù.
¹°·Ð lineÀº ùÁ¡°ú ³¡Á¡ Á¤º¸°¡ ÀÖ°ÚÁÒ? circle¿¡¼ centerÁ¡À» array·Î Àâ¾ÆÁØ °Í ó·³ ùÁ¡°ú ³¡Á¡À» array·Î Àâ¾ÆÁÖ¸é µÉ °ÍÀÔ´Ï´Ù.
¾îÁ¦ÀÇ Äڵ忡¼ array¼±¾ðÇÏ´Â ºÎºÐ°ú addline¸Þ¼µå ºÎºÐ¸¸ °íÃÄÁÖ¸é lineÀ» Ãß°¡ÇÏ´Â ·çƾÀº ¾ÆÁÖ °£´ÜÇÏ°Ô ¸»µé¾îÁú °ÍÀÔ´Ï´Ù. µµ¿ò¸»À» ÂüÁ¶ÇϽñ¸¿ä.
µµ¿ò¸»ÀÇ exampleÀ» ÀÌ¿ëÇÏ´Â °Íµµ ÁÁÀº ¹æ¹ýÀÔ´Ï´Ù. »ç½Ç ¼³¸í ¸îÁÙÀ» Àд °Íº¸´Ù ¿¹Á¦ ¼Ò½ºÇѹø º¸´Â°Ô ÀÌÇØ°¡ ÈξÀ ºü¸¦ ¼ö ÀÖÀ¸´Ï±î¿ä.
Sub Macro1()
Dim acad As Object 'AutoCAD°³Ã¼¸¦ ³Ö¾îµÑ º¯¼ö
Dim l As Object 'line object¸¦ ³Ö¾îµÑ º¯¼ö
Dim pnt1(2) As Double '½ÃÀÛÁ¡À» ³Ö¾îµÑ ¹è¿
Dim pnt2(2) As Double '³¡Á¡À» ³Ö¾îµÑ ¹è¿
pnt1(0) = 0 'xÁÂÇ¥
pnt1(1) = 0 'yÁÂÇ¥
pnt1(2) = 0 'zÁÂÇ¥
pnt2(0) = 1 'xÁÂÇ¥
pnt2(1) = 1 'yÁÂÇ¥
pnt2(2) = 0 'zÁÂÇ¥
Set acad = GetObject(, "AutoCAD.application")
Set l = acad.activedocument.modelspace.AddLine(pnt1, pnt2)
End Sub
À̹ø¿¡´Â text¸¦ Ãß°¡ÇÏ´Â ¹æ¹ýÀ» ¾Ë¾Æº¸µµ·Ï ÇÏ°Ù½À´Ï´Ù. text¸¦ Ãß°¡Çϱâ À§Çؼ´Â »ðÀÔÁ¡°ú text string ±×¸®°í text³ôÀÌ°¡ ÇÊ¿äÇÕ´Ï´Ù.
¿ª½Ã »ðÀÔÁ¡Àº array·Î µÇ¾îÀÖ¾î¾ß Çϱ¸¿ä. ¾Æ·¡ÀÇ ÄÚµå´Â µµ¿ò¸»ÀÇ addtext¿¡ ´ëÇÑ ¿¹Á¦ ÄÚµåÀÔ´Ï´Ù. ±³°ú¼ÀûÀÎ ÄÚµåÀÌ´Ï Çѹø ´«¿©°Üº¸½Ã´Â
°Íµµ ÁÁÀ» °Í °°½À´Ï´Ù. ƯÀÌÇÑ °ÍÀº dim textObj As AcadText¶ó°í ¼±¾ðÇß½À´Ï´Ù. ±×³É As ObjectÇصµ µÉÅÙµ¥ AcadText¶ó°í ÇßÀ»±î¿ä?
Sub Example_AddText()
' This example creates a text object in model space.
Dim textObj As AcadText
Dim textString As String
Dim insertionPoint(0 To 2) As Double
Dim height As Double
' Define the text object
textString = "Hello, World."
insertionPoint(0) = 2: insertionPoint(1) = 2: insertionPoint(2) = 0
height = 0.5
' Create the text object in model space
Set textObj = ThisDrawing.ModelSpace.AddText(textString, insertionPoint, height)
ZoomAll
End Sub
±×¸®°í ÀÌ Äڵ带 ½ÇÇà½ÃÅ°¸é ¾Æ·¡¿Í °°Àº ¿¡·¯¸Þ¼¼Áö°¡ ³ª¿É´Ï´Ù. µµ¿ò¸» ÆÄÀÏ¿¡ ½ÇÇ൵ ¾ÈµÇ´Â ¿¹Á¦¸¦ ³Ö¾î³õ´Ù´Ï.. ÇÏ¸é¼ ¿åÇÏ½Ç ºÐµéµµ ¸¹À¸¸®¶ó
»ý°¢µË´Ï´Ù.
Á¦°¡ ¼³¸íµå¸° ±âÁ¸Äڵ忡¼´Â Ç×»ó °³Ã¼¸¦ object·Î ¼±¾ðÇÏ¿´½À´Ï´Ù. ¾î¶²ÇüÅÂÀÇ objectÀÎÁö´Â ¸ð¸£Áö¸¸ ¾ÏÆ° object·Î ¼±¾ðÇß´ø °ÍÀÔ´Ï´Ù.
ÇÏÁö¸¸ À§ÀÇ Äڵ忡¼´Â textObj¶ó´Â º¯¼ö¿¡ text object°¡ µé¾î°¥ °ÍÀÌ È®½ÇÇϱ⠶§¹®¿¡ object°¡ ¾Æ´Ñ AcadText¶ó´Â ÇüÀ» »ç¿ëÇÑ °ÍÀÔ´Ï´Ù. object´Â
objectÀε¥ AcadText object¶ó´Â À̾߱â ÀÔ´Ï´Ù.
±×·¸´Ù¸é ¿Ö ½ÇÇàÀÌ ¾ÈµÇ°í ¿¡·¯°¡ ³µÀ»±î¿ä? ¿¡·¯¸Þ½ÃÁö¸¦ º¸¸é "»ç¿ëÀÚÁ¤ÀÇ Çü½ÄÀÌ Á¤ÀǵÇÁö ¾Ê¾Ò½À´Ï´Ù"¶ó°í µÇ¾îÀÖ½À´Ï´Ù. ¾î´ÀºÎºÐ¿¡¼ ¿¡·¯°¡ ³µÀ»±î?
ÇÏ°í ã¾Æ°¡º¸µµ·Ï ÇÒ±î¿ä? È®ÀιöÆ°À» ´©¸£¸é ¾Æ·¡±×¸²Ã³·³ ¿¡·¯°¡ ³ºÎºÐÀ» º¸¿©ÁÝ´Ï´Ù.
ÇÁ·Î±×·¥ ½ÇÇàÀÌ ¿¡·¯°¡ ³ºÎºÐ¿¡¼ ¸ØÃß¾îÀÖ½À´Ï´Ù. ÀÌ·± »óŸ¦
µð¹ö±ë »óŶó°í ÇÏ°í ¿¡·¯°¡ ³ ºÎºÐÀ» ¼öÁ¤À» °¡ÇÑ´ÙÀ½¿¡ °è¼Ó ½ÇÇà½Ãų ¼ö ÀÖ½À´Ï´Ù. µð¹ö±ë¿¡ ´ëÇؼ´Â ³ªÁß¿¡ ¼³¸íµå¸®±â·Î ÇÏ°í ¾ÏÆ° ¿¡·¯°¡ ³ºÎºÐÀº
¹Ù·Î Dim textObj As AcadText <-- À̺κÐÀÔ´Ï´Ù. ¿ì¸®°¡ dim ¹®À¸·Î ¼±¾ðÇØÁÙ ¼ö ÀÖ´Â µ¥ÀÌÅÍÀÇ ÇüÀº ¸î°¡Áö ÀÖ½À´Ï´Ù. integerµµ ÀÖ°í doubleµµ ÀÖ½À´Ï´Ù.
ÇÏÁö¸¸ ÀÌ ÄÚµåÀÇ AcadText´Â VBA°¡ ÀνÄÇÏÁö ¸øÇÏ´Â ÇüÀÔ´Ï´Ù. ÇöÀç Äڵ尡 ½ÇÇàÁßÀÎ Excel¿¡´Â ÀÌ·± ÇüÀÌ Á¤ÀÇ µÇ¾îÀÖÁö ¾Ê±â ¶§¹®ÀÔ´Ï´Ù.
±×·¸´Ù¸é AutoCAD ¿¹Á¦¿¡´Â ¿Ö ÀÌ·± Äڵ带 ³Ö¾îµÎ¾úÀ»±î¿ä? ¹°·Ð AutoCAD±â¹ÝÀÇ VBA¿¡¼´Â ÀÌ Äڵ尡 ¹®Á¦¾øÀÌ µ¹¾Æ°©´Ï´Ù. AutoCAD2000ºÎÅÍ´Â
tools¸Þ´º¿¡ macro¶ó´Â VBA¸Þ´º°¡ ÀÖÁö¿ä. °Å±â¿¡¼ À§¿Í°°Àº Äڵ带 ½ÇÇà½ÃÅ°¸é Àß µ¹¾Æ°©´Ï´Ù.
±×·¸´Ù¸é Excel VBA¿¡¼´Â AcadText°°Àº ÇüÀ» »ç¿ëÇÏÁö ¸øÇÏ´Â °ÍÀϱî¿ä? .. ¾Æ´Õ´Ï´Ù. AutoCAD°¡ Áö¿øÇÏ´Â ÇüÀ» Á¤ÀÇÇÏ¸é »ç¿ëÇÏ¸é µÇ´Â °ÍÀÔ´Ï´Ù.
¿ì¸®°¡ Á÷Á¢ Á¤ÀÇÇÏ´Â °ÍÀÌ ¾Æ´Ï°í Á¤ÀǸ¦ ¸ð¾ÆµÐ ÆÄÀÏÀ» ÂüÁ¶ÇÔÀ¸·Î¼ °¡´ÉÇÕ´Ï´Ù. VBA EditorâÀÇ µµ±¸¸Þ´º¸¦ º¸¸é ¾Æ·¡¿Í °°ÀÌ ÂüÁ¶Ç׸ñÀÌ ÀÖ½À´Ï´Ù.
ÀÌ Ç׸ñÀ» Ŭ¸¯ÇÏ¸é ¾Æ·¡ ±×¸²°ú °°Àº ÂüÁ¶Ç׸ñÀ» ¼±ÅÃÇÒ ¼ö âÀÌ ¶å´Ï´Ù.
¿©±â¼ AutoCAD type library¸¦ ¼±ÅÃÇÕ´Ï´Ù. ¾Æ·¡ ±×¸²¿¡¼´Â À§ÂÊ¿¡ ¿Ã¶ó¿Í ÀÖÁö¸¸
¿©·¯ºÐµéÀÇ ÄÄÇ»ÅÍ¿¡´Â ¾Æ·¡ÂÊ¿¡ ÀÖÀ»Áöµµ ¸ð¸¨´Ï´Ù. ¾ÆÆÐÂÊÀ¸·Î °¡¸é¼ ã¾Æº¸¸é µÉ °ÍÀÔ´Ï´Ù. type library¿¡´Â AcadText°°Àº Çüµµ Á¤ÀÇ µÇ¾îÀÖ°í
¶ÇÇÑ »ó¼öµµ Á¤ÀǵǾî ÀÖ½À´Ï´Ù. ÀÌ ÆÄÀÏÀ» ÂüÁ¶ÇÔÀ¸·Î¼ ºñ·Î¼Ò AutoCAD¿Í ExcelÀÌ ¿ÏÀüÈ÷ ¿¬°áµÇ¾ú´Ù°íÇÒ ¼ö ÀÖ½À´Ï´Ù.
±×·³ ³»ÀÏ °è¼ÓÇϵµ·Ï ÇÏ°Ú½À´Ï´Ù.
[ÀÌÀü °ÁÂ]
[´ÙÀ½ °ÁÂ]
|