ID:
PW:

     0 ºÐ
     26 ºÐ

¿£Áö´Ï¾î µ¹Á¾
  dolljong

Áö½ÄÀº °øÀ¯µÇ¾úÀ» ¶§ ±× ÈûÀ» ¹ßÈÖÇÑ´Ù.


Excel VBA, AutoCAD ActiveX ¸Àº¸±â °­ÁÂ(16)

Excel°ú AutoCAD¿¬°á(1)
Á¦°¡ óÀ½ ActiveX¸¦ °øºÎÇϸ鼭 ¶â¾îº¸¾Ò´ø ÇÁ·Î±×·¥ÀÌ r14¹öÁ¯ÀÇ ¿¹Á¦ ÆÄÀÏ·Î µû¶ó¿Ô´ø ÇÁ·Î±×·¥ÀÔ´Ï´Ù. ijµåÀÇ attribute¸¦ Àо Excel½¬Æ®¿¡ »Ñ·ÁÁÖ´Â ÇÁ·Î±×·¥À̾ú½À´Ï´Ù. Uno21´ÔÀÇ "Excel·Î ¹è¿ì´Â VB"°­Á¸¦ ¸î¹ø Àо °É »©°í¼­´Â Excel¿¡¼­ ÇÁ·Î±×·¥À» ¸¸µé¾îº» ÀûÀÌ ¾ø¾ú°í, ¸¸µé Çʿ伺µµ ´À³¢Áö ¸øÇÏ´ø Â÷¿¡, Excel°ú AutoCADÀÇ ¿¬°áÀº Á¤¸» ³î¶ó¿î ÀÏÀ̾ú½À´Ï´Ù.

±× ÆÄÀÏÀº r14¿¡µµ ÀÖ¾úÁö¸¸ 2000¿¡µµ ÀÖ´õ±º¿ä. sample¹æÀÇ activex¹æ¿¡ ¼¼°³Á¤µµÀÇ ¿¹Á¦ µð·ºÅ丮°¡ Àִµ¥ ±×Áß Çϳª°¡ ExcelÆÄÀÏ·Î µÇ¾îÀÖ´Â ÇÁ·Î±×·¥ÀÔ´Ï´Ù. Extattr.xls·Î µÇ¾îÀÖ½À´Ï´Ù. ÀÌ ¿¢¼¿ÆÄÀÏÀ» ¶ç¿öº¸µµ·Ï ÇÏ°Ú½À´Ï´Ù. ¾Æ¹«·¡µµ AutoCAD¿¡¼­ Á¦°øÇÏ´Â ÇÁ·Î±×·¥ÀÌ´Ï Á¤È®ÇÑ ¹®¹ýÀ» ±¸»çÇÏ°í ÀÖÀ» °Í °°¾Æ ÀÌ ÇÁ·Î±×·¥À¸·Î AutoCAD¿ÍÀÇ ¿¬°á¿¡ ´ëÇؼ­ À̾߱â Çغ¸µµ·Ï ÇÏ°Ú½À´Ï´Ù.

¿ì¼± ÇÁ·Î±×·¥À» Çѹø »ì¦ º¼±î¿ä? ¹«Áö ±ä°Í °°Áö¸¸ ¸ðµç ÇÁ·Î±×·¥Àº ¼ø¼­´ë·Î Àаųª ÇÔ¼öº°·Î ¶Ç´Â ±â´Éº°·Î ³ª´²Á® Àֱ⠸¶·ÃÀÌÁö¿ä. ºÎºÐºÎºÐÀ» ÀÌÇØÇÏ°í ³ª¸é ÀüüÀûÀÎ È帧ÀÌ º¸ÀÏ °Í ÀÔ´Ï´Ù. ¾Æ·¡´Â extattr.xlsÀÇ ¸ðµâ¿¡ µé¾îÀÖ´Â ÄÚµåÀÇ ¾ÕºÎºÐÀÔ´Ï´Ù.

Public acad As Object
Public mspace As Object
Public excel As Object
Public AcadRunning As Integer
Public excelSheet As Object
Sub Extract()
    Dim sheet As Object
    Dim shapes As Object
    Dim elem As Object
    Dim excel As Object
    Dim Max As Integer
    Dim Min As Integer
    Dim NoOfIndices As Integer
    Dim excelSheet As Object
    Dim RowNum As Integer
    Dim Array1 As Variant
    Dim Count As Integer
     
    Set excel = GetObject(, "Excel.Application")
    Worksheets("Attributes").Activate
    Set excelSheet = excel.ActiveWorkbook.Sheets("Attributes")
    excelSheet.Range(Cells(1, 1), Cells(1000, 100)).Clear
    excelSheet.Range(Cells(1, 1), Cells(1, 100)).Font.Bold = True
    Set acad = Nothing
    On Error Resume Next
    Set acad = GetObject(, "AutoCAD.Application")
    If Err <> 0 Then
        Set acad = CreateObject("AutoCAD.Application")
        MsgBox "Open the drawing file first and then rexecute!"
        Exit Sub
    End If
'    acad.Visible = True
    Set doc = acad.ActiveDocument
    Set mspace = doc.ModelSpace
    
    ...ÀÌÇÏ»ý·«...

À½.. Á» ±æ±º¿ä. ÇÏÁö¸¸ ´ëºÎºÐ ºñ½ÁÇÑ °ÍµéÀÌ ¹Ýº¹µÇ¾îÀֱ⠶§¹®¿¡ ±æ¾îº¸ÀÏ »ÓÀÔ´Ï´Ù. Á¤ÀÛ Áß¿äÇÑ ÁÙÀº ¸îÁÙ ¾ÈµË´Ï´Ù. ¹°·Ð ¸ðµç ÁÙÀÌ ÀÖ¾î¾ß ÇÁ·Î±×·¥ÀÌ µ¹¾Æ°¡°ÚÁö¸¸, Á¦°¡ Áß¿äÇÏ´Ù°í ¸»ÇÑ ºÎºÐÀº ¿ì¸®ÀÇ È­µÎÀÎ AutoCAD¿Í ExcelÀÇ ¿¬°áÇÏ´Â ¹æ¹ýÀÌ°ÚÁÒ.

¿ì¼± ¾ÕºÎºÐ ºÎÅÍ º¸µµ·Ï ÇÏ°Ú½À´Ï´Ù. ùÁÙ¿¡ Public acad as object¶ó°í ³ª¿ÍÀÖ½À´Ï´Ù. º¯¼ö¸¦ ¼±¾ðÇÏ´Â ºÎºÐÀÔ´Ï´Ù. »ç½Ç ÀÌ °­Á¸¦ ÁøÇàÇϸ鼭 Á¶±Ý °ÆÁ¤µÇ´Â ºÎºÐÀÌ Á¦°¡ VB Àüü¸¦ °­ÁÂÇص帱 ¼ö ¾ø´Ù´Â °ÍÀÔ´Ï´Ù. ±âº»ÀûÀ¸·Î VB¿¡ ´ëÇؼ­ ¾î´ÀÁ¤µµ ¾Ë°í ÀÖ¾î¾ß Çϴµ¥.. ¾ÏÆ° Àü ¿©·¯ºÐÀÌ ¾î´ÀÁ¤µµ VB¿¡ ´ëÇؼ­ ¾Ë°í ÀÖ´Ù´Â ÀüÁ¦ÇÏ¿¡ °­Á¸¦ ÁøÇàÇÏ°í ÀÖ½À´Ï´Ù. publicÀ¸·Î Á¤ÀÇÇϸé Àü¿ªº¯¼ö°¡ µÇ´Â °ÍÀÌÁö¿ä. ÀÌÇÏ ¸ðµç subÀ̳ª function¿¡¼­ ÀÌ º¯¼öÀÇ °ªÀ» ÂüÁ¶ÇÒ ¼ö°¡ ÀÖ½À´Ï´Ù. ¾ÏÆ° public acad as object¶ó°í acad¶ó´Â º¯¼ö¸¦ Á¤ÀÇÇߴµ¥, as integer³ª as doubleµîÀº ¸¹ÀÌ º¸¾Æ¿Â Çü½ÄÀε¥ object´Â Á» »ý¼ÒÇÒ ¼ö ÀÖÀ» °Í °°½À´Ï´Ù. ¾ðÁ¨°¡ Á¦°¡ oop¿¡ ´ëÇؼ­ ¸»¾¸µå·È´Âµ¥ °³Ã¼,¸Þ¼Òµå,¼Ó¼ºÀÌ ÀÖ´Ù°í ÇßÁÒ? ¹Ù·Î acad¶ó´Â º¯¼ö´Â °³Ã¼ÇüŶó´Â °ÍÀ» Á¤ÀÇÇØÁÖ´Â °ÍÀÔ´Ï´Ù.

