明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 2857|回复: 3

等不及金斑竹了,我先发个简单的例子

[复制链接]
发表于 2004-6-28 13:40:00 | 显示全部楼层 |阅读模式
本帖最后由 作者 于 2004-6-28 15:26:10 编辑

Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.Interop
Imports Autodesk.AutoCAD.Geometry
Imports AutoCadTM = Autodesk.AutoCAD.DatabaseServices.TransactionManager
Module Module1
End Module Public Class TlsTemp <CommandMethod("test")> Public Shared Sub MytestCmd() Dim pUtility As AcadUtility = Application.DocumentManager.MdiActiveDocument.AcadDocument.Utility
Dim pT As New TlsDatabase
Dim p1, p2 As Object
'在屏幕上选取两个点生成一条直线
p1 = pUtility.GetPoint()
p2 = pUtility.GetPoint(p1)
Dim pLine As New Line(New Point3d(p1(0), p1(1), p1(2)), New Point3d(p2(0), p2(1), p2(2)))
pT.AppendEntity(pLine) '生成一条直线,并加入到无名块,插入
Dim p As Object = pUtility.GetPoint()
Dim pEs(0) As DBObject
'pEs(0) = New Line(New Point3d(p1(0), p1(1), p1(2)), New Point3d(p2(0), p2(1), p2(2)))
pEs(0) = pLine.Clone
Dim pBlock As ObjectId = pT.AppendBlock("*U", pEs)
Dim pObj As New BlockReference(New Point3d(p(0), p(1), p(2)), pBlock)
pT.AppendEntity(pObj) End Sub
End Class
Public Class TlsDatabase '程序功能:向当前模型空间加入实体
Public Function AppendEntity(ByVal TlsEntity As DBObject) Dim pDatabase As Database = Application.DocumentManager.MdiActiveDocument.Database
Dim pTransactionManager As AutoCadTM = pDatabase.TransactionManager
Dim pStartTransaction As Transaction = pTransactionManager.StartTransaction() Try Dim pBlockTable As BlockTable = CType(pTransactionManager.GetObject(pDatabase.BlockTableId, OpenMode.ForRead, False), BlockTable)
Dim pBlockTableRecord As BlockTableRecord = CType(pTransactionManager.GetObject(pBlockTable(BlockTableRecord.ModelSpace), OpenMode.ForWrite, False), BlockTableRecord) pBlockTableRecord.AppendEntity(TlsEntity)
pTransactionManager.AddNewlyCreatedDBObject(TlsEntity, True) pStartTransaction.Commit() Finally pStartTransaction.Dispose() End Try End Function '程序功能:生成一个新块,并加入实体
Public Function AppendBlock(ByVal Name As String, ByVal Entitys As DBObject()) As ObjectId
Dim i As DBObject
Dim pDatabase As Database = Application.DocumentManager.MdiActiveDocument.Database
Dim pTransactionManager As AutoCadTM = pDatabase.TransactionManager
Dim pStartTransaction As Transaction = pTransactionManager.StartTransaction()
Try Dim pBlockTable As BlockTable = CType(pTransactionManager.GetObject(pDatabase.BlockTableId, OpenMode.ForWrite, False), BlockTable)
Dim pBlockTableRecord As New BlockTableRecord
pBlockTableRecord.Name = Name
pBlockTable.Add(pBlockTableRecord)
Dim pId As ObjectId = pBlockTableRecord.Id
For Each i In Entitys
pBlockTableRecord.AppendEntity(i)
pTransactionManager.AddNewlyCreatedDBObject(i, True)
Next i
pBlockTableRecord.Close()
pStartTransaction.Commit() Return pId Finally pStartTransaction.Dispose() End Try End Function End Class
发表于 2004-6-29 22:08:00 | 显示全部楼层
金版主用的夹叙夹议之春秋笔法,有滋有味。你来个只练不讲,责把开头的一堆“Imports”解释清楚。:)
 楼主| 发表于 2004-6-30 08:00:00 | 显示全部楼层
河伯老兄,偶还等着金版主的文章呢,就靠偶的三脚猫可不行,:)
发表于 2004-7-10 18:28:00 | 显示全部楼层
这是用VB.net做的吗?怎么这么像ARX啊。。。


好像挺烦的,不如VBA来得简单啊,不知有什么优点???
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-11-28 23:49 , Processed in 0.170730 second(s), 24 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表