明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 2851|回复: 1

各位高手:添加一多义线并设置线型错在什么地方

[复制链接]
发表于 2007-5-21 21:41:00 | 显示全部楼层 |阅读模式

 '绘多义线
    <CommandMethod("AddPL")> _
        Public Sub AddPL()
        Dim pl As New Polyline
        Dim DB As Database
        Dim trans As Transaction
        Dim btr As BlockTableRecord
        Dim bt As BlockTable
        'Dim li As Object


        DB = HostApplicationServices.WorkingDatabase
        trans = DB.TransactionManager.StartTransaction
        bt = trans.GetObject(DB.BlockTableId, OpenMode.ForWrite)
        btr = trans.GetObject(bt(BlockTableRecord.ModelSpace), OpenMode.ForWrite)
        'Dim pLinetypeTbl As LinetypeTable = trans.GetObject(DB.LinetypeTableId, OpenMode.ForRead)

        'If pLinetypeTbl.Has("DASHDOT") Then

            'DB.LoadLineTypeFile("DASHDOT", "acadiso.lin")
            'End If
            Dim point2D(2) As Point2d

            point2D(0) = New Point2d(10, 10)
            point2D(1) = New Point2d(10, 5)
            point2D(2) = New Point2d(30, 40)

            pl.AddVertexAt(0, point2D(0), 0, 1, 1)
            pl.AddVertexAt(1, point2D(1), 0, 1, 1)
        pl.AddVertexAt(2, point2D(2), 0, 1, 1)
        pl.LinetypeId = CreatLineType("DASHDOT")
            ' pl.Linetype = "DASHDOT"
            btr.AppendEntity(pl)
            trans.AddNewlyCreatedDBObject(pl, True)
            trans.Commit()
            trans.Dispose()

    End Sub

    Private Function CreatLineType(ByVal LineTypeName As String) As ObjectId
        Dim LineTypeID As ObjectId
        Dim db As Database = HostApplicationServices.WorkingDatabase
        Using trans As Transaction = db.TransactionManager.StartTransaction
            Dim it As LinetypeTable = trans.GetObject(db.LinetypeTableId, OpenMode.ForRead)
            If it.Has(LineTypeName) Then
                LineTypeID = it.Item(LineTypeName)
            Else
                db.LoadLineTypeFile(LineTypeName, "acadiso.lin")
                Dim ltr As New LinetypeTableRecord
                ltr.Name = LineTypeName
                it.UpgradeOpen()
                LineTypeID = it.Add(ltr)
                trans.AddNewlyCreatedDBObject(ltr, True)
                
            End If

trans.Commit()

        End Using
        Return LineTypeID
    End Function

发表于 2007-5-22 13:28:00 | 显示全部楼层

Dim it As LinetypeTable = trans.GetObject(db.LinetypeTableId, OpenMode.ForRead)

 OpenMode.ForRead 改为OpenMode.ForWrite

没有测试过,只是看见这个地方有问题

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

本版积分规则

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

GMT+8, 2024-11-26 08:21 , Processed in 0.171426 second(s), 23 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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