乐筑天下

搜索
欢迎各位开发者和用户入驻本平台 尊重版权,从我做起,拒绝盗版,拒绝倒卖 签到、发布资源、邀请好友注册,可以获得银币 请注意保管好自己的密码,避免账户资金被盗
查看: 26|回复: 0

[编程交流] 将Dwg集从DA转换为CC

[复制链接]

28

主题

130

帖子

126

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
154
发表于 2022-7-6 17:14:37 | 显示全部楼层 |阅读模式
有人能给我一些关于如何改进我的编码格式等的建议吗?关于如何改进下面的代码有什么建议吗??
 
谢谢
 
下面的代码是我编写的将图形集从DA更改为CC的代码的一部分
它首先从R:\Jobs 2007\07447\Acad\DA复制完整的图形集,并将其粘贴到R:\Jobs 2007\07447\Acad\CC
将单个图形从07447\u DA\u C000重命名为07447\u CC\u C000,然后进入图形并将标题栏中的属性从07447\u DA\u C000重命名为07447\u CC\u C000,然后卸载外部参照-将其从XR07447\u DA\u SURVEY重命名为XR07447\u CC\u SURVEY,并将其重新定位到新的CC文件夹。
 
如果需要的话,我可以提供表格。
 
干杯伙计们
 
 
  1. Public FormResultREV As Boolean
  2. Sub RevUpDrawings()
  3. Dim tmpyearREV As Integer
  4. Dim JobDirectorycurrentREV, jobdirectoryNEWREV, JobNoDirectory, JobYearREV As String
  5. Dim CURREV, NEWREV, CURREVPATH, NEWREVPATH, result As String
  6. Dim fs
  7. If FormResultREV Then
  8.        tmpyearREV = CDbl(VBA.Left(UserFormcombined.JOBNOREV, 2))
  9.    If tmpyearREV > 80 Then
  10.        tmpyearREV = 1900 + tmpyearREV
  11.    Else
  12.        tmpyearREV = 2000 + tmpyearREV
  13.    End If
  14.        JobYearREV = CStr(tmpyearREV)
  15.        CURREV = "_" & UserFormcombined.CurrentStageREV & "_"
  16.        NEWREV = "_" & UserFormcombined.NewStageREV & "_"
  17.        jobdirectoryNEWREV = "R:\Jobs " & JobYearREV & "" & UserFormcombined.JOBNOREV & "\ACAD" & UserFormcombined.NewStageREV
  18.        JobDirectorycurrentREV = "R:\Jobs " & JobYearREV & "" & UserFormcombined.JOBNOREV & "\ACAD" & UserFormcombined.CurrentStageREV
  19.    'Create new directory and copy all old contents
  20.    Set fs = CreateObject("scripting.filesystemobject")
  21.    MkDir jobdirectoryNEWREV
  22.    fs.CopyFile JobDirectorycurrentREV & "\*", jobdirectoryNEWREV
  23.    'Rename all drawings
  24.    result = Dir((jobdirectoryNEWREV & "\*.dwg"))
  25.    Do
  26.        If result = "" Then Exit Do
  27.            Name jobdirectoryNEWREV & "" & result As jobdirectoryNEWREV & "" & Replace(result, CURREV, NEWREV)
  28.        result = Dir()
  29.    Loop
  30.            MsgBox "The entire " & UserFormcombined.CurrentStageREV & " drawing set for Job Number " & UserFormcombined.JOBNOREV & " has been converted to a " _
  31.            & UserFormcombined.NewStageREV & " drawing set." & VBA.Chr(13) & "Drawings have been created in the new directory " & jobdirectoryNEWREV & VBA.Chr(13) & _
  32.            "Drawings will be now be opened so that title block attributes can be edited and xrefs can be renamed and repathed." & VBA.Chr(13) & VBA.Chr(13) & "Please wait until finished. Thank you", vbInformation, "ATTENTION PLEASE READ"
  33. renamedrawingnumbers
  34. End If
  35. End Sub
  36. Function renamedrawingnumbers()
  37. Dim i, j, k As Integer
  38. Dim element, ArrayAttributes
  39. Dim jobdirectoryNEWREV, JobYearREV, tmpyearREV, OldDWGNO, NewDWGNO As String
  40. Dim CURREV, NEWREV, revtest As String
  41.    tmpyearREV = CDbl(VBA.Left(UserFormcombined.JOBNOREV, 2))
  42.    If tmpyearREV > 80 Then
  43.    tmpyearREV = 1900 + tmpyearREV
  44.    Else
  45.    tmpyearREV = 2000 + tmpyearREV
  46.    End If
  47.    JobYearREV = CStr(tmpyearREV)
  48.    revtest = CStr(VBA.Left(UserFormcombined.NewStageREV, 1))
  49.    If revtest = "C" Then
  50.    revtest = "A"
  51.    Else
  52.    revtest = "01"
  53.    End If
  54.        CURREV = "_" & UserFormcombined.CurrentStageREV & "_"
  55.        NEWREV = "_" & UserFormcombined.NewStageREV & "_"
  56.        jobdirectoryNEWREV = "R:\Jobs " & JobYearREV & "" & UserFormcombined.JOBNOREV & "\ACAD" & UserFormcombined.NewStageREV
  57. On Error Resume Next
  58.        For i = 1 To UserFormcombined.ListBox5REV.ListCount
  59.        UserFormcombined.ListBox5REV.ListIndex = i - 1
  60.        Documents.Open jobdirectoryNEWREV & "" & UserFormcombined.ListBox5REV.Text    'open each drawing in listbox
  61.                    For j = 0 To ThisDrawing.Layouts.Count - 1 'loop through each tab and update info
  62.                If ThisDrawing.Layouts(j).Name = "Model" Then GoTo 10
  63.                ThisDrawing.SendCommand "layout s " & ThisDrawing.Layouts(j).Name & vbCr
  64.                For Each element In ThisDrawing.PaperSpace
  65.                    If element.EntityType = 7 Then
  66.                        If Err Then GoTo 5
  67.                        If element.HasAttributes = True Then
  68.                            ArrayAttributes = element.GetAttributes
  69.                            For k = LBound(ArrayAttributes) To UBound(ArrayAttributes)
  70.                                If ArrayAttributes(k).TagString = "DATE" Then ArrayAttributes(k).TextString = VBA.UCase(VBA.Format(VBA.Date, "Mmm yyyy"))
  71.                                If ArrayAttributes(k).TagString = "R" Then ArrayAttributes(k).TextString = revtest
  72.                                If ArrayAttributes(k).TagString = "A" Then ArrayAttributes(k).TextString = revtest
  73.                                If ArrayAttributes(k).TagString = "DESCRIPTION" Then ArrayAttributes(k).TextString = "REVISION IN PROGRESS"
  74.                                If ArrayAttributes(k).TagString = "DWG-NO." Then
  75.                                OldDWGNO = ArrayAttributes(k).TextString
  76.                                NewDWGNO = Replace(OldDWGNO, CURREV, NEWREV)
  77.                                ArrayAttributes(k).TextString = NewDWGNO
  78.                                ThisDrawing.ActiveLayout.Name = NewDWGNO
  79.                                End If
  80.                            Next k
  81.                        End If
  82. 5
  83.                    End If
  84.                Next
  85. 10
  86.            Next j
  87.   RenameXrefBlockAttribs
  88.        Next i
  89. End Function
  90. Function RenameXrefBlockAttribs()
  91. Dim AttribValues, XrefOld, XrefNew, XrefPathOld, XrefPathNew, ListXref, TEST As String
  92. Dim CURREV, NEWREV, CURREVPATH, NEWREVPATH As String
  93. Dim element As AcadBlockReference
  94.        CURREV = "_" & UserFormcombined.CurrentStageREV & "_"
  95.        NEWREV = "_" & UserFormcombined.NewStageREV & "_"
  96.        CURREVPATH = "" & UserFormcombined.CurrentStageREV & ""
  97.        NEWREVPATH = "" & UserFormcombined.NewStageREV & ""
  98. On Error Resume Next
  99.        ListXref = "" 'Create a list of xrefs to avoid repeating - for some reason it lists each element more than once
  100.        For Each element In ThisDrawing.ModelSpace
  101.            If element.EntityType = 42 Then 'Test if it is an xref
  102.               ' ListXref = ListXref & ", " & element.Name
  103.               ' GoTo 10
  104.                'If LCase(Left(element.Name, 2)) = "xr" Then
  105. '                    MsgBox element.Name
  106.                    If InStr(0, ListXref, element.Name) > 0 Then
  107.                        If Err = 5 Then Err = 0: GoTo 5
  108.                        GoTo 10 'check if xref in list
  109.                    End If
  110. 5
  111.                    ListXref = ListXref & ", " & element.Name
  112.                    XrefOld = element.Name
  113.                    XrefNew = Replace(XrefOld, CURREV, NEWREV)
  114.                   ''''' XrefNew = InputBox("Rename Xref from " & XrefOld & " to:", "Rename Xref", XrefNew)
  115.                    If XrefNew = "" Then GoTo 10 'cancel pressed
  116.                    XrefPathOld = element.Path
  117.                    XrefPathNew = Replace(XrefPathOld, XrefOld, XrefNew)
  118.                    XrefPathNew = Replace(XrefPathNew, CURREVPATH, NEWREVPATH)
  119.                   ''''' XrefPathNew = InputBox("Rename XrefPath from " & XrefPathOld & " to:", "Rename XrefPath", XrefPathNew)
  120.                    If XrefPathNew = "" Then GoTo 10 'cancel pressed
  121.                    'check if new path file exists and rename if it doesn't - warn if still not present
  122.                    If Dir(XrefPathNew) = "" Then
  123.                        Name Replace(XrefPathNew, XrefNew, XrefOld) As XrefPathNew
  124.                        If Dir(XrefPathNew) = "" Then
  125.                            MsgBox "Could not find file in xref path."
  126.                            GoTo 10
  127.                        End If
  128.                    End If
  129.                    'rename xref
  130.                    ThisDrawing.SendCommand VBA.Chr(27) & VBA.Chr(27) & "-rename" & VBA.vbCr & "b" & VBA.vbCr & XrefOld & VBA.vbCr & XrefNew & VBA.vbCr
  131.                    'check if xref loaded and unload
  132.                    'unload xref
  133.                    ThisDrawing.SendCommand VBA.Chr(27) & VBA.Chr(27) & "-xref" & VBA.vbCr & "u" & VBA.vbCr & XrefNew & VBA.vbCr
  134.                    'repath xref
  135.                    ThisDrawing.SendCommand VBA.Chr(27) & VBA.Chr(27) & "-xref" & VBA.vbCr & "p" & VBA.vbCr & XrefNew & VBA.vbCr & XrefPathNew & VBA.vbCr
  136.                    'if previously loaded then reload xref
  137.                    ThisDrawing.SendCommand VBA.Chr(27) & VBA.Chr(27) & "-xref" & VBA.vbCr & "r" & VBA.vbCr & XrefNew & VBA.vbCr
  138.                End If
  139. 10
  140.            'End If
  141.        Next
  142. End Function
回复

使用道具 举报

发表回复

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

QQ|关于我们|小黑屋|乐筑天下 繁体中文

GMT+8, 2025-3-4 16:19 , Processed in 0.574030 second(s), 54 queries .

© 2020-2025 乐筑天下

联系客服 关注微信 帮助中心 下载APP 返回顶部 返回列表