乐筑天下

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

[编程交流] 块属性到文本错误

[复制链接]

8

主题

21

帖子

13

银币

初来乍到

Rank: 1

铜币
40
发表于 2022-7-6 21:56:49 | 显示全部楼层 |阅读模式
我尝试在块对象的同一点添加文本对象。
但它在下面的红线处给出了一个错误。
 
错误代码为;
运行时错误“5”:
过程调用或参数无效
 
  1. Sub Block_Attributes_to_Text()
  2. Dim obj As AcadBlockReference
  3. Dim oText As AcadText
  4. Dim inspt As Variant
  5. Dim AttList As Variant
  6. Dim metin As String
  7. Dim poz As String
  8. Dim adet As String
  9. Dim cap As String
  10. Dim ara As String
  11. Dim boy As String
  12. Dim MidPoint(0 To 2)
  13. Dim NewColorObject As AcadAcCmColor
  14. Dim acı As Double
  15. ThisDrawing.Utility.GetEntity obj, inspt, "Select Block:"
  16. If obj.ObjectName = "AcDbBlockReference" Then
  17.    If obj.HasAttributes Then
  18.        AttList = obj.GetAttributes
  19.        For i = LBound(AttList) To UBound(AttList)
  20.            Select Case AttList(i).TagString
  21.    
  22.            Case Is = "POZ1"
  23.                poz = AttList(i).TextString
  24.            Case Is = "DAD"
  25.                adet = AttList(i).TextString
  26.            Case Is = "CAP"
  27.                cap = AttList(i).TextString
  28.            Case Is = "ARA"
  29.                ara = AttList(i).TextString
  30.            Case Is = "BOY1"
  31.                boy = AttList(i).TextString
  32.            End Select
  33.        Next i
  34.    End If
  35. Else
  36.    MsgBox "You did not select a block."
  37. End If
  38.       
  39.    
  40.        metin = poz & "+" & adet & "»" & cap & "/" & ara & " L=" & boy
  41.        MidPoint(0) = obj.InsertionPoint(0)
  42.        MidPoint(1) = obj.InsertionPoint(1)
  43.        MidPoint(2) = 0
  44.        [b][color=red]Set oText = ThisDrawing.ModelSpace.AddText(metin, MidPoint, 5)[/color][/b]
  45.        Set NewColorObject = obj.TrueColor
  46.        NewColorObject.ColorMethod = acColorMethodByACI
  47.        NewColorObject.ColorIndex = 2
  48.        oText.TrueColor = NewColorObject
  49.            
  50.        acı = obj.Rotation
  51.        oText.Rotate MidPoint, acı
  52.        oText.Update
  53. acı = Empty
  54. Set NewColorObject = Nothing
  55. Erase MidPoint
  56. boy = vbNullString
  57. ara = vbNullString
  58. cap = vbNullString
  59. adet = vbNullString
  60. poz = vbNullString
  61. metin = vbNullString
  62. AttList = Empty
  63. inspt = Empty
  64. oText = Nothing
  65. obj = Nothing
  66. End Sub
回复

使用道具 举报

12

主题

175

帖子

77

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
149
发表于 2022-7-6 23:18:17 | 显示全部楼层
只需将中点声明为双精度
  1. Dim MidPoint(0 To 2) As Double

 
此外,虽然与您遇到的问题无关,但您还必须更改底部的最后两行,在开头添加“set”关键字
  1. Set oText = Nothing
  2. Set obj = Nothing
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

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

GMT+8, 2025-3-4 14:04 , Processed in 0.417080 second(s), 56 queries .

© 2020-2025 乐筑天下

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