乐筑天下

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

[编程交流] 在VB中插入块。净额

[复制链接]

16

主题

35

帖子

30

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
91
发表于 2022-7-6 19:12:22 | 显示全部楼层 |阅读模式
团队
 
有没有人有任何样本代码,我可以使用vb插入一个块。网帮助文档基于vb。
回复

使用道具 举报

44

主题

3166

帖子

2803

银币

中流砥柱

Rank: 25

铜币
557
发表于 2022-7-6 19:43:40 | 显示全部楼层
也许是这样?
 
伪代码:
  1. [color=black]     <CommandMethod("InsertBlock")> _
  2.    Public Sub InsertBlock()
  3.        Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument
  4.        acDoc.SendStringToExecute("._-insert [color=red]<YouFillInTheRest>[/color]", False, False, False)
  5.    End Sub[/color]
  6.    
回复

使用道具 举报

10

主题

973

帖子

909

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
118
发表于 2022-7-6 19:59:33 | 显示全部楼层
以下是通过首先使用对话框选择文件来插入块参照的示例。
 
它是适度基本的;例如,可以通过“跳汰”进一步扩展,以允许在插入过程中进行视觉反馈。这将增加相当多的复杂性。
 
 
观看文字换行!
 
  1.         Public Sub InsertFromFileCommand()
  2.            Dim ofd As OpenFileDialog = New OpenFileDialog()
  3.            ofd.DefaultExt = ".dwg"
  4.            ofd.Filter = "Drawing Files (*.dwg)|*.dwg"
  5.            If ofd.ShowDialog() <> DialogResult.OK Then
  6.                Return
  7.            End If
  8.            Dim doc As Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument
  9.            Dim db As Database = doc.Database
  10.            Dim ed As Editor = doc.Editor
  11.            Dim ppo As New PromptPointOptions(vbLf & "Insertion point: ")
  12.            Dim ppr As PromptPointResult = ed.GetPoint(ppo)
  13.            If ppr.Status <> PromptStatus.OK Then
  14.                Return
  15.            End If
  16.            Using xDb As New Database(False, True)
  17.                xDb.ReadDwgFile(ofd.FileName, FileShare.Read, True, Nothing)
  18.                Using tr As Transaction = doc.TransactionManager.StartTransaction()
  19.                    Dim name As String = SymbolUtilityServices.GetBlockNameFromInsertPathName(ofd.FileName)
  20.                    Dim id As ObjectId = db.Insert(name, xDb, True)
  21.                    If id.IsNull Then
  22.                        ed.WriteMessage(vbLf & "Failed to insert block")
  23.                        Return
  24.                    End If
  25.                    Dim currSpace As BlockTableRecord = CType(tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite), BlockTableRecord)
  26.                    Dim p3d As Point3d = ppr.Value
  27.                    Dim coordS As CoordinateSystem3d = New CoordinateSystem3d(p3d, db.Ucsxdir, db.Ucsydir) 'Determine UCS
  28.                    Dim insert As New BlockReference(p3d, id)
  29.                    insert.Normal = coordS.Zaxis 'Align to UCS
  30.                    currSpace.AppendEntity(insert)
  31.                    insert.SetDatabaseDefaults()
  32.                    tr.AddNewlyCreatedDBObject(insert, True)
  33.                    tr.Commit()
  34.                End Using
  35.            End Using
  36.        End Sub
回复

使用道具 举报

0

主题

1

帖子

1

银币

初来乍到

Rank: 1

铜币
0
发表于 2022-7-6 20:21:50 | 显示全部楼层
嗨,肖特,
我为我自己的程序得到了你的部分代码,它按预期工作。代码非常有用,是将来改进代码的最佳示例。
非常感谢。
 
科拉诺
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

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

GMT+8, 2025-3-4 14:53 , Processed in 0.548044 second(s), 71 queries .

© 2020-2025 乐筑天下

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