EaBIM一直以来积极响应国家“十二五”推进建筑业信息化的号召,对建筑领域的信息技术开展深入技术交流和探讨!致力于打造“BIM-建筑师-生态技术”三位一体综合资源交流共享平台,希望为BIM与可持续设计理念及技术的普及做出微小的贡献!!!

EaBIM

 找回密码
 注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

搜索
查看: 754|回复: 0
打印 上一主题 下一主题

[资料] 创建和编辑AutoCAD实体(二) 创建对象(3)

[复制链接]

1514

主题

7465

帖子

1万

积分

admin

Rank: 10Rank: 10Rank: 10Rank: 10Rank: 10Rank: 10Rank: 10Rank: 10Rank: 10Rank: 10

积分
12406

社区QQ达人

跳转到指定楼层
楼主
发表于 2014-1-8 15:48:03 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

7、Create Hatches创建图案填充
Closed boundaries can be filled with a pattern.
可以使用图案来填充闭合边界。
When creating hatch, you do not initially specify the area to be filled. First you must create the Hatch object. Once this is done, you can specify the outer loop, which is the outermost boundary for the hatch. You can then continue to specify any inner loops that may exist in the hatch.
创建图案填充时,不必一上来就指定要填充的区域,应首先创建Hatch对象,然后可以指定外环,也就是要填充的区域的最外边界,然后可以继续指定可能存在的所有填充内环。
For more information about working with hatches, see “Overview of Hatch Patterns and Fills” in the AutoC AD User's Guide.
关于使用图案填充的更多内容,见AutoCAD用户指南的“填充图案与填充概览”。
Topics in this section本小节内容

·         Create a Hatch Object 创建Hatch对象
·         Associate a Hatch 关联图案填充
·         Assign the Hatch Pattern Type and Name 指定填充图案的类型和名称
·         Define the Hatch Boundaries 定义填充边界

