CAD开发者社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

ObjectARX 开发指南

使用线型 (.NET)

2023-1-1 12:57| 发布者: admin| 查看: 1429| 评论: 0|来自: AutoCAD

线型是虚线、点和空格的重复模式。复杂线型是符号的重复模式。要使用线型,必须先将其加载到图形中。线型定义必须存在于 LIN 库文件中,然后才能将线型加载到图形中。要将线型加载到图形中,请使用对象的杆件方法。LoadLineTypeFileDatabase

注意:AutoCAD 内部使用的线型不应与某些绘图仪提供的硬件线型混淆。这两种类型的虚线产生类似的结果。但是,不要同时使用这两种类型,因为结果可能是不可预测的。

将线型加载到 AutoCAD 中

本示例尝试从acad.lin文件加载线型“CENTER”。如果线型已存在,或者文件不存在,则会显示一条消息。

VB.NET

Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
 
<CommandMethod("LoadLinetype")> _
Public Sub LoadLinetype()
    '' Get the current document and database
    Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument
    Dim acCurDb As Database = acDoc.Database

    '' Start a transaction
    Using acTrans As Transaction = acCurDb.TransactionManager.StartTransaction()

        '' Open the Linetype table for read
        Dim acLineTypTbl As LinetypeTable
        acLineTypTbl = acTrans.GetObject(acCurDb.LinetypeTableId, _
                                         OpenMode.ForRead)

        Dim sLineTypName As String = "Center"

        If acLineTypTbl.Has(sLineTypName) = False Then
            '' Load the Center Linetype
            acCurDb.LoadLineTypeFile(sLineTypName, "acad.lin")
        End If

        '' Save the changes and dispose of the transaction
        acTrans.Commit()
    End Using
End Sub

C#

using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
 
[CommandMethod("LoadLinetype")]
public static void LoadLinetype()
{
    // Get the current document and database
    Document acDoc = Application.DocumentManager.MdiActiveDocument;
    Database acCurDb = acDoc.Database;

    // Start a transaction
    using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
    {
        // Open the Linetype table for read
        LinetypeTable acLineTypTbl;
        acLineTypTbl = acTrans.GetObject(acCurDb.LinetypeTableId,
                                            OpenMode.ForRead) as LinetypeTable;

        string sLineTypName = "Center";

        if (acLineTypTbl.Has(sLineTypName) == false)
        {
            // Load the Center Linetype
            acCurDb.LoadLineTypeFile(sLineTypName, "acad.lin");
        }

        // Save the changes and dispose of the transaction
        acTrans.Commit();
    }
}

VBA/ActiveX 代码参考

Sub LoadLinetype()
    On Error GoTo ERRORHANDLER
 
    Dim linetypeName As String
    linetypeName = "CENTER"
 
    ' Load "CENTER" line type from acad.lin file
    ThisDrawing.Linetypes.Load linetypeName, "acad.lin"
    Exit Sub
 
ERRORHANDLER:
    MsgBox Err.Description
 
End Sub

路过

雷人

握手

鲜花

鸡蛋

最新评论

QQ|Archiver|CAD开发者社区 ( 苏ICP备2022047690号-1 )

GMT+8, 2024-5-19 12:45

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

返回顶部