乐筑天下

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

更新侧数据库中的属性(AutoCAD 2019)

[复制链接]

15

主题

44

帖子

1

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
104
发表于 2019-1-21 09:57:47 | 显示全部楼层 |阅读模式
此代码不再适用于AutoCAD 2019。我的目标是框架4.7。托管.NET参考指南指定函数<pre>
  1. Database.ReadDwgFile(string, FileShare, [MarshalAs(UnmanagedType.U1)] bool, string) Method

已过时,将在未来版本中删除。调试时,它不会遍历BlockTableRecord中的对象ID?功能是否已被替换?我正在研究图形系统的变化…但任何输入都很好…
谢谢。
  1. Public Shared Sub UpdateAttributesInSideDatabase(ByVal FilePath As String, blockName As String, attbName As String, attbValue As String)
  2.         Dim doc As Document = Application.DocumentManager.MdiActiveDocument
  3.         Dim currentDb As Database = doc.Database
  4.         Dim ed As Editor = doc.Editor
  5.         Using targetDb As New Database(False, True)
  6.             Try
  7.                 targetDb.ReadDwgFile(FilePath, System.IO.FileShare.ReadWrite, True, "")
  8.                 Using tr As Transaction = targetDb.TransactionManager.StartTransaction()
  9.                     Dim layoutDict As DBDictionary = tr.GetObject(targetDb.LayoutDictionaryId, OpenMode.ForRead)
  10.                     For Each dicEnt As DBDictionaryEntry In layoutDict
  11.                         Dim lay As Layout = DirectCast(dicEnt.Value.GetObject(OpenMode.ForRead), Layout)
  12.                         ''do your stuffs in every layout
  13.                         If lay.LayoutName  "Model" Then
  14.                             Dim btr As BlockTableRecord = tr.GetObject(lay.BlockTableRecordId, OpenMode.ForRead)
  15.                             For Each id As ObjectId In btr
  16.                                 If id.ObjectClass.DxfName = "INSERT" Then
  17.                                     Dim br As BlockReference = DirectCast(tr.GetObject(id, OpenMode.ForRead), BlockReference)
  18.                                     ' ... to see whether it's a block with
  19.                                     ' the name we're after
  20.                                     If br.Name.ToUpper() = blockName.ToUpper() Then
  21.                                         For Each arId As ObjectId In br.AttributeCollection
  22.                                             Dim ar As AttributeReference = DirectCast(tr.GetObject(arId, OpenMode.ForRead), AttributeReference)
  23.                                             ' ... to see whether it has
  24.                                             ' the tag we're after
  25.                                             If ar.Tag.ToUpper() = attbName.ToUpper() Then
  26.                                                 ' If so, update the value
  27.                                                 ' and increment the counter
  28.                                                 ar.UpgradeOpen()
  29.                                                 ar.TextString = attbValue
  30.                                                 'realign attributes after editing their values
  31.                                                 'ar.AdjustAlignment(targetDb)
  32.                                                 'ar.DowngradeOpen()
  33.                                             End If
  34.                                         Next
  35.                                     End If
  36.                                 End If
  37.                             Next
  38.                         End If
  39.                     Next
  40.                     'end of code from template insert
  41.                     tr.Commit()
  42.                 End Using
  43.                 targetDb.SaveAs(FilePath, DwgVersion.Current)
  44.             Catch ex As Autodesk.AutoCAD.Runtime.Exception
  45.                 ed.WriteMessage(vbLf & "Error while running > " + ex.Message)
  46.             End Try
  47.         End Using
  48.     End Sub

本帖以下内容被隐藏保护;需要你回复后,才能看到!

游客,如果您要查看本帖隐藏内容请回复
回复

使用道具 举报

71

主题

928

帖子

8

银币

顶梁支柱

Rank: 50Rank: 50

铜币
1230
发表于 2019-1-21 10:25:10 | 显示全部楼层
更改此选项:
目标数据库。ReadDwgFile(文件路径,System.IO.FileShare.ReadWrite,True,“”
指向以下对象:
targetDb。ReadDwgFile(文件路径,FileOpenMode.OpenForReadAndWriteNoShare,True,“”)
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

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

GMT+8, 2025-2-4 08:52 , Processed in 0.202959 second(s), 56 queries .

© 2020-2025 乐筑天下

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