Question

Goal

To create an Ellipse in AutoCAD 2014 with the possibility of rotating it horizontally (as seen in the red rectangle below).

Horizontal Ellipse


Attempt

I was able to create the Ellipse but I cannot seem to find how to rotate it horizontally.

CreateEllipse(AcadDoc)

Public Function CreateEllipse(ByRef AcadDoc As Document) As ObjectId
    Dim returnId As ObjectId
    Dim db As Database = AcadDoc.Database
    Dim x As Vector3d = db.Ucsxdir
    Dim y As Vector3d = db.Ucsydir
    Dim normalVec As Vector3d = x.CrossProduct(y)
    Dim axisvec As Vector3d = normalVec.GetNormal()
    Dim CenterPoint As New Point3d(Me.StartPoint.X + 50, Me.StartPoint.Y + 40, 0)
    Dim aEllipse As New Ellipse(CenterPoint, axisvec, New Vector3d(0, 20, 0), 0.5, 0, Math.PI * 2)

    returnId = Utils.CreateAcadObject(AcadDoc, aEllipse)
    aEllipse.Dispose()
    Utils.regenLayers()

    Return returnId
End Function

Utils.CreateAcadObject(AcadDoc, aEllipse)

Public Function CreateAcadObject(ByRef acDoc As Document, ByRef acObj As Object) As ObjectId
    Dim objId As ObjectId
    Dim acCurDb As Database = acDoc.Database 'Get the current database
    Dim acBlkTbl As BlockTable
    Dim acBlkTblRec As BlockTableRecord

    Using lock As DocumentLock = acDoc.LockDocument
        'Start a transaction
        Using acTrans As Transaction = acCurDb.TransactionManager.StartTransaction()
            'Open Model space for write
            acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId, OpenMode.ForRead)
            acBlkTblRec = acTrans.GetObject(acBlkTbl(BlockTableRecord.ModelSpace), OpenMode.ForWrite)
            acObj.SetDatabaseDefaults()

            'Add the object to the drawing
            objId = acBlkTblRec.AppendEntity(acObj)
            acTrans.AddNewlyCreatedDBObject(acObj, True)

            'Commit the changes and dispose of the transaction
            acTrans.Commit()
        End Using
    End Using

    Return objId
End Function

This is the result I get:

Vertical Ellipse


I'll keep trying to figure it out and I'll post my answer when I end up doing so.

Was it helpful?

Solution

On the line where you create the ellipse:

Dim aEllipse As New Ellipse(CenterPoint, axisvec, New Vector3d(0, 20, 0), 0.5, 0, Math.PI * 2)

You need to change the coordinates of the major axis like this:

Dim aEllipse As New Ellipse(CenterPoint, axisvec, New Vector3d(20, 0, 0), 0.5, 0, Math.PI * 2)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top