Results 1 to 2 of 2

Thread: Ellipse - Offseted as Ellipse, not as a spline.

  1. #1
    Active Member harilalmn's Avatar
    Join Date
    2005-03
    Location
    From Kerala, Currently located at Bangalore, India
    Posts
    95
    Login to Give a bone
    0

    Smile Ellipse - Offseted as Ellipse, not as a spline.

    Guys,
    In AutoCAD if you offset an ellipse, the new object formed would be a spline, not an ellipse. I had a project in which I have to offset so many ellipses. It was too sad that I used to get splines instead of ellipse. So, I thought of writing a macro.

    It is working perfectly and thought of sharing it. You will defenitely be able to have better suggestions after seeing the code, as I am not a master in VBA. Please feel free to feedback.

    Here is the code.

    Code:
    Public Sub EllipseOffset()
    On Error Resume Next
    Dim El As AcadEllipse
    Dim NEL As AcadEllipse
    Dim C As Variant
    Dim Center(0 To 2) As Double
    Dim MjAx As Variant
    Dim MiAx As Variant
    Dim MajorAx(0 To 2) As Double
    Dim MinorAx(0 To 2) As Double
    Dim RadRatio As Double
    Dim MajorRad, MinorRad As Double
    Dim En As AcadEntity
    Dim PkPnt As Variant
    Dim Offset As Double
    Dim InOut As String
    Dim kwordList As String
    Dim RepeatMacro As Boolean
    Dim RepNum As Integer
    Dim ConVal As Double
    RepeatMacro = False
    kwordList = "Inside Outside Multiple Repeat"
    Repeat:
    ThisDrawing.Utility.GetEntity En, Pk, "Select Ellipse:"
    If Err Then Exit Sub
    Offset = ThisDrawing.Utility.GetDistance(, "Offset:<" & ConVal & ">")
    If Err Then Err.Clear
    If Offset = 0 Then
    Offset = 1
    Else
    ConVal = Round(Offset, 4)
    End If
    If Offset < 0 Then
    Offset = Offset * -1
    End If
        If TypeOf En Is AcadEllipse Then
            Set El = En
            C = El.Center
            Center(0) = C(0)
            Center(1) = C(1)
            Center(2) = C(2)
            MjAx = El.MajorAxis
            MiAx = El.MinorAxis
            MajorAx(0) = MjAx(0)
            MajorAx(1) = MjAx(1)
            MajorAx(2) = MjAx(2)
            MinorAx(0) = MiAx(0)
            MinorAx(1) = MiAx(1)
            MinorAx(2) = MiAx(2)
            MajorRad = El.MajorRadius
            MinorRad = El.MinorRadius
            RadRatio = El.RadiusRatio
    Break:
            ThisDrawing.Utility.InitializeUserInput 1, kwordList
            If RepeatMacro = False Then
            InOut = ThisDrawing.Utility.GetKeyword("Enter an option (Inside,Outside,Multiple, Repeat): ")
            End If
            
            If RepeatMacro = True Then
            InOut = ThisDrawing.Utility.GetKeyword("Enter an option (Inside,Outside,Multiple): ")
            End If
            
            If InOut = "Repeat" Then
            kwordList = "Inside Outside Multiple"
            RepeatMacro = True
            GoTo Break
            End If
            
            If InOut = "Inside" Then
            Set NEL = ThisDrawing.ModelSpace.AddEllipse(Center, MajorAx, RadRatio)
            NEL.MajorRadius = MajorRad - Offset
            NEL.MinorRadius = MinorRad - Offset
            NEL.RadiusRatio = (MinorRad - Offset) / (MajorRad - Offset)
            End If
            
            If InOut = "Outside" Then
            Set NEL = ThisDrawing.ModelSpace.AddEllipse(Center, MajorAx, RadRatio)
            NEL.MajorRadius = MajorRad + Offset
            NEL.MinorRadius = MinorRad + Offset
            NEL.RadiusRatio = (MinorRad + Offset) / (MajorRad + Offset)
            End If
            
            If InOut = "Multiple" Then
            RepNum = ThisDrawing.Utility.GetInteger("Number of Offsets: ")
            ThisDrawing.Utility.InitializeUserInput 1, kwordList
            InOut = ThisDrawing.Utility.GetKeyword("Enter an option (Inside,Outside): ")
            Set NEL = ThisDrawing.ModelSpace.AddEllipse(Center, MajorAx, RadRatio)
            MjAx = NEL.MajorAxis
            MiAx = NEL.MinorAxis
            MajorAx(0) = MjAx(0)
            MajorAx(1) = MjAx(1)
            MajorAx(2) = MjAx(2)
            MajorRad = NEL.MajorRadius
            MinorRad = NEL.MinorRadius
            RadRatio = NEL.RadiusRatio
            If Not RepNum = 1 Then
                For i = 1 To RepNum
                    If InOut = "Inside" Then
                        Set NEL = ThisDrawing.ModelSpace.AddEllipse(Center, MajorAx, RadRatio)
                        NEL.MajorRadius = MajorRad - Offset
                        NEL.MinorRadius = MinorRad - Offset
                        NEL.RadiusRatio = (MinorRad - Offset) / (MajorRad - Offset)
                            MjAx = NEL.MajorAxis
                            MiAx = NEL.MinorAxis
                            MajorAx(0) = MjAx(0)
                            MajorAx(1) = MjAx(1)
                            MajorAx(2) = MjAx(2)
                            MajorRad = NEL.MajorRadius
                            MinorRad = NEL.MinorRadius
                            RadRatio = NEL.RadiusRatio
                    End If
                    If InOut = "Outside" Then
                        Set NEL = ThisDrawing.ModelSpace.AddEllipse(Center, MajorAx, RadRatio)
                        NEL.MajorRadius = MajorRad + Offset
                        NEL.MinorRadius = MinorRad + Offset
                        NEL.RadiusRatio = (MinorRad + Offset) / (MajorRad + Offset)
                            MjAx = NEL.MajorAxis
                            MiAx = NEL.MinorAxis
                            MajorAx(0) = MjAx(0)
                            MajorAx(1) = MjAx(1)
                            MajorAx(2) = MjAx(2)
                            MajorRad = NEL.MajorRadius
                            MinorRad = NEL.MinorRadius
                            RadRatio = NEL.RadiusRatio
                    End If
                Next
            End If
            End If
            Update
        End If
    If RepeatMacro = True Then
    GoTo Repeat
    End If
    End Sub
    Last edited by RobertB; 2009-06-09 at 03:22 PM. Reason: Added [code] tags

  2. #2
    The Silent Type RobertB's Avatar
    Join Date
    2000-01
    Location
    Seattle WA USA
    Posts
    5,859
    Login to Give a bone
    0

    Default Re: Ellipse - Offseted as Ellipse, not as a spline.

    Please consider the following comments as constructive criticism.

    Your command prompts are formatted incorrectly. Options are supposed to be enclosed in square brackets ([ ]) and separated by forward slashes (/), e.g.:

    "Enter an option [Inside/Outside/Multiple/Repeat]: "

    You also have not provided the default condition. How does the user know what happens if they hit Enter? The default should be part of the option list and also included in angled brackets (< >) after the option list's square brackets.

    The prompts should also display on a new line, e.g. vbCrLf & <string>.

    Using GoTo statements is an indication that the code could use restructuring.
    R. Robert Bell
    Design Technology Manager
    Stantec
    Opinions expressed are mine alone and do not reflect the views of Stantec.

Similar Threads

  1. Ellipse 3d -> 2d
    By clovis in forum AutoLISP
    Replies: 12
    Last Post: 2011-03-18, 10:19 AM
  2. Ellipse
    By vdenis in forum Revit Architecture - Général
    Replies: 16
    Last Post: 2010-05-15, 11:23 AM
  3. A Ellipse
    By clintonc in forum VBA/COM Interop
    Replies: 3
    Last Post: 2007-09-12, 06:41 PM
  4. ellipse
    By glen.85659 in forum Revit Architecture - Wish List
    Replies: 3
    Last Post: 2005-06-25, 03:25 PM
  5. Ellipse
    By Jack Carson in forum Revit Architecture - General
    Replies: 1
    Last Post: 2004-10-26, 08:21 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •