发布一个ObjectARX .NET AutoCAD 二次开发 添加各种实体的类

本文详细介绍使用Visual Basic .NET在AutoCAD中创建各种实体的方法,包括直线、圆、弧、椭圆、多段线、文字、表格、填充等,并提供了创建组、添加UCS、视口和视图的功能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 

ContractedBlock.gifExpandedBlockStart.gif
None.gifImports Autodesk.AutoCAD.ApplicationServices
None.gif
Imports Autodesk.AutoCAD.DatabaseServices
None.gif
Imports Autodesk.AutoCAD.Runtime
None.gif
Imports Autodesk.AutoCAD.Geometry
None.gif
Imports Autodesk.AutoCAD.EditorInput
None.gif
Imports Autodesk.AutoCAD.Colors
None.gif
Imports DBTransMan = Autodesk.AutoCAD.DatabaseServices.TransactionManager
None.gif
REM Line, Circle, Arc, Ellipse, Polyline, DBText, MText, Table, Hatch and the Dimensions
ExpandedBlockStart.gifContractedBlock.gif
Public Class PublicClassClass PublicClass
ExpandedSubBlockStart.gifContractedSubBlock.gif    
Enum PPColorEnum PPColor
InBlock.gif        Red 
= 1
InBlock.gif        Yellow 
= 2
InBlock.gif        Green 
= 3
InBlock.gif        cyan 
= 4 '青色
InBlock.gif
        Blue = 5
InBlock.gif        Fuchsin 
= 6 '品红
InBlock.gif
        White = 7
ExpandedSubBlockEnd.gif    
End Enum

InBlock.gif    
REM <summary>
InBlock.gif
    '''函数注释
InBlock.gif
    '''</summary>  
InBlock.gif
    '''<typeparam name="msg">变量参数的注释说明</typeparam>
InBlock.gif
    '''<remarks>
InBlock.gif
    '''自己的注释说明
InBlock.gif

InBlock.gif    
'''</remarks>
ExpandedSubBlockStart.gifContractedSubBlock.gif
    Public Sub ShowMessage()Sub ShowMessage(ByVal msg As String)
