乐筑天下

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

Acad 2007 文件更新?

[复制链接]

23

主题

68

帖子

12

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
153
发表于 2007-4-2 11:11:07 | 显示全部楼层 |阅读模式
下面的例程查找所有模型视图,去掉它们的名称,并根据属性重命名它们。该例程是在我们使用Acad 2002时创建的,非常有效
  1. ' Author: Wellington Gomes - Darby Anderson
  2. Option Explicit
  3. Sub CreateRunAutoNamedView()
  4.     ThisDrawing.SendCommand ("(defun C:RunAutoNamedView () (setvar ""filedia"" 0) (command ""_VBARUN"" ""CreateNamedViews"") (setvar ""filedia"" 1) )" & vbCr)
  5. End Sub
  6. Sub CreateNamedViews()
  7. Dim mspace As AcadModelSpace
  8. Dim mviews As AcadViews
  9. Dim elem As Variant
  10. Dim elemBl As Variant
  11. Dim Incview As AcadView
  12. Dim iIndex As Integer
  13. Dim sName As String
  14. Const XValue1 = 15.5     ' associated constant to XScale
  15. Const YValue1 = 9.8125   ' associated constant to YScale
  16. Const XValue2 = 11       ' associated constant to XScale
  17. Const YValue2 = 8.5      ' associated constant to YScale
  18. Const XValue3 = 8.5      ' associated constant to XScale
  19. Const YValue3 = 11       ' associated constant to YScale
  20. Dim point1 As Variant
  21. Dim point2(0 To 1) As Double
  22. On Error Resume Next
  23. Set mspace = ThisDrawing.ModelSpace
  24. Set mviews = ThisDrawing.Views
  25.     For Each elem In mviews
  26.         elem.Delete
  27.     Next
  28.     iIndex = 0
  29.    
  30.     For Each elemBl In mspace
  31.         If elemBl.EntityName = "AcDbBlockReference" Then
  32. '''''''''''''
  33.             If (elemBl.Name = "DWGATTRIBUTES" Or elemBl.Name = "dwgattributes" Or elemBl.Name = "DWGATTRIBUTES2") Then
  34.    
  35.                 point1 = elemBl.InsertionPoint
  36.                 point2(0) = elemBl.XScaleFactor * XValue1 + point1(0)
  37.                 point2(1) = elemBl.YScaleFactor * YValue1 + point1(1)
  38.                 iIndex = nGetAttributes(elemBl) 'Get attribute TagString = PG
  39.                 If Err.Number  0 Then
  40.                     MsgBox "Error - Block without PG: " & elemBl.Name
  41.                     Exit Sub
  42.                 End If
  43.                
  44.                 If iIndex = 0 Then
  45.                     MsgBox "Error - Block without PG: " & elemBl.Name
  46.                     Exit Sub
  47.                 End If
  48.    
  49.                 Set Incview = ThisDrawing.Views.Add(iIndex)
  50.                 If Err.Number  0 Then
  51.                     MsgBox "Error - Block already exists: " & iIndex
  52.                     Exit For
  53.                 End If
  54.                 Incview.Width = elemBl.XScaleFactor * XValue1
  55.                 Incview.Height = elemBl.YScaleFactor * YValue1
  56.                 point2(0) = Incview.Width / 2 + point1(0)
  57.                 point2(1) = Incview.Height / 2 + point1(1)
  58.                 Incview.Center = point2
  59. '    Incview.Update
  60.             End If
  61. '''''''''''''''''''''''
  62.             If (elemBl.Name = "IITITLEHA") Then
  63.    
  64.                 point1 = elemBl.InsertionPoint
  65.                 point2(0) = elemBl.XScaleFactor * XValue2 + point1(0)
  66.                 point2(1) = elemBl.YScaleFactor * YValue2 + point1(1)
  67.                 iIndex = nGetAttributes(elemBl) 'Get attribute TagString = PG
  68.                 If Err.Number  0 Then
  69.                     MsgBox "Error - Block without PG: " & elemBl.Name
  70.                     Exit Sub
  71.                 End If
  72.                
  73.                 If iIndex = 0 Then
  74.                     MsgBox "Error - Block without PG: " & elemBl.Name
  75.                     Exit Sub
  76.                 End If
  77.    
  78.                 Set Incview = ThisDrawing.Views.Add(iIndex)
  79.                 If Err.Number  0 Then
  80.                     MsgBox "Error - Block already exists: " & iIndex
  81.                     Exit For
  82.                 End If
  83.                 Incview.Width = elemBl.XScaleFactor * XValue2
  84.                 Incview.Height = elemBl.YScaleFactor * YValue2
  85.                 point2(0) = Incview.Width / 2 + point1(0)
  86.                 point2(1) = Incview.Height / 2 + point1(1)
  87.                 Incview.Center = point2
  88. '    Incview.Update
  89.             End If
  90. '''''''''''''''''''''''
  91.             If (elemBl.Name = "IITITLEVA") Then
  92.    
  93.                 point1 = elemBl.InsertionPoint
  94.                 point2(0) = elemBl.XScaleFactor * XValue3 + point1(0)
  95.                 point2(1) = elemBl.YScaleFactor * YValue3 + point1(1)
  96.                 iIndex = nGetAttributes(elemBl) 'Get attribute TagString = PG
  97.                 If Err.Number  0 Then
  98.                     MsgBox "Error - Block without PG: " & elemBl.Name
  99.                     Exit Sub
  100.                 End If
  101.                
  102.                 If iIndex = 0 Then
  103.                     MsgBox "Error - Block without PG: " & elemBl.Name
  104.                     Exit Sub
  105.                 End If
  106.    
  107.                 Set Incview = ThisDrawing.Views.Add(iIndex)
  108.                 If Err.Number  0 Then
  109.                     MsgBox "Error - Block already exists: " & iIndex
  110.                     Exit For
  111.                 End If
  112.                 Incview.Width = elemBl.XScaleFactor * XValue3
  113.                 Incview.Height = elemBl.YScaleFactor * YValue3
  114.                 point2(0) = Incview.Width / 2 + point1(0)
  115.                 point2(1) = Incview.Height / 2 + point1(1)
  116.                 Incview.Center = point2

