乐筑天下

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

求助,无名块插入的程序,错在哪?

[复制链接]

4

主题

10

帖子

3

银币

初来乍到

Rank: 1

铜币
26
发表于 2006-3-22 22:25:00 | 显示全部楼层 |阅读模式
无名块插入的程序,错在哪?
  1. Sub Example_InsertBlock()
  2.     ' This example creates a block containing a circle.
  3.     ' It then inserts the block
  4.     ' Create the block
  5.     Dim blockObj As AcadBlock
  6.     Dim insertionPnt(0 To 2) As Double
  7.     insertionPnt(0) = 0#: insertionPnt(1) = 0#: insertionPnt(2) = 0#
  8.     Set blockObj = ThisDrawing.Blocks.Add(insertionPnt, "*u")
  9.     ' Add a circle to the block
  10.     Dim circleObj As AcadCircle
  11.     Dim center(0 To 2) As Double
  12.     Dim radius As Double
  13.     center(0) = 0: center(1) = 0: center(2) = 0
  14.     radius = 1
  15.     Set circleObj = blockObj.AddCircle(center, radius)
  16.     ' This example creates an attribute definition in model space.
  17.     Dim attributeObj As AcadAttribute
  18.     Dim height As Double
  19.     Dim mode As Long
  20.     Dim prompt As String
  21.     Dim insertionPoint(0 To 2) As Double
  22.     Dim tag As String
  23.     Dim value As String
  24.     ' Define the attribute definition
  25.     height = 1#
  26.     mode = acAttributeModeVerify
  27.     prompt = "New Prompt"
  28.     insertionPoint(0) = 5#: insertionPoint(1) = 5#: insertionPoint(2) = 0
  29.     tag = "New Tag"
  30.     value = "New Value"
  31.     ' Create the attribute definition object in model space
  32.     Set attributeObj = blockObj.AddAttribute(height, mode, prompt, insertionPoint, tag, value)
  33.     ' Insert the block
  34.     Dim i As Long
  35.     i = 0&
  36.     Dim scaX As Double
  37.     Dim scaY As Double
  38.     Dim scaZ As Double
  39.     scaX = 1#
  40.     scaY = 1#
  41.     scaZ = 1#
  42.     Dim strname As String
  43.     Dim strname1 As String
  44.     Dim blockRefObj As AcadBlockReference
  45.     For i = 1& To 10&
  46.     scaX = scaX + i
  47.     scaY = scaY + i
  48.     scaZ = scaZ + i
  49.     strname1 = Format(i, "")
  50.     strname = "*u"
  51.     MsgBox strname1
  52.     strname = strname + strname1
  53.     MsgBox strname
  54.     insertionPnt(0) = 2# + i
  55.     insertionPnt(1) = 2# + i
  56.     insertionPnt(2) = 0#
  57.     Set blockRefObj = ThisDrawing.ModelSpace.InsertBlock(insertionPnt, strname, scaX, scaY, scaZ, 0)
  58.     Next i
  59.     ZoomAll
  60. End Sub

回复

使用道具 举报

72

主题

2726

帖子

9

银币

社区元老

Rank: 75Rank: 75Rank: 75

铜币
3014
发表于 2006-3-23 13:39:00 | 显示全部楼层
strname = "*u"
改为
strname = blockObj.name
回复

使用道具 举报

4

主题

10

帖子

3

银币

初来乍到

Rank: 1

铜币
26
发表于 2006-3-23 22:04:00 | 显示全部楼层
版主你好,我的本意是要创建从*U1至*U10的不同的无名块,像INTECAD中的材料明细表一样的。而本程序运行时每次只能(依次)创建一个无名块,然后出现“运行时错误‘2147418113(8000FFFF)’;方法‘Insertblock’作用于‘IAcadmodelspace’时失败”后退出。就是第一次运行时创建*U1后出错退出,第二次运行时创建*U1,*U2后退出,第三次创建*U1,*U2,*U3.....
回复

使用道具 举报

72

主题

2726

帖子

9

银币

社区元老

Rank: 75Rank: 75Rank: 75

铜币
3014
发表于 2006-3-23 22:42:00 | 显示全部楼层
无名块要创建一次,插入一次
如果要创建从*U1至*U10的不同的无名块,就要创建10个块定义,*U后面的数字也不会由你来控制,要获取无名块的名字,只能用strname = blockObj.name 的形式调用
回复

使用道具 举报

4

主题

10

帖子

3

银币

初来乍到

Rank: 1

铜币
26
发表于 2006-3-24 21:53:00 | 显示全部楼层
谢谢版主,这下明白了.
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

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

GMT+8, 2025-7-6 05:55 , Processed in 1.276978 second(s), 62 queries .

© 2020-2025 乐筑天下

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