7.1、Create a Hatch Object创建Hatch对象
When creating a Hatch object, you specify the hatch pattern type, the hatch pattern name, and the associativity. Once a Hatch object has been created, you will not be able to change the hatch associativity.
创建Hatch对象时,需指定填充图案类型、填充图案名称及关联属性。一旦创建好Hatch对象,就不能改变其关联属性。
To create a Hatch object, you create a new instance of the object and then use the AppendEntity method to add it to a BlockTableRecord object.
所谓创建Hatch对象,就是创建Hatch对象的一个新的实例,然后用AppendEntity方法将该实例添加到BlockTableRecord对象中。
7.2、Associate a Hatch关联图案填充
You can create associative or nonassociative hatches. Associative hatches are linked to their boundaries and updated when the boundaries are modified. Nonassociative hatches are independent of their boundaries.
可以创建关联图案填充或非关联图案填充。关联图案填充就是图案填充对象与其边界是关联的,当边界改变时图案填充随之更新。而非关联图案填充是不依赖其边界的。
To make a hatch associative, set the Associative property of the hatch object created to TRUE. To make a hatch nonassociative, set the Associative property to FALSE.
要想创建关联图案填充,需将所创建图案填充对象的Associative属性设置为TRUE。创建非关联图案填充,就将Associative属性设置为FALSE。
Associativity for hatch must be set before appending the hatch loop. If a hatch object is nonassociative, you can make it associative again by setting the Associative property to TRUE and reappending the hatch loop.
图案填充的关联属性必须在将其添加到填充环之前设置。如果图案填充对象是非关联的,可以通过设置Associative属性值为TRUE将其重新设为关联的,然后再重新将其添加到填充环内。
7.3、Assign the Hatch Pattern Type and Name指定填充图案的类型和名称
AutoCAD supplies a solid-fill and more than fifty industry-standard hatch patterns. Hatch patterns highlight a particular feature or area of a drawing. For example, patterns can help differentiate the components of a 3D object or represent the materials that make up an object.
AutoCAD提供了一个实体填充和多至50种工业标准的填充图案。填充图案用来强调图形中的特殊形状或区域。比如,图案可以帮助区分三维对象的部件或表示构成对象的材质等。
You can use a pattern supplied with AutoCAD or one from an external pattern library. For a table of the hatch patterns supplied with AutoCAD, see the AutoCAD Command Reference Guide.
我们可以使用AutoCAD提供的填充图案,或使用外部填充库提供的填充图案。AutoCAD提供的填充图案的列表,见AutoCAD命令参考指南
To specify a unique pattern, you must specify both a pattern type and name for the Hatch object. The pattern type specifies where to look up the pattern name. When entering the pattern type, use one of the following constants:
要指定某一特定的填充图案,必须同时指定Hatch对象的填充图案类型和名称。填充图案类型指明到哪里去查找填充图案的名称。输入填充图案类型时,使用下列常量之一:
HatchPatternType.PreDefined
Selects the pattern name from those defined in the acad.pat or files.
从acad.pat文件中定义的图案名称中选择;
HatchPatternType.UserDefined
Defines a pattern of lines using the current linetype.
使用当前线型定义一个直线图案;
HatchPatternType.CustomDefined
Selects the pattern name from a PAT other than the acad.pat or files.
从acad.pat以外的PAT文件中选择图案名称
When entering the pattern name, use a name that is valid for the file specified by the pattern type.
输入图案名称时,使用的名称必须是图案类型指定的PAT文件里的有效名称。
7.4、Define the Hatch Boundaries定义填充边界
Once the Hatch object is created, the hatch boundaries can be added. Boundaries can be any combination of lines, arcs, circles, 2D polylines, ellipses, splines, and regions.
创建Hatch对象之后,就可以添加填充边界。边界可以是直线、圆弧、圆、二维多段线、椭圆、样条曲线及面域的任意组合。
The first boundary added must be the outer boundary, which defines the outermost limits to be filled by the hatch. To add the outer boundary, use the AppendLoop method with the HatchLoopTypes.Outermost constant for the type of loop to append.
首先添加的必须是外侧边界,它定义了图案填充的最外界限。添加外侧边界,使用带HatchLoopTypes.Outermost常量的AppendLoop方法,该常量表示所添加封闭边界的类型。
Once the outer boundary is defined, you can continue adding additional boundaries. Add inner boundaries using the AppendLoop method with the HatchLoopTypes.Default constant.
定义好外侧边界后,可以继续添加其他边界。使用带HatchLoopTypes.Default常量的 AppendLoop方法可以添加内边界。
Inner boundaries define islands within the hatch. How these islands are handled by the Hatch object depends on the setting of the HatchStyle property. The HatchStyle property can be set to one of the following conditions:
内边界定义填充区域内的孤立区域。Hatch对象如何处理这些孤立区域依赖于HatchStyle属性的设置。HatchStyle属性可以设置为下列情况:

Hatch style definitions填充样式定义


HatchStyleConditionDescription描述
1

                               
登录/注册后可看大图



Normal
(HatchStyle.Normal)

Specifies standard style, or normal. This option hatches inward from the outermost area boundary. If AutoCAD encounters an internal boundary, it turns off hatching until it encounters another boundary. This is the default setting for the HatchStyle property.
标准样式或常规样式,是HatchStyle属性的默认设置。AutoCAD从最外边往里填充,当遇到一个内边界时关闭填充直到遇到另一个内边界。
2

                               
登录/注册后可看大图


Outer
(HatchStyle.Outer)

Fills the outermost areas only. This style also hatches inward from the area boundary, but it turns off hatching if it encounters an internal boundary and does not turn it back on again.
只填充最外区域。本样式也是从最外边往里填充,当遇到一个内边界时关闭填充并不再打开。
3

                               
登录/注册后可看大图


Ignore
(HatchStyle.Ignore)

Ignores internal structure. This option hatches through all internal objects.
忽略内部结构。本选项填充全部内部对象。


When you have finished defining the hatch it must be evaluated before it can be displayed. Use the EvaluateHatch method to do this.
完成对图案填充的定义后,必须在显示前对其进行求值。使用EvaluateHatch方法来作这件事。
Create a Hatch object 创建Hatch对象

The following example creates an associated hatch in Model space. Once the hatch has been created, you can change the size of the circle that the hatch is associated with. The hatch will change to match the size of the circle.
下面的示例在模型空间创建一个关联图案填充。图案填充创建完后,可以改变填充所关联的圆的大小,填充将改变自己来适应圆的大小。
VB.NET
Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.Geometry