现在我们有了Acad2007,它在分配“视图1”后爆炸,并留下此错误消息
  1. Error-Block without PG: DWGATTRIBUTES

使用ACAD2007,我在ACAD2002中使用的图纸上测试了这一点。问题在于我们更新到2007年。
有人能确定我们需要做什么来纠正这一点吗?我被难住了 0 Then
            MsgBox "Error - Block without PG: " & elemBl.Name
            Exit Sub
        End If
        
        If iIndex = 0 Then
            MsgBox "Error - Block without PG: " & elemBl.Name
            Exit Sub
        End If
        Set Incview = ThisDrawing.Views.Add(iIndex)
        If Err.Number  0 Then
            MsgBox "Error - Block already exists: " & iIndex
            Exit For
        End If
        Incview.Width = elemBl.XScaleFactor * X
        Incview.Height = elemBl.YScaleFactor * Y
        point2(0) = Incview.Width / 2 + point1(0)
        point2(1) = Incview.Height / 2 + point1(1)
        Incview.Center = point2
Skip:
    Next elemBl
End Sub[/code]
回复

使用道具 举报

170

主题

1424

帖子

8

银币

顶梁支柱

Rank: 50Rank: 50

铜币
2119
发表于 2007-4-2 23:21:15 | 显示全部楼层
谢谢布莱科 0 Then
            MsgBox "Error - Block without PG: " & elemBl.Name
            Exit Sub
        End If
        
        If iIndex = 0 Then
            MsgBox "Error - Block without PG: " & elemBl.Name
            Exit Sub
        End If
        Set Incview = ThisDrawing.Views.Add(iIndex)
        If Err.Number  0 Then
            MsgBox "Error - Block already exists: " & iIndex
            Exit For
        End If
        Incview.Width = elemBl.XScaleFactor * X
        Incview.Height = elemBl.YScaleFactor * Y
        point2(0) = Incview.Width / 2 + point1(0)
        point2(1) = Incview.Height / 2 + point1(1)
        Incview.Center = point2
Skip:
    Next elemBl
