乐筑天下

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

[编程交流] Modify Block Attributes; VB.NE

[复制链接]

1

主题

2

帖子

1

银币

初来乍到

Rank: 1

铜币
5
发表于 2022-7-6 22:04:59 | 显示全部楼层 |阅读模式
I need to change the attribute of "tag" = "PRO" in all blocks of the model space of the active document in autocad. The text you need to add is "my project".
 
I searched for information about walking blocks and change the attributes but I get nothing. Can anyone help me please?
回复

使用道具 举报

44

主题

3166

帖子

2803

银币

中流砥柱

Rank: 25

铜币
557
发表于 2022-7-6 22:34:17 | 显示全部楼层
Welcome to CADTutor!
 
Once you've obtained the desired BlockTableRecord, simply iterate GetBlockReferenceIds(), opening each BlockReference and edit the Attribute as needed... Here are some articles that may help:
 
Identify the number of reference to a block
 
Updating a specific attribute inside an AutoCAD drawing using .NET
 
Edit Attribute Definitions
 
 
Cheers
回复

使用道具 举报

1

主题

2

帖子

1

银币

初来乍到

Rank: 1

铜币
5
发表于 2022-7-6 23:00:07 | 显示全部楼层
thank you very much. I am going to read them.
回复

使用道具 举报

106

主题

1万

帖子

101

银币

顶梁支柱

Rank: 50Rank: 50

铜币
1299
发表于 2022-7-6 23:08:08 | 显示全部楼层
Here is some examples to get you started
 
  1. Public Sub ModifyPitSchedule1()' adds single ptDim SS As AcadSelectionSetDim objENT As AcadEntityDim Count, Cntr As IntegerDim Newpitname As StringDim pitname As StringDim FilterDXFCode(0) As IntegerDim FilterDXFVal(0) As VariantDim PitNameSelect As AcadObjectDim basepnt, pt1, pt2, pt3 As VariantDim attribs As Variant'On Error Resume NextNewpitname = "1"   'dummy to pass then return changedBLOCK_NAME = "SCHEDTEXT"pitname = Getpitname(Newpitname)MsgBox "pitname selected is " & pitnameFilterDXFCode(0) = 0FilterDXFVal(0) = "INSERT"'FilterDXFCode(1) = 2'FilterDXFVal(1) = "SCHEDTEXT"Set SS = ThisDrawing.SelectionSets.Add("pit1sel")SS.Select acSelectionSetAll, , , FilterDXFCode, FilterDXFValFor Cntr = 0 To SS.Count - 1If SS.Item(Cntr).Name = BLOCK_NAME Then   attribs = SS.Item(Cntr).GetAttributes           If attribs(0).TextString = pitname Then      pt1 = ThisDrawing.Utility.GetPoint(, " pick first point")      txtx1 = CStr(FormatNumber(pt1(0), 3))      TXTY1 = CStr(FormatNumber(pt1(1), 3))              attribs(1).TextString = txtx1       attribs(2).TextString = TXTY1              attribs(1).Update       attribs(2).Update'        ThisDrawing.Application.Update' try this       Cntr = SS.Count        Else: End If     Else: End IfNext CntrThisDrawing.SelectionSets.Item("pit1sel").DeleteEnd Sub
 
This one allows either a text as the name of the attribute or pick a block
 
  1. Function Getpitname(Newpitname As String) As StringDim PitNameSelect As AcadObjectDim pitattribs As VariantThisDrawing.Utility.GetEntity PitNameSelect, basepnt, "pick pit name : "If PitNameSelect.ObjectName = "AcDbText" Then Getpitname = PitNameSelect.TextStringEnd IfIf PitNameSelect.ObjectName = "AcDbBlockReference" Then pitblname = PitNameSelect.Name   ' RETURNS BLOCK NAME pitattribs = PitNameSelect.GetAttributes Getpitname = pitattribs(0).TextStringEnd IfEnd Function
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

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

GMT+8, 2025-3-4 08:52 , Processed in 1.254836 second(s), 71 queries .

© 2020-2025 乐筑天下

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