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

EaBIM

 找回密码
 注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

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

[资料] 创建和编辑AutoCAD实体(四) 编辑二维命名对象 (5)

[复制链接]

1514

主题

7465

帖子

1万

积分

admin

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

积分
12396

社区QQ达人

跳转到指定楼层
楼主
发表于 2014-1-8 15:34:42 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
7、Extend and Trim Objects延伸和修剪对象
You can change the angle of arcs and you can change the length of lines, open polylines, elliptical arcs, and open splines. The results are similar to both extending and trimming objects.
我们可以改变圆弧的角度,还可以改变直线、开放多段线、椭圆弧及开放样条曲线的长度。其结果类似于延伸对象和修剪对象。
You can extend or trim an object by editing its properties. For example, to lengthen a line, simply change the coordinates of the StartPoint or EndPoint properties. To change the angle of an arc, change the StartAngle or EndAngle property of the arc. Once you have altered an object's property or properties, you might need to regenerate the display to see the changes in the drawing window.
我们可以编辑对象属性来延伸或修剪对象。例如,延长一条直线,只需简单修改直线的StartPoint属性或EndPoint属性坐标。修改圆弧的角度,只需简单修改圆弧的StartAngle 属性或EndAngle属性。一旦改变了对象的一个或多个属性,我们就需要重新生成图形显示才能看到所作的修改。
For more information about extending and trimming objects, see “Resize or Reshape Objects” in theAutoCAD User's Guide.
更多关于延伸和修剪对象的内容,见AutoCAD用户指南中的“修改对象的大小和形状”内容。
Lengthen a line延长一条直线

This example creates a line and then changes the endpoint of that line, resulting in a longer line.
本例创建一条直线,然后修改其EndPoint属性来使直线变长。
VB.NET
Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.Geometry

<CommandMethod("ExtendObject")> _
  1. <div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">Public Sub ExtendObject()</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">  '' Get the current document and database</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">  Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">  Dim acCurDb As Database = acDoc.Database</div>
  2. <div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">  '' Start a transaction</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">  Using acTrans As Transaction = acCurDb.TransactionManager.StartTransaction()</div>
  3. <div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      '' Open the Block table for read</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      Dim acBlkTbl As BlockTable</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId, _</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">                                   OpenMode.ForRead)</div>
  4. <div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      '' Open the Block table record Model space for write</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      Dim acBlkTblRec As BlockTableRecord</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      acBlkTblRec = acTrans.GetObject(acBlkTbl(BlockTableRecord.ModelSpace), _</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">                                      OpenMode.ForWrite)</div>
  5. <div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      '' Create a line that starts at (4,4,0) and ends at (7,7,0)</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      Dim acLine As Line = New Line(New Point3d(4, 4, 0), _</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">                                    New Point3d(7, 7, 0))</div>
  6. <div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      '' Add the new object to the block table record and the transaction</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      acBlkTblRec.AppendEntity(acLine)</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      acTrans.AddNewlyCreatedDBObject(acLine, True)</div>
  7. <div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      '' Update the display and diaplay a message box</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      acDoc.Editor.Regen()</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      Application.ShowAlertDialog("Before extend")</div>
  8. <div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      '' Double the length of the line</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      acLine.EndPoint = acLine.EndPoint + acLine.Delta</div>
  9. <div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      '' Save the new object to the database</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      acTrans.Commit()</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">  End Using</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">End Sub</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; "><strong>C#</strong></div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">using Autodesk.AutoCAD.Runtime;</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">using Autodesk.AutoCAD.ApplicationServices;</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">using Autodesk.AutoCAD.DatabaseServices;</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">using Autodesk.AutoCAD.Geometry;</div>
  10. <div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">[CommandMethod("ExtendObject")]</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">public static void ExtendObject()</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">{</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">  // Get the current document and database</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">  Document acDoc = Application.DocumentManager.MdiActiveDocument;</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">  Database acCurDb = acDoc.Database;</div>
  11. <div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">  // Start a transaction</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">  using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">  {</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      // Open the Block table for read</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      BlockTable acBlkTbl;</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId,</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">                                   OpenMode.ForRead) as BlockTable;</div>
  12. <div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      // Open the Block table record Model space for write</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      BlockTableRecord acBlkTblRec;</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      acBlkTblRec = acTrans.GetObject(acBlkTbl[BlockTableRecord.ModelSpace],</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">                                      OpenMode.ForWrite) as BlockTableRecord;</div>
  13. <div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      // Create a line that starts at (4,4,0) and ends at (7,7,0)</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      Line acLine = new Line(new Point3d(4, 4, 0),</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">                             new Point3d(7, 7, 0));</div>
  14. <div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      // Add the new object to the block table record and the transaction</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      acBlkTblRec.AppendEntity(acLine);</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      acTrans.AddNewlyCreatedDBObject(acLine, true);</div>
  15. <div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      // Update the display and diaplay a message box更新显示</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      acDoc.Editor.Regen();</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      Application.ShowAlertDialog("Before extend");</div>
  16. <div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      // Double the length of the line直线延长一倍</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      acLine.EndPoint = acLine.EndPoint + acLine.Delta;</div>
  17. <div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      // Save the new object to the database保存新对象到数据库</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      acTrans.Commit();</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">  }</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">}</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; "><strong>VBA/ActiveX Code Reference</strong></div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">Sub ExtendObject()</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">    ' Define and create the line</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">    Dim lineObj As AcadLine</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">    Dim startPoint(0 To 2) As Double</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">    Dim endPoint(0 To 2)  As Double</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">    startPoint(0) = 4</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">    startPoint(1) = 4</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">    startPoint(2) = 0</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">    endPoint(0) = 7</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">    endPoint(1) = 7</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">    endPoint(2) = 0</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">    Set lineObj = ThisDrawing.ModelSpace. _</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">                                AddLine(startPoint, endPoint)</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">    lineObj.Update</div>
  18. <div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">    ' Double the length of the line</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">    endPoint(0) = lineObj.endPoint(0) + lineObj.Delta(0)</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">    endPoint(1) = lineObj.endPoint(1) + lineObj.Delta(1)</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">    endPoint(2) = lineObj.endPoint(2) + lineObj.Delta(2)</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">    lineObj.endPoint = endPoint</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">    lineObj.Update</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">End Sub</div>
复制代码
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友 微信微信
收藏收藏 转播转播 分享分享 分享淘帖 支持支持 反对反对
工作时间:工作日的9:00-12:00/13:30-18:00,节假日不在线,请勿留言
*滑块验证:
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-9-28 10:21

Powered by Discuz! X3.2 Licensed

© 2001-2013 Comsenz Inc.

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