°³Ã¼ÇüÀ¸·Î Á¤ÀǵǴ º¯¼ö°¡ ¸î°³ ÀÖ´Â °ÍÀ» º¼ ¼ö ÀÖ½À´Ï´Ù. acadµµ ±×·¸°í, mspace¶ó´Â ¹ºÁö ¸ð¸£´Â °Í ±×·¸°í, Excel°ú Excelsheet¶ó´Â ³à¼®µµ ¸ðµÎ °³Ã¼ÇüÀ¸·Î Á¤ÀǵǾú½À´Ï´Ù. ÀÌ·¸°Ô Á¤ÀǸ¦ ÇÒ ¶§±îÁö´Â acad, excel, excelsheetº¯¼ö¿¡ ¾Æ¹«°Íµµ µé¾î°¡Áö ¾Ê½À´Ï´Ù. ±×³É À̰͵éÀº °³Ã¼¸¦ ÀúÀåÇÏ´Â º¯¼öµéÀÌ´Ù.. ¶ó°í Á¤ÀǸ¸ ÇÏ´Â °ÍÀÌÁö¿ä.. ¼±¾ðÇÑ´Ù°íµµ ÇÕ´Ï´Ù.

objectÇüÀÇ º¯¼öµéÀ» Á¤ÀÇÇÏ°í ³ª¼­´Â ¾î¶² °ÍÀ» ÇÒ±î¿ä? ¹Ù·Î sub Extract()·Î ¹Ù·Î ÇÁ·Î±×·¥À¸·Î µé¾î°©´Ï´Ù. ¿ª½Ã ¶Ç ¸î°³ÀÇ objectÇü°ú inger±×¸®°í VariantÇüÀÇ º¯¼öµéÀ» Á¤ÀÇÇØÁÝ´Ï´Ù. ³ªÁß¿¡ ÀÌ·± °ÍµéÀ» ÇÁ·Î±×·¥¿¡¼­ »ç¿ëÇÏ°ÚÁö¿ä? ¾ÏÆ° Áö±ÝÀº ÀÌ·¸°Ô Á¤Àǵȴٴ °Í¸¸ ¾Ë°í ³Ñ¾î°¡µµ·Ï ÇÏ°Ú½À´Ï´Ù. ¿ì¸®°¡ °ü½ÉÀÌ ÀÖ´Â °ÍÀº ´ÙÀ½¿¡ ÀÌ º¯¼öµéÀ» ÅëÇØ ¾î¶»°Ô AutoCAD¿¡ Á¢±ÙÇÏ´À³ÄÀ̴ϱî¿ä.

dim¹®µéÀÌ ³¡³ª°í ³ª¼­ ùÁÙÀÌ ¹Ù·Î Set Excel=GetObject(,"Excel.Application")À̶õ ÁÙÀÔ´Ï´Ù. ¹«¾ùÀÌ°¡ Áß¿äÇÑ ¿ªÇÒÀ» ÇÏ°í ÀÖ´Â °Í °°À̺¸ÀÔ´Ï´Ù. ±×·±µ¥ Excel=¾ÕÀÇ setÀº ¹«¾ùÀϱî¿ä? º¸Åë º¯¼ö¿¡ ¹º°¡¸¦ ´ëÀÔÇÒ ¶§´Â ±×³É µîÈ£¸¸ ½áÁÖ¸é µÇ´Â °ÍÀ¸·Î ¾Ë°í ÀÖ¾ú´Âµ¥.. setÀº ¿Ö ¼¹À»±î¿ä? Àú ¶ÇÇÑ Ã³À½¿¡ activexÇÁ·Î±×·¥À» °øºÎÇϸ鼭 ±×·± Àǹ®Á¡À» °¡Á³´Âµ¥¿ä. ÀÏ´Ü objectÇüÀÇ º¯¼ö¿¡ ¹«¾ùÀΰ¡¸¦ ´ëÀÔÇÒ ¶§´Â ¹Ýµå½Ã setÀ» »ç¿ëÇؾߵȴٴ °ÍÀ» ¾Ë°í °è¼Å¾ß ÇÕ´Ï´Ù. ¾Æ·¡ÂÊÀ» ÂÞ¿í ÈȾ¾Æµµ ¾Ë¼ö ÀÖµíÀÌ object·Î ¼±¾ðµÈ º¯¼ö¿¡ ¹«¾ùÀΰ¡¸¦ ÇÒ´çÇÒ ¶§´Â ¸ðµÎ setÀ» ÀÌ¿ëÇÑ °ÍÀ» º¼ ¼ö ÀÖ½À´Ï´Ù.

¾Ñ.. ¿À´Ãµµ Á¡½É½Ã°£ÀÌ... ÂÁ.. ¹º À̾߱Ⱑ Á» Ç®¸±·Á°í Çϸé Á¡½É½Ã°£ÀÌ ³¡³ª¹ö¸®³×¿ä.. ¸¶Ä¡ ¿¬¼Ó±Øó·³...
±×·³ ³»ÀÏ ¶Ç °è¼ÓÇÏ°Ú½À´Ï´Ù.

[ÀÌÀü °­ÁÂ]     [´ÙÀ½ °­ÁÂ]


dolljong@gmail.com