End Sub
Function nGetAttributes(element) As Integer
    Dim ArrayAttributes As Variant
    Dim I As Integer, Num
   
    ArrayAttributes = element.GetAttributes
    For I = LBound(ArrayAttributes) To UBound(ArrayAttributes)
        Select Case ArrayAttributes(I).TagString
            Case "PG", "PG1", "2", "PAGE_NO."
                Num = ArrayAttributes(I).TextString
                If IsNumeric(Num) Then
                    nGetAttributes = Int(Num)
                End If
                Exit Function
       End Select
   
    Next
End Function
[/code]
回复

使用道具 举报

23

主题

68

帖子

12

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
153
发表于 2007-4-5 14:24:17 | 显示全部楼层
2006 年和 2008 年,lisp 除了代码运行良好之外什么都不做。
摆脱lisp或告诉我哪里出了问题。
  1. Sub CreateNamedViews()
  2. Dim mspace As AcadModelSpace
  3. Dim mviews As AcadViews
  4. Dim elem As Variant
  5. Dim elemBl As Variant
  6. Dim Incview As AcadView
  7. Dim iIndex As Integer
  8. Dim sName As String
  9. Const XValue1 = 15.5     ' associated constant to XScale
  10. Const YValue1 = 9.8125   ' associated constant to YScale
  11. Const XValue2 = 11       ' associated constant to XScale
  12. Const YValue2 = 8.5      ' associated constant to YScale
  13. Const XValue3 = 8.5      ' associated constant to XScale
  14. Const YValue3 = 11       ' associated constant to YScale
  15. Dim X As Double, Y As Double
  16. Dim point1 As Variant
  17. Dim point2(0 To 1) As Double
  18. 'On Error Resume Next
  19. Set mspace = ThisDrawing.ModelSpace
  20. Set mviews = ThisDrawing.Views
  21.     For Each elem In mviews
  22.         elem.Delete
  23.     Next
  24.     iIndex = 0
  25.    
  26.     For Each elemBl In mspace
  27.         If Not elemBl.EntityName = "AcDbBlockReference" Then GoTo Skip
  28.         Select Case elemBl.Name
  29.             Case "DWGATTRIBUTES", "dwgattributes", "DWGATTRIBUTES2"
  30.                 X = XValue1: Y = YValue1
  31.             Case "IITITLEHA"
  32.                 X = XValue2: Y = YValue2
  33.             Case "IITITLEVA"
  34.                 X = XValue3: Y = YValue3
  35.             Case Else
  36.                 GoTo Skip
  37.         End Select
  38.             
  39.         point1 = elemBl.InsertionPoint
  40.         point2(0) = elemBl.XScaleFactor * X + point1(0)
  41.         point2(1) = elemBl.YScaleFactor * Y + point1(1)
  42.         iIndex = nGetAttributes(elemBl)  'Get attribute TagString = PG
  43.         If Err.Number  0 Then
  44.             MsgBox "Error - Block without PG: " & elemBl.Name
  45.             Exit Sub
  46.         End If
  47.         
  48.         If iIndex = 0 Then
  49.             MsgBox "Error - Block without PG: " & elemBl.Name
  50.             Exit Sub
  51.         End If
  52.         Set Incview = ThisDrawing.Views.Add(iIndex)
  53.         If Err.Number  0 Then
  54.             MsgBox "Error - Block already exists: " & iIndex
  55.             Exit For
  56.         End If
  57.         Incview.Width = elemBl.XScaleFactor * X
  58.         Incview.Height = elemBl.YScaleFactor * Y
  59.         point2(0) = Incview.Width / 2 + point1(0)
  60.         point2(1) = Incview.Height / 2 + point1(1)
  61.         Incview.Center = point2
  62. Skip:
  63.     Next elemBl
  64. End Sub

回复

使用道具 举报

170

主题

1424

帖子

8

银币

顶梁支柱

Rank: 50Rank: 50

铜币
2119
发表于 2007-4-5 16:05:47 | 显示全部楼层
还行,离得很近!
如果没有现有的视图,例程将很好地工作。
如果图形中存在除最后一个视图之外的所有视图都被删除,则例程将爆炸。
必须在代码的这一部分中:
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

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

GMT+8, 2025-7-7 14:15 , Processed in 0.906138 second(s), 61 queries .

© 2020-2025 乐筑天下

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