03-05 创建和编辑AutoCAD实体(五) 使用图层、颜色和线型(1)使用图层(1-2)

03-05 创建和编辑AutoCAD实体(五) 使用图层、颜色和线型(1)使用图层(1-2),第1张

概述  1.2、Create and Name Layers 创建并命名图层 You can create new layers and assign color and linetype properties to those layers. Each individual layer is part of the Layers table. Use the Add function to crea 1.2、Create and name Layers 创建并命名图层@H_404_1@

You can create new layers and assign color and linetype propertIEs to those layers. Each indivIDual layer is part of the Layers table. Use the Add function to create a new layer and add it to the Layers table.

我们可以创建新图层,并给这些新图层的颜色和线型属性赋值。每个图层均为Layers表的一部分。使用Add方法创建新图层并将其添加到Layers表中。

You can assign a name to a layer when it is created. To change the name of a layer after it has been created,use the name property. Layer names can include up to 255 characters and contain letters,digits,and the special characters dollar sign ($),hyphen (-),and underscore (_).

创建图层时可以为其命名,修改图层名称用name属性。图层名称可以含最多255个字符,包括字母、数字以及特殊字符美元符号($)、连字符(-)、下划线(_)等。

For more information about creating layers,see “Create and name Layers” in the autoCAD User's GuIDe.

创建图层的更多内容,见autoCAD用户指南中的“创建并命名图层”。

Create a new layer,assign it the color red,and add an object to the layer 创建一个新图层,设为红色,并添加到图层表里

The following code creates a new layer and circle object. The new layer is assigned the color red. The circle is assigned to the layer,and the color of the circle changes accordingly.

下面的代码创建一个新图层和一个圆对象,新图层的颜色设为红色。将圆指定到新图层时,圆的颜色会相应地变成红色。

VB.NET

imports autodesk.autoCAD.Runtime

imports autodesk.autoCAD.applicationservices

imports autodesk.autoCAD.DatabaseServices

imports autodesk.autoCAD.Geometry

imports autodesk.autoCAD.colors

<CommandMethod("CreateAndAssignALayer")> _

Public Sub CreateAndAssignALayer()

'' 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 Layer table for read

Dim acLyrTbl As Layertable

acLyrTbl = acTrans.Getobject(acCurDb.LayertableID,_

OpenMode.ForRead)

Dim sLayername As String = "Center"

If acLyrTbl.Has(sLayername) = False Then

Dim acLyrTblRec As LayertableRecord = New LayertableRecord()

'' Assign the layer the ACI color 1 and a name

acLyrTblRec.color = color.FromcolorIndex(colorMethod.ByAci,1)

acLyrTblRec.name = sLayername

'' Upgrade the Layer table for write

acLyrTbl.Upgradeopen()

'' Append the new layer to the Layer table and the transaction

acLyrTbl.Add(acLyrTblRec)

acTrans.AddNewlyCreatedDBObject(acLyrTblRec,True)

End If

'' Open the Block table for read

Dim acBlkTbl As Blocktable

acBlkTbl = acTrans.Getobject(acCurDb.BlocktableID,_

OpenMode.ForRead)

'' Open the Block table record Model space for write

Dim acBlkTblRec As BlocktableRecord

acBlkTblRec = acTrans.Getobject(acBlkTbl(BlocktableRecord.ModelSpace),_

OpenMode.ForWrite)

'' Create a circle object

Dim acCirc As Circle = New Circle()

acCirc.Center = New Point3d(2,2,0)

acCirc.Radius = 1

acCirc.Layer = sLayername

acBlkTblRec.AppendEntity(acCirc)

acTrans.AddNewlyCreatedDBObject(acCirc,True)

'' 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;

using autodesk.autoCAD.Geometry;

using autodesk.autoCAD.colors;

[CommandMethod("CreateAndAssignALayer")]

public static voID CreateAndAssignALayer()

{

// 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 Layer table for read以读打开图层表

Layertable acLyrTbl;

acLyrTbl = acTrans.Getobject(acCurDb.LayertableID,

OpenMode.ForRead) as Layertable;

string sLayername = "Center";

if (acLyrTbl.Has(sLayername) == false)

{

LayertableRecord acLyrTblRec = new LayertableRecord();

// Assign the layer the autoCADcolorIndex(ACI) color 1 and a name赋予图层颜色和名称(颜色索引值1表示红色)

acLyrTblRec.color = color.FromcolorIndex(colorMethod.ByAci,1);

acLyrTblRec.name = sLayername;

// Upgrade the Layer table for write以写升级打开图层表

acLyrTbl.Upgradeopen();

// Append the new layer to the Layer table and the transaction

// 将新图层添加到图层表,并进行事务登记

acLyrTbl.Add(acLyrTblRec);

acTrans.AddNewlyCreatedDBObject(acLyrTblRec,true);

}

// Open the Block table for read以读打开块表

Blocktable acBlkTbl;

acBlkTbl = acTrans.Getobject(acCurDb.BlocktableID,

OpenMode.ForRead) as Blocktable;

// Open the Block table record Model space for write以写打开块表记录模型空间

BlocktableRecord acBlkTblRec;

acBlkTblRec = acTrans.Getobject(acBlkTbl[BlocktableRecord.ModelSpace],

OpenMode.ForWrite) as BlocktableRecord;

// Create a circle object新建一个圆

Circle acCirc = new Circle();

acCirc.Center = new Point3d(2,0);

acCirc.Radius = 1;

// 设置圆所归属的图层

acCirc.Layer = sLayername;

acBlkTblRec.AppendEntity(acCirc);

acTrans.AddNewlyCreatedDBObject(acCirc,true);

// Save the changes and dispose of the transaction保存修改并关闭事务

acTrans.Commit();

}

}

VBA/ActiveX Code Reference

Sub CreateAssignALayer()

' Create a new layer and assign it the color red

Dim layerObj As AcadLayer

Set layerObj = ThisDrawing.Layers.Add("Center")

layerObj.color = acRed

' Create a circle

Dim circleObj As AcadCircle

Dim center(0 To 2) As Double

Dim radius As Double

center(0) = 2: center(1) = 2: center(2) = 0

radius = 1

Set circleObj = ThisDrawing.ModelSpace. _

AddCircle(center,radius)

' Place the circle on the Center layer

circleObj.Layer = "Center"

circleObj.Update

End Sub

总结

以上是内存溢出为你收集整理的03-05 创建和编辑AutoCAD实体(五) 使用图层、颜色和线型(1)使用图层(1-2)全部内容,希望文章能够帮你解决03-05 创建和编辑AutoCAD实体(五) 使用图层、颜色和线型(1)使用图层(1-2)所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/1291706.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-10
下一篇 2022-06-10

发表评论

登录后才能评论

评论列表(0条)

保存