InBlock.gif        Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage(
Chr(10+ msg)
ExpandedSubBlockEnd.gif    
End Sub

ExpandedSubBlockStart.gifContractedSubBlock.gif    
Public Sub SendCommand()Sub SendCommand(ByVal cmd As String)
InBlock.gif        
Dim dotnetDoc As Document = Application.DocumentManager.MdiActiveDocument
InBlock.gif        dotnetDoc.SendStringToExecute(cmd 
+ Chr(13), TrueFalseFalse)
ExpandedSubBlockEnd.gif    
End Sub

InBlock.gif
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif    
Public Function GetPointAR()Function GetPointAR(ByVal pt1 As Point3d, ByVal angle As DoubleByVal length As DoubleAs Point3d
InBlock.gif        
REM angle(计算sin cos 时 是以弧度计量的角度)
InBlock.gif
        angle = angle * Math.PI / 180
InBlock.gif        
Dim pt2 As New Point3d(pt1.X + length * Math.Cos(angle), pt1.Y + length * Math.Sin(angle), pt1.Z)
InBlock.gif        
Return pt2
ExpandedSubBlockEnd.gif    
End Function

InBlock.gif    
'  Public Sub ShowMessage(ByVal msg As String, ByVal ex As Autodesk.AutoCAD.Runtime.Exception)
InBlock.gif
    '      ShowMessage(Chr(10) + msg + "错误信息如下:" + Chr(10) + ex.Message)
InBlock.gif
    '  End Sub
ExpandedSubBlockStart.gifContractedSubBlock.gif
    Public Function AddEntity()Function AddEntity(ByVal ent As Entity) As ObjectId
InBlock.gif        
Dim db As Database = Application.DocumentManager.MdiActiveDocument.Database
InBlock.gif        
Dim tm As DBTransMan = db.TransactionManager
InBlock.gif        
Dim ta As Transaction = tm.StartTransaction
InBlock.gif        
Try
InBlock.gif            
Dim bt As BlockTable = ta.GetObject(db.BlockTableId, OpenMode.ForWrite, False)
InBlock.gif            
Dim btr As BlockTableRecord = ta.GetObject(bt(BlockTableRecord.ModelSpace), OpenMode.ForWrite, False)
InBlock.gif            
Dim objId As ObjectId = btr.AppendEntity(ent)
InBlock.gif            ta.AddNewlyCreatedDBObject(ent, 
True)
InBlock.gif            ta.Commit()
InBlock.gif            ta.Dispose()
InBlock.gif            
Return objId
InBlock.gif        
Catch ex As Exception
InBlock.gif            ShowMessage(
"AddEntity出错了:" + ex.Message)
InBlock.gif        
End Try
ExpandedSubBlockEnd.gif    
End Function

ExpandedSubBlockStart.gifContractedSubBlock.gif    
Public Function AddLayer()Function AddLayer(ByVal LayerName As StringByVal newColor As PPColor, ByVal LineWeithS As LineWeight, ByVal LineTypeName As StringOptional ByVal Description As String = "没有描述")
InBlock.gif        
Dim objId As ObjectId
InBlock.gif        
Dim db As Database = Application.DocumentManager.MdiActiveDocument.Database
InBlock.gif        
Dim tm As DBTransMan = db.TransactionManager
InBlock.gif        
Dim ta As Transaction = tm.StartTransaction
InBlock.gif        
Dim lt As LayerTable = tm.GetObject(db.LayerTableId, OpenMode.ForWrite)
InBlock.gif        
If lt.Has(LayerName) Then
InBlock.gif            objId 
= lt.Item(LayerName)
InBlock.gif        
Else
InBlock.gif            
Dim ltr As New LayerTableRecord
InBlock.gif            ltr.Name 
= LayerName
InBlock.gif            
Dim ColorType As Type = GetType(PPColor)
InBlock.gif            
Dim color1 As Color
ExpandedSubBlockStart.gifContractedSubBlock.gif            color1 
= Color.FromColorIndex(ColorMethod.ByAci, [Enum ]Enum].Parse(ColorType, newColor.ToString))
InBlock.gif            ltr.Color 
= color1
InBlock.gif            ltr.LineWeight 
= LineWeithS
InBlock.gif            ltr.LinetypeObjectId 
= LineType(LineTypeName)
InBlock.gif            ltr.Description 
= Description
InBlock.gif            objId 
= lt.Add(ltr)
InBlock.gif            tm.AddNewlyCreatedDBObject(ltr, 
True)
InBlock.gif            ta.Commit()
InBlock.gif        
End If
InBlock.gif        ta.Dispose()
InBlock.gif        tm.Dispose()
InBlock.gif        
Return objId
ExpandedSubBlockEnd.gif    
End Function

ExpandedSubBlockStart.gifContractedSubBlock.gif    
Public Function AddArc()Function AddArc(ByVal centerPoint As Point3d, ByVal normal As Vector3d, ByVal radius As DoubleByVal startAngle As DoubleByVal endAngle As DoubleByVal LayerName As StringAs ObjectId
InBlock.gif        
REM 此处不用设置线型,颜色等,因为这些已经在图层里设置好了
InBlock.gif
        Dim a As New Arc(centerPoint, normal, radius, startAngle, endAngle)
InBlock.gif        a.Layer 
= LayerName
InBlock.gif        
REM  a.Clone() REM 复制实体
InBlock.gif
        Return AddEntity(a)
ExpandedSubBlockEnd.gif    
End Function

ExpandedSubBlockStart.gifContractedSubBlock.gif    
Public Function AddLine()Function AddLine(ByVal startPt As Point3d, ByVal endpt As Point3d, ByVal LayerName As StringAs ObjectId
InBlock.gif        
Dim line As New Line(startPt, endpt)
InBlock.gif        line.Layer 
= LayerName
InBlock.gif        
Return AddEntity(line)
ExpandedSubBlockEnd.gif    
End Function

ExpandedSubBlockStart.gifContractedSubBlock.gif    
Public Function AddLine()Function AddLine(ByVal startPt As Point3d, ByVal angle As DoubleByVal length As DoubleByVal LayerName As StringAs ObjectId
InBlock.gif        
Dim line As New Line(startPt, GetPointAR(startPt, angle, length))
InBlock.gif        line.Layer 
= LayerName
InBlock.gif        
Return AddEntity(line)
ExpandedSubBlockEnd.gif    
End Function

ExpandedSubBlockStart.gifContractedSubBlock.gif    
Public Function AddMLine()Function AddMLine(ByVal scale As DoubleByVal newVertex As Point3d, ByVal LayerName As StringAs ObjectId
InBlock.gif        
REM 多样线
InBlock.gif
        Dim ml As New Mline
InBlock.gif
InBlock.gif        
Dim ms As New MlineStyle
InBlock.gif        ms.Name 
= "standard"
InBlock.gif
InBlock.gif        ml.Style 
= ms.ObjectId
InBlock.gif        ml.Layer 
= LayerName
InBlock.gif        ml.Scale 
= scale
InBlock.gif        ml.AppendSegment(newVertex)
InBlock.gif        ml.AppendSegment(
New Point3d(20200))
InBlock.gif
ExpandedSubBlockEnd.gif    
End Function

ExpandedSubBlockStart.gifContractedSubBlock.gif    
Public Function AddTrace()Function AddTrace(ByVal pointer1 As Point3d, ByVal pointer2 As Point3d, ByVal pinter3 As Point3d, ByVal pointer4 As Point3d, ByVal LayerName As StringAs ObjectId
InBlock.gif        
REM 有问题吧
InBlock.gif
        Dim myTrace As New Trace(pointer1, pointer2, pinter3, pointer4)
InBlock.gif        myTrace.LineWeight 
= LineWeight.LineWeight200
InBlock.gif        myTrace.Layer 
= LayerName
InBlock.gif        
Return AddEntity(myTrace)
InBlock.gif
ExpandedSubBlockEnd.gif    
End Function

ExpandedSubBlockStart.gifContractedSubBlock.gif    
Public Function AddShape()Function AddShape(ByVal position As Point3d, ByVal size As DoubleByVal shapeName As StringByVal rotation As DoubleByVal widthFactor As DoubleAs ObjectId
InBlock.gif        
REM shapeName ??? 有问题吧
InBlock.gif
        Dim sh As New Shape(position, size, shapeName, rotation, widthFactor)
InBlock.gif        
Return AddEntity(sh)
ExpandedSubBlockEnd.gif    
End Function

InBlock.gif
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif    
Public Function AddPolygon()Function AddPolygon(ByVal upperLeft As Point3d, ByVal upperRight As Point3d, ByVal lowerLeft As Point3d, ByVal lowerRight As Point3d) As ObjectId
InBlock.gif        
Dim rect As New Rectangle3d(upperLeft, upperRight, lowerLeft, lowerRight)
InBlock.gif        
Dim rect3d As Entity3d
InBlock.gif
InBlock.gif
InBlock.gif        
'   Dim m As New Plane(New Point3d(100, 100, 0), New Point3d(100, 200, 0), New Point3d(100, 200, 100))
InBlock.gif

InBlock.gif
InBlock.gif
InBlock.gif
ExpandedSubBlockEnd.gif    
End Function

InBlock.gif    
'''<summary>
InBlock.gif
    '''获取或设置外部处理过程的委托
InBlock.gif
    '''</summary>
ExpandedSubBlockStart.gifContractedSubBlock.gif
    Public Function AddCircle()Function AddCircle(ByVal center As Point3d, ByVal radius As DoubleAs ObjectId
InBlock.gif        
Dim myCircle = New Circle(center, Vector3d.ZAxis, radius)
InBlock.gif        
Dim circleId As ObjectId = AddEntity(myCircle)
InBlock.gif        
Return circleId
ExpandedSubBlockEnd.gif    
End Function

InBlock.gif    
'''<remarks>
InBlock.gif
    '''自己的注释说明
InBlock.gif
    '''</remarks>
ExpandedSubBlockStart.gifContractedSubBlock.gif
    Public Function AddEllipse()Function AddEllipse(ByVal centerPoint As Point3d, ByVal majorAxis As Vector3d, ByVal radiusRatio As DoubleByVal startAngle As DoubleByVal endAngle As Double)
InBlock.gif        
REM 画完整椭圆时,开始角度= 终止角度,调整角度,就可以调整方向
InBlock.gif
        REM 可能存在问题
InBlock.gif
        ' Ellipse(Ellipse = New Ellipse(center, Vector3d.ZAxis, New Vector3d(3, 0, 0), 0.5, 0, 0))
InBlock.gif
        Dim unitNormal = Vector3d.ZAxis
InBlock.gif        
Dim e As New Ellipse(centerPoint, unitNormal, majorAxis, radiusRatio, startAngle, endAngle)
InBlock.gif        
Return AddEntity(e)
ExpandedSubBlockEnd.gif    
End Function

InBlock.gif    
'''<typeparam name="text">变量参数的注释说明</typeparam>
ExpandedSubBlockStart.gifContractedSubBlock.gif
    Public Function AddDBText()Function AddDBText(ByVal text As StringByVal Position As Point3d, ByVal LayerName As String)
InBlock.gif        
'''<typeparam name="msg">变量参数的注释说明</typeparam>
InBlock.gif
        Dim mytext As New DBText
InBlock.gif        mytext.TextString 
= text   REM TextString Contents
InBlock.gif
        mytext.Position = Position REM location position
InBlock.gif
        mytext.VerticalMode = TextVerticalMode.TextVerticalMid '垂直对齐方式
InBlock.gif
        mytext.HorizontalMode = TextHorizontalMode.TextCenter '水平对齐方式
InBlock.gif
        '   mytext.AlignmentPoint = Position '文本的坐标    mytext.Position = Position  重复 ???矛盾
InBlock.gif
        mytext.Layer = LayerName
InBlock.gif        
Return AddEntity(mytext)
ExpandedSubBlockEnd.gif    
End Function

ExpandedSubBlockStart.gifContractedSubBlock.gif    
Public Function AddMText()Function AddMText(ByVal text As StringByVal Position As Point3d, ByVal LayerName As String)
InBlock.gif        
Dim mytext As New MText
InBlock.gif        mytext.Contents 
= text
InBlock.gif        mytext.Location 
= Position
InBlock.gif        mytext.Layer 
= LayerName
InBlock.gif        
Return AddEntity(mytext)
ExpandedSubBlockEnd.gif    
End Function

ExpandedSubBlockStart.gifContractedSubBlock.gif    
Public Function AddHatch()Function AddHatch(ByVal PointArray() As Point3d, ByVal HatchStyleType As HatchStyle, ByVal PatternScale As DoubleByVal PatternAngle As DoubleByVal LayerName As StringOptional ByVal PatternName As String = "ANSI31"As ObjectId
InBlock.gif        
REM 多点填充
InBlock.gif
        REM 圆,圆弧的填充呢??
InBlock.gif
        Dim hl As New HatchLoop  REM 少了new 时:未将对象设置引用到实例
InBlock.gif
        Dim P3d As Point3d
InBlock.gif        
Dim p As Point2d
InBlock.gif        
Dim bv As BulgeVertex
InBlock.gif        
For Each P3d In PointArray
InBlock.gif            
Try
InBlock.gif                p 
= New Point2d(P3d.X, P3d.Y)
InBlock.gif                bv 
= New BulgeVertex(p, 0)
InBlock.gif                
REM ShowMessage("bv.Bulge=  " + bv.Bulge.ToString)
InBlock.gif
                REM ShowMessage(" bv.Vertex.ToString" + bv.Vertex.ToString)
InBlock.gif
                hl.Add(bv)
InBlock.gif                
'  hl.LoopType = HatchLoopTypes.Default REM 改怎么选
InBlock.gif

InBlock.gif            
Catch ex As Exception
InBlock.gif                ShowMessage(
"" + ex.Message)
InBlock.gif            
End Try
InBlock.gif
InBlock.gif        
Next
InBlock.gif
InBlock.gif
InBlock.gif        
Dim ha As New Hatch REM 还有很多属性可以设置
InBlock.gif
        ha.HatchStyle = HatchStyleType
InBlock.gif        
'  ha.HatchStyle = HatchStyle.Normal   REM 三种
InBlock.gif
        ha.Layer = LayerName
InBlock.gif        ha.PatternAngle 
= PatternAngle  REM 填充图案角度 0 90,270
InBlock.gif
        ha.PatternScale = PatternScale
InBlock.gif        
' ha.HatchObjectType = HatchObjectType.HatchObject REM 2种
InBlock.gif
        ha.SetHatchPattern(HatchPatternType.PreDefined, PatternName) REM 预定义 ,自定义 ,用户定义 三种
InBlock.gif
        ' ha.SetGripStatus(GripStatus.GripsToBeDeleted)
InBlock.gif
        'ha.SetGradient(GradientPatternType.PreDefinedGradient,"")
InBlock.gif
        ' ha.IntersectWith(ent, Intersect.ExtendThis, d, 0, 0)
InBlock.gif
        ' ha.EvaluateGradientColorAt(1)
InBlock.gif
        ' ha.BoundingBoxIntersectWith(
InBlock.gif
        ' ha.AppendLoop
InBlock.gif
        ha.AppendLoop(hl)
InBlock.gif        ha.EvaluateHatch(
True)
InBlock.gif        
Return AddEntity(ha)
ExpandedSubBlockEnd.gif    
End Function

ExpandedSubBlockStart.gifContractedSubBlock.gif    
Public Function AddHatch()Function AddHatch(ByVal idC As ObjectIdCollection, ByVal HatchStyleType As HatchStyle, ByVal PatternScale As DoubleByVal PatternAngle As DoubleByVal LayerName As StringOptional ByVal PatternName As String = "ANSI31"As ObjectId
InBlock.gif        
REM 圆的填充()
InBlock.gif
        REM 多边形与圆组合的填充   ????
InBlock.gif
        Dim ha As New Hatch
InBlock.gif        ha.HatchStyle 
= HatchStyleType
InBlock.gif        
'  ha.HatchStyle = HatchStyle.Normal   REM 三种
InBlock.gif
        ha.Layer = LayerName
InBlock.gif        ha.PatternAngle 
= PatternAngle  REM 填充图案角度 0 90,270
InBlock.gif
        ha.PatternScale = PatternScale
InBlock.gif        
' ha.HatchObjectType = HatchObjectType.HatchObject REM 2种
InBlock.gif
        ha.SetHatchPattern(HatchPatternType.PreDefined, PatternName) REM 预定义 ,自定义 ,用户定义 三种
InBlock.gif

InBlock.gif        ha.AppendLoop(
0, idC)
InBlock.gif        ha.EvaluateHatch(
True)
InBlock.gif        
Return AddEntity(ha)
InBlock.gif
ExpandedSubBlockEnd.gif    
End Function

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif    
Public Function AddPolyline()Function AddPolyline(ByVal ptArr As Point3dCollection, ByVal LayerName As StringOptional ByVal width As Double = 0As ObjectId
InBlock.gif        
REM 有 Polyline Polyline2d  Polyline3d
InBlock.gif
        Dim pl As New Polyline
InBlock.gif        pl.Layer 
= LayerName
InBlock.gif        
Dim i As Integer
InBlock.gif        
Dim bulge, startWidth, endWidth As Double
InBlock.gif        bulge 
= 0
InBlock.gif        startWidth 
= width
InBlock.gif        endWidth 
= width
InBlock.gif        
For i = 0 To ptArr.Count - 1
InBlock.gif            pl.AddVertexAt(i, 
New Point2d(ptArr(i).X, ptArr(i).Y), bulge, startWidth, endWidth)
InBlock.gif        
Next
InBlock.gif        
Return AddEntity(pl)
InBlock.gif
InBlock.gif
ExpandedSubBlockEnd.gif    
End Function

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif    
Public Function AddPolyline()Function AddPolyline(ByVal ptArr As Point3dCollection, ByVal closed As BooleanByVal LayerName As StringAs ObjectId
InBlock.gif        
REM 有 Polyline Polyline2d  Polyline3d
InBlock.gif
        'closed表示闭合 只有添加多边形时才闭合
InBlock.gif
        Dim pline3d As New Polyline3d(Poly3dType.SimplePoly, ptArr, closed)
InBlock.gif        pline3d.Layer 
= LayerName
InBlock.gif        
Return AddEntity(pline3d)
ExpandedSubBlockEnd.gif    
End Function

ExpandedSubBlockStart.gifContractedSubBlock.gif    
Public Function AddRectangle()Function AddRectangle(ByVal pt1 As Point3d, ByVal pt3 As Point3d, ByVal LayerName As StringAs ObjectId
InBlock.gif        
Dim ptArr As New Point3dCollection
InBlock.gif        ptArr.Add(pt1)
InBlock.gif        ptArr.Add(
New Point3d(pt1.X, pt3.Y, 0))
InBlock.gif        ptArr.Add(pt3)
InBlock.gif        ptArr.Add(
New Point3d(pt3.X, pt1.Y, 0))
InBlock.gif        
Return AddPolyline(ptArr, True, LayerName)
ExpandedSubBlockEnd.gif    
End Function

ExpandedSubBlockStart.gifContractedSubBlock.gif    
Public Function AddPolygon()Function AddPolygon(ByVal centerPoint As Point3d, ByVal number As IntegerByVal radius As DoubleByVal LayerName As StringOptional ByVal width As Double = 0As ObjectId
InBlock.gif        
REM 半径指的是外接圆的半径
InBlock.gif
        Dim angle As Double
InBlock.gif        angle 
= Math.PI * 2 / number
InBlock.gif        
Dim ptArr As New Point3dCollection
InBlock.gif        
Dim pt As Point3d
InBlock.gif        
Dim i As Integer
InBlock.gif        
For i = 0 To number - 1
InBlock.gif            
' pt.X = centerPoint.X + radius * Math.Cos(i * angle)
InBlock.gif
            ' pt.Y = centerPoint.Y + radius * Math.Sin(i * angle)
InBlock.gif
            pt = New Point3d(centerPoint.X + radius * Math.Cos(i * angle), centerPoint.Y + radius * Math.Sin(i * angle), 0)
InBlock.gif            ptArr.Add(pt)
InBlock.gif        
Next
InBlock.gif        
Return AddPolyline(ptArr, True, LayerName)
InBlock.gif
ExpandedSubBlockEnd.gif    
End Function

InBlock.gif
InBlock.gif    
REM 没有成功
ExpandedSubBlockStart.gifContractedSubBlock.gif
    Public Function AddTable()Function AddTable(ByVal Position As Point3d, ByVal row As IntegerByVal col As IntegerAs ObjectId
InBlock.gif        
Dim mytable As New Table
InBlock.gif        mytable.NumRows 
= row
InBlock.gif        mytable.NumColumns 
= col
InBlock.gif        mytable.SetRowHeight(
13)
InBlock.gif        mytable.SetTextHeight(
322.5)
InBlock.gif        mytable.Position 
= Position
InBlock.gif        mytable.SetBackgroundColor(
22, Color.FromColorIndex(ColorMethod.ByAci, 1))
InBlock.gif        mytable.SetTextString(
00"你是SB")  REM 还有其他的
InBlock.gif
        AddEntity(mytable)
ExpandedSubBlockEnd.gif    
End Function

ContractedSubBlock.gifExpandedSubBlockStart.gif
创建组#Region "创建组"
ExpandedSubBlockStart.gifContractedSubBlock.gif    
Public Sub AddGroup()Sub AddGroup(ByVal objIds As ObjectIdCollection, ByVal pGroupName As System.String)
InBlock.gif        
Dim db As Database = Application.DocumentManager.MdiActiveDocument.Database
InBlock.gif        
Dim tm As DBTransMan = db.TransactionManager
InBlock.gif        
'start a transaction
InBlock.gif
        Dim ta As Transaction = tm.StartTransaction()
InBlock.gif        
Try
InBlock.gif            
Dim gp As New Group(pGroupName, True)
InBlock.gif            
Dim dict As DBDictionary = tm.GetObject(db.GroupDictionaryId, OpenMode.ForWrite, True)
InBlock.gif            dict.SetAt(
"ASDK_NEWNAME", gp)
InBlock.gif
InBlock.gif            
Dim thisId As ObjectId
InBlock.gif            
For Each thisId In objIds
InBlock.gif                gp.Append(thisId)
InBlock.gif            
Next
InBlock.gif            tm.AddNewlyCreatedDBObject(gp, 
True)
InBlock.gif            ta.Commit()
InBlock.gif        
Finally
InBlock.gif            ta.Dispose()
InBlock.gif        
End Try
ExpandedSubBlockEnd.gif    
End Sub

ExpandedSubBlockEnd.gif
#End Region

ContractedSubBlock.gifExpandedSubBlockStart.gif
添加UCS#Region "添加UCS"
ExpandedSubBlockStart.gifContractedSubBlock.gif    
Public Function AddUcs()Function AddUcs(ByVal UcsName As StringAs ObjectId
InBlock.gif        
Dim objId As ObjectId
InBlock.gif        
Dim db As Database = Application.DocumentManager.MdiActiveDocument.Database
InBlock.gif        
Dim tm As DBTransMan = db.TransactionManager
InBlock.gif        
Dim ta As Transaction = tm.StartTransaction
InBlock.gif        
Dim ut As UcsTable = tm.GetObject(db.UcsTableId, OpenMode.ForWrite)
InBlock.gif        
If ut.Has(UcsName) Then
InBlock.gif            objId 
= ut.Item(UcsName)
InBlock.gif        
Else
InBlock.gif            
Dim utr As New UcsTableRecord
InBlock.gif            utr.Name 
= UcsName
InBlock.gif            
'utr.Origin=
InBlock.gif
            ' utr.XAxis
InBlock.gif
            objId = ut.Add(utr)
InBlock.gif            tm.AddNewlyCreatedDBObject(utr, 
True)
InBlock.gif            ta.Commit()
InBlock.gif
InBlock.gif        
End If
InBlock.gif        ta.Dispose()
InBlock.gif        tm.Dispose()
InBlock.gif        
Return objId
ExpandedSubBlockEnd.gif    
End Function

ExpandedSubBlockEnd.gif
#End Region

ContractedSubBlock.gifExpandedSubBlockStart.gif
添加视口#Region "添加视口"
ExpandedSubBlockStart.gifContractedSubBlock.gif    
Public Function AddViewport()Function AddViewport(ByVal ViewPortName As StringAs ObjectId
InBlock.gif        
Dim objId As ObjectId
InBlock.gif        
Dim db As Database = Application.DocumentManager.MdiActiveDocument.Database
InBlock.gif        
Dim tm As DBTransMan = db.TransactionManager
InBlock.gif        
Dim ta As Transaction = tm.StartTransaction
InBlock.gif        
Dim vpt As ViewportTable = tm.GetObject(db.ViewportTableId, OpenMode.ForWrite)
InBlock.gif        
If vpt.Has(ViewPortName) Then
InBlock.gif            objId 
= vpt.Item(ViewPortName)
InBlock.gif        
Else
InBlock.gif            
Dim vptr As New ViewportTableRecord
InBlock.gif            vptr.Name 
= ViewPortName
InBlock.gif            
'  Autodesk.AutoCAD.Geometry.CoordinateSystem3d()
InBlock.gif
            'vptr.Ucs()
InBlock.gif

InBlock.gif            objId 
= vpt.Add(vptr)
InBlock.gif            tm.AddNewlyCreatedDBObject(vptr, 
True)
InBlock.gif            ta.Commit()
InBlock.gif        
End If
InBlock.gif        ta.Dispose()
InBlock.gif        tm.Dispose()
InBlock.gif        
Return objId
ExpandedSubBlockEnd.gif    
End Function

ExpandedSubBlockEnd.gif
#End Region

ContractedSubBlock.gifExpandedSubBlockStart.gif
添加视图#Region "添加视图"
ExpandedSubBlockStart.gifContractedSubBlock.gif    
Public Function AddView()Function AddView(ByVal ViewName As StringByVal render As RenderMode, ByVal ucsId As ObjectId) As ObjectId
InBlock.gif        
REM 添加视图() 这个和添加图层是相同的
InBlock.gif
        Dim db As Database = Application.DocumentManager.MdiActiveDocument.Database
InBlock.gif        
Dim tm As DBTransMan = db.TransactionManager
InBlock.gif        
Dim ta As Transaction = tm.StartTransaction
InBlock.gif        
Dim vt As ViewTable = ta.GetObject(db.ViewTableId, OpenMode.ForWrite)
InBlock.gif        
Dim objId As ObjectId
InBlock.gif        
If vt.Has(ViewName) Then
InBlock.gif            objId 
= vt.Item(ViewName)
InBlock.gif        
Else
InBlock.gif            
Dim vtr As New ViewTableRecord
InBlock.gif            vtr.Name 
= ViewName
InBlock.gif            vtr.RenderMode 
= render
InBlock.gif            vtr.SetUcs(ucsId)
InBlock.gif            
REM vtr.SetUcs(
InBlock.gif
            objId = vt.Add(vtr)
InBlock.gif            tm.AddNewlyCreatedDBObject(vtr, 
True)
InBlock.gif            ta.Commit()
InBlock.gif        
End If
InBlock.gif        
Return objId
ExpandedSubBlockEnd.gif    
End Function

ExpandedSubBlockEnd.gif
#End Region

InBlock.gif
InBlock.gif
InBlock.gif
ExpandedBlockEnd.gif
End Class

None.gif

转载于:https://www.cnblogs.com/ObjectARX/archive/2005/10/10/251605.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值