<CommandMethod("AddHatch")> _
Public Sub AddHatch()
  '' 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 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 for the closed boundary to hatch
      Dim acCirc As Circle = New Circle()
      acCirc.Center = New Point3d(3, 3, 0)
      acCirc.Radius = 1

      '' Add the new circle object to the block table record and the transaction
      acBlkTblRec.AppendEntity(acCirc)
      acTrans.AddNewlyCreatedDBObject(acCirc, True)

      '' Adds the circle to an object id array
      Dim acObjIdColl As ObjectIdCollection = New ObjectIdCollection()
      acObjIdColl.Add(acCirc.ObjectId)

      '' Create the hatch object and append it to the block table record
      Dim acHatch As Hatch = New Hatch()
      acBlkTblRec.AppendEntity(acHatch)
      acTrans.AddNewlyCreatedDBObject(acHatch, True)

      '' Set the properties of the hatch object
      '' Associative must be set after the hatch object is appended to the
      '' block table record and before AppendLoop
      acHatch.SetHatchPattern(HatchPatternType.PreDefined, "ANSI31")
      acHatch.Associative = True
      acHatch.AppendLoop(HatchLoopTypes.Outermost, acObjIdColl)
      acHatch.EvaluateHatch(True)

      '' Save the new object to the database
      acTrans.Commit()
  End Using
End Sub
C#
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;

[CommandMethod("AddHatch")]
public static void AddHatch()
{
  // 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 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 for the closed boundary to hatch
      //创建一个圆作为填充的封闭边界
      Circle acCirc = new Circle();
      acCirc.Center = new Point3d(3, 3, 0);
      acCirc.Radius = 1;

      // Add the new circle object to the block table record and the transaction
      acBlkTblRec.AppendEntity(acCirc);
      acTrans.AddNewlyCreatedDBObject(acCirc, true);

      // Adds the circle to an object id array
      //将圆的ObjectId添加到对象id数组
      ObjectIdCollection acObjIdColl = new ObjectIdCollection();
      acObjIdColl.Add(acCirc.ObjectId);

      // Create the hatch object and append it to the block table record
      // 创建填充对象并添加到块表记录,然后设置其属性
      Hatch acHatch = new Hatch();
      acBlkTblRec.AppendEntity(acHatch);
      acTrans.AddNewlyCreatedDBObject(acHatch, true);

      // Set the properties of the hatch object
      // Associative must be set after the hatch object is appended to the
      // block table record and before AppendLoop
      // 设置填充对象的属性,在调用AppendLoop之前设置填充对象的关联属性
      acHatch.SetHatchPattern(HatchPatternType.PreDefined, "ANSI31");
      acHatch.Associative = true;
      acHatch.AppendLoop(HatchLoopTypes.Outermost, acObjIdColl);
      acHatch.EvaluateHatch(true);

      // Save the new object to the database保存新对象到数据库
      acTrans.Commit();
  }
}
VBA/ActiveX Code Reference
Sub AddHatch()
    Dim hatchObj As AcadHatch
    Dim patternName As String
    Dim PatternType As Long
    Dim bAssociativity As Boolean

    ' Define the hatch
    patternName = "ANSI31"
    PatternType = 0
    bAssociativity = True

    ' Create the associative Hatch object
    Set hatchObj = ThisDrawing.ModelSpace.AddHatch _
                       (PatternType, patternName, bAssociativity)

    ' Create the outer boundary for the hatch. (a circle)
    Dim outerLoop(0 To 0) As AcadEntity
    Dim center(0 To 2) As Double
    Dim radius As Double
    center(0) = 3: center(1) = 3: center(2) = 0
    radius = 1
    Set outerLoop(0) = ThisDrawing.ModelSpace. _
                           AddCircle(center, radius)

    ' Append the outerboundary to the hatch
    ' object, and display the hatch
    hatchObj.AppendOuterLoop (outerLoop)
    hatchObj.Evaluate
    ThisDrawing.Regen True
End Sub


分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友 微信微信
收藏收藏 转播转播 分享分享 分享淘帖 支持支持 反对反对

相关帖子

工作时间:工作日的9:00-12:00/13:30-18:00,节假日不在线,请勿留言
*滑块验证:
您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|EaBIM网 ( 苏ICP备2020058923号-1  苏公网安备32011502011255号

GMT+8, 2024-11-27 04:15

Powered by Discuz! X3.2 Licensed

© 2001-2013 Comsenz Inc.

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