鱼C论坛

 找回密码
 立即注册

CAD export each drawing to form separate dwg file

已有 549 次阅读2016-8-18 14:09 |个人分类:Study Script

'testing export each drawing from the cubicle drawing as separate file. 
Sub inttest()
Dim entry As AcadEntity
Dim BlockObj As AcadBlock
Dim ssetObj As AcadSelectionSet
Dim moSpace As AcadModelSpace
Set moSpace = ThisDrawing.ModelSpace
Dim minExt As Variant
Dim maxExt As Variant
Dim minExt1 As Variant
Dim maxExt1 As Variant
Dim test1 As Variant
Dim test2 As Variant
Dim name As String
Dim txt As String
j = 0
Dim count As Integer
count = 0
    'count = ThisDrawing.ModelSpace.count
'MsgBox count
For Each entry In ThisDrawing.ModelSpace
    count = count + 1
    'MsgBox "objid is " & entry.ObjectID
    'MsgBox "objname is " & entry.ObjectName
  
    
    
    If entry.ObjectName = "AcDbBlockReference" Then
        If entry.name = "FDFDSGDGFDH" Then
            j = j + 1
            'If j = 1 Then
            entry.GetBoundingBox minExt, maxExt
            'MsgBox "The extents of the bounding box for the drawing are:" & vbCrLf _
         & "Min Extent: " & minExt(0) & "," & minExt(1) & "," & minExt(2) _
         & vbCrLf & "Max Extent: " & maxExt(0) & "," & maxExt(1) & "," & maxExt(2), vbInformation, "GetBoundingBox Example"
            ReDim minExt1(2)
            ReDim maxExt1(2)
            minExt1(0) = minExt(0) - 10
            minExt1(1) = minExt(1) - 10
            minExt1(2) = minExt(2)
            maxExt1(0) = maxExt(0) + 10
            maxExt1(1) = maxExt(1) + 10
            maxExt1(2) = maxExt(2)
            
            'End If
            Do While ThisDrawing.SelectionSets.count > 0
                ThisDrawing.SelectionSets.Item(0).Delete
            Loop
            Set ssetObj = ThisDrawing.SelectionSets.Add("TEST_SELECTIONSET")

            Set objUtility = ThisDrawing.Utility
            objUtility.CreateTypedArray test1, vbDouble, minExt1(0), minExt1(1), minExt1(2)
            objUtility.CreateTypedArray test2, vbDouble, maxExt1(0), maxExt1(1), maxExt1(2)

            ssetObj.Select acSelectionSetCrossing, test1, test2
            
            
            'MsgBox "ssetObj.count is " & ssetObj.count
            For Each objobj In ssetObj
                    If objobj.ObjectName = "AcDbText" Then
                        txt = objobj.TextString
                        If InStr(txt, "853/W/") > 0 Then
                            name = Right(txt, 3)
                            name = Left(ThisDrawing.name, Len(ThisDrawing.name) - 4) & "-" & name & ".dwg"
                        End If
                    End If
            Next
'name = ShowSave(ThisDrawing.HWND, "Drawing1.dwg", "新建图形文件", "图形(*.dwg)")
'ThisDrawing.Wblock name, ssetObj
'ThisDrawing.Wblock ShowSave(ThisDrawing.HWND, "Drawing1.dwg"), ssetObj
            'name = j & ".dwg"
            ThisDrawing.Wblock name, ssetObj
        End If
        
    
    End If
Next
MsgBox "job finish!"

End Sub

路过

鸡蛋

鲜花

握手

雷人

评论 (0 个评论)

facelist

您需要登录后才可以评论 登录 | 立即注册

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-5-6 10:06

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

返回顶部