Imports System Imports Autodesk.AutoCAD.DatabaseServices Imports Autodesk.AutoCAD.ApplicationServices Imports Autodesk.AutoCAD.Geometry Imports Autodesk.AutoCAD.Runtime Imports Autodesk.AutoCAD.EditorInput Imports Autodesk.AutoCAD.GraphicsInterface Imports System.Reflection Imports System.Collections Imports System.IO Imports System.Runtime.InteropServices Imports System.Diagnostics Public Class TestEntityJig Class EllipseJig ' using EntityJig Inherits EntityJig Dim mCenterPt, mAxisPt, acquiredPoint As Point3d Dim mNormal, mMajorAxis As Vector3d Dim mRadiusRatio As Double Dim mPromptCounter As Integer Dim m_dims As DynamicDimensionDataCollection Public Sub New(ByVal center As Point3d, ByVal vec As Vector3d) MyBase.new(New Ellipse) mCenterPt = center mNormal = vec mRadiusRatio = 0.00001 mPromptCounter = 0 m_dims = New DynamicDimensionDataCollection() Dim dim1 As Dimension = New AlignedDimension dim1.SetDatabaseDefaults() m_dims.Add(New DynamicDimensionData(dim1, True, True)) Dim dim2 As Dimension = New AlignedDimension dim2.SetDatabaseDefaults() m_dims.Add(New DynamicDimensionData(dim2, True, True)) End Sub Protected Overrides Function Sampler(ByVal prompts As JigPrompts) As SamplerStatus Dim jigOpts As JigPromptOptions = New JigPromptOptions() jigOpts.UserInputControls = (UserInputControls.Accept3dCoordinates Xor UserInputControls.NoZeroResponseAccepted Xor UserInputControls.NoNegativeResponseAccepted) If mPromptCounter = 0 Then jigOpts.Message = vbCrLf & "Ellipse Major axis:" Dim dres As PromptPointResult = prompts.AcquirePoint(jigOpts) Dim axisPointTemp As Point3d = dres.Value If axisPointTemp <> mAxisPt Then mAxisPt = axisPointTemp Else Return SamplerStatus.NoChange End If If dres.Status = PromptStatus.Cancel Then Return SamplerStatus.Cancel Else Return SamplerStatus.OK End If ElseIf mPromptCounter = 1 Then jigOpts.BasePoint = mCenterPt jigOpts.UseBasePoint = True jigOpts.Message = vbCrLf & "Ellipse Minor axis:" Dim radiusRatioTemp As Double = -1 Dim res As PromptPointResult = prompts.AcquirePoint(jigOpts) acquiredPoint = res.Value radiusRatioTemp = mCenterPt.DistanceTo(acquiredPoint) If radiusRatioTemp <> mRadiusRatio Then mRadiusRatio = radiusRatioTemp Else Return SamplerStatus.NoChange End If If (res.Status = PromptStatus.Cancel) Then Return SamplerStatus.Cancel Else Return SamplerStatus.OK End If Else Return SamplerStatus.NoChange End If End Function Protected Overrides Function Update() As Boolean Dim radiusRatio As Double = 1.0 Select Case mPromptCounter Case 0 '// At this time, mAxis contains the value of one '// endpoint of the desired major axis. The '// AcDbEllipse class stores the major axis as the '// vector from the center point to where the axis '// intersects the ellipse path (such as half of the true '// major axis), so we already have what we need. '// mMajorAxis = mAxisPt - mCenterPt Exit Select Case 1 '// Calculate the radius ratio. mRadiusRatio '// currently contains the distance from the ellipse '// center to the current pointer position. This is '// half of the actual minor axis length. Since '// AcDbEllipse stores the major axis vector as the '// vector from the center point to the ellipse curve '// (half the major axis), to get the radius ratio we '// simply divide the value currently in mRadiusRatio '// by the length of the stored major axis vector. '// radiusRatio = mRadiusRatio / mMajorAxis.Length Exit Select End Select Try Dim entity As Ellipse = New Ellipse(mCenterPt, New Vector3d(0, 0, 1), mMajorAxis, radiusRatio, 0.0, 6.2831853071795862) UpdateDimensions() Catch ex As Exception Return False End Try Return True End Function Protected Overrides Function GetDynamicDimensionData(ByVal dimScale As Double) As DynamicDimensionDataCollection Return m_dims End Function Protected Overrides Sub OnDimensionValueChanged(ByVal e As Autodesk.AutoCAD.DatabaseServices.DynamicDimensionChangedEventArgs) End Sub Sub UpdateDimensions() If mPromptCounter = 0 Then Dim myellipse As Ellipse = New Ellipse Dim d As AlignedDimension = m_dims(0).Dimension d.XLine1Point = myellipse.Center d.XLine2Point = mAxisPt d.DimLinePoint = myellipse.Center Else Dim myellipse As Ellipse = New Ellipse Dim dim2 As AlignedDimension = m_dims(1).Dimension dim2.XLine1Point = myellipse.Center dim2.XLine2Point = acquiredPoint dim2.DimLinePoint = myellipse.Center End If End Sub Public Sub setPromptCounter(ByVal i As Integer) mPromptCounter = i End Sub Public Property GetEntity() As Entity Get Return Entity End Get Set(ByVal value As Entity) End Set End Property End Class _ Public Sub DoIt() Dim ed As Editor = Application.DocumentManager.MdiActiveDocument.Editor Dim opts As PromptOptions = New PromptPointOptions("Enter Ellipse Center Point:") Dim res As PromptPointResult = ed.GetPoint(opts) Dim x As Vector3d = Application.DocumentManager.MdiActiveDocument.Database.Ucsxdir Dim y As Vector3d = Application.DocumentManager.MdiActiveDocument.Database.Ucsydir Dim NormalVec As Vector3d = x.CrossProduct(y) Dim db As Database = Application.DocumentManager.MdiActiveDocument.Database Dim tm As Autodesk.AutoCAD.DatabaseServices.TransactionManager = db.TransactionManager '//Create Ellipsejig Dim jig As EllipseJig = New EllipseJig(res.Value, NormalVec.GetNormal()) '//first call drag to get the major axis jig.setPromptCounter(0) Application.DocumentManager.MdiActiveDocument.Editor.Drag(jig) '// Again call drag to get minor axis jig.setPromptCounter(1) Application.DocumentManager.MdiActiveDocument.Editor.Drag(jig) Dim trans As Transaction = tm.StartTransaction Dim bt As BlockTable = trans.GetObject(db.BlockTableId, OpenMode.ForRead, False) Dim btr As BlockTableRecord = trans.GetObject(bt(BlockTableRecord.ModelSpace), OpenMode.ForWrite, False) btr.AppendEntity(jig.GetEntity) trans.AddNewlyCreatedDBObject(jig.GetEntity, True) trans.Commit() trans.Dispose() End Sub End Class