03-04 创建和编辑AutoCAD实体(四) 编辑二维命名对象 (5)

前端之家收集整理的这篇文章主要介绍了03-04 创建和编辑AutoCAD实体(四) 编辑二维命名对象 (5)前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

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")> _

Public Sub ExtendObject()

'' 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 line that starts at (4,4,0) and ends at (7,7,0)

Dim acLine As Line = New Line(New Point3d(4,0),_

New Point3d(7,0))

'' Add the new object to the block table record and the transaction

acBlkTblRec.AppendEntity(acLine)

acTrans.AddNewlyCreatedDBObject(acLine,True)

'' Update the display and diaplay a message Box

acDoc.Editor.Regen()

Application.ShowAlertDialog("Before extend")

'' Double the length of the line

acLine.EndPoint = acLine.EndPoint + acLine.Delta

'' 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("ExtendObject")]

public static void ExtendObject()

{

// 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 line that starts at (4,0)

Line acLine = new Line(new Point3d(4,

new Point3d(7,0));

// Add the new object to the block table record and the transaction

acBlkTblRec.AppendEntity(acLine);

acTrans.AddNewlyCreatedDBObject(acLine,true);

// Update the display and diaplay a message Box更新显示

acDoc.Editor.Regen();

Application.ShowAlertDialog("Before extend");

// Double the length of the line直线延长一倍

acLine.EndPoint = acLine.EndPoint + acLine.Delta;

// Save the new object to the database保存新对象到数据库

acTrans.Commit();

}

}

VBA/ActiveX Code Reference

Sub ExtendObject()

' Define and create the line

Dim lineObj As AcadLine

Dim startPoint(0 To 2) As Double

Dim endPoint(0 To 2) As Double

startPoint(0) = 4

startPoint(1) = 4

startPoint(2) = 0

endPoint(0) = 7

endPoint(1) = 7

endPoint(2) = 0

Set lineObj = ThisDrawing.ModelSpace. _

AddLine(startPoint,endPoint)

lineObj.Update

' Double the length of the line

endPoint(0) = lineObj.endPoint(0) + lineObj.Delta(0)

endPoint(1) = lineObj.endPoint(1) + lineObj.Delta(1)

endPoint(2) = lineObj.endPoint(2) + lineObj.Delta(2)

lineObj.endPoint = endPoint

lineObj.Update

End Sub

原文链接:https://www.f2er.com/vb/261016.html

猜你在找的VB相关文章