Article | 41021141 |
Type | HowTo |
Product | Engine |
Version | 4.x |
Date Added | 6/6/2003 |
Submitted by | Robbert Nieuwerf |
Keywords |
I want to create my own cmdEllipseArc (rubber elliptic arc). How can I make it ?
Check the VB 6.0 code below:
Dim CenterPoint As Variant ' Center point of ellipse Dim SA As Double ' Start angle Dim EA As Double ' End angle Dim Major As Double ' Major axis length Dim Minor As Double ' Minor axis length Dim MajorAngl As Double ' Major axis angle Dim saFlag As Boolean ' Start angle defined flag Dim eaFlag As Boolean ' End angle defined flag Dim flag As Boolean ' In custom "cmdEllipse" loop flag Private Sub Command1_Click() Dim p1 As Variant ' a temporary point Dim MajorP2 As Variant Dim MinorP2 As Variant flag = False saFlag = False eaFlag = False SA = 0 ' set the sa to 0 EA = 2 * 3.1415927 ' set the endangle to 360 VDPro.Prompt "Center of elliptic arc :" CenterPoint = VDPro.Utility.GetPoint If IsEmpty(CenterPoint) Then Exit Sub ' user canceled command VDPro.Prompt "Major axis Length and Angle :" MajorP2 = VDPro.Utility.GetLine(CenterPoint) If IsEmpty(MajorP2) Then Exit Sub ' user canceled command MajorAngl = VDPro.Utility.geomAngle(CenterPoint, MajorP2) Major = VDPro.Utility.geomDistance(CenterPoint, MajorP2) VDPro.Prompt "Minor axis length :" MinorP2 = VDPro.Utility.GetLine(CenterPoint) If IsEmpty(MinorP2) Then Exit Sub ' user canceled command Minor = VDPro.Utility.geomDistance(CenterPoint, MinorP2) flag = True eaFlag = True VDPro.Prompt "Start Angle:" p1 = VDPro.Utility.GetLine(CenterPoint) If IsEmpty(p1) Then Exit Sub ' user canceled command saFlag = True eaFlag = False VDPro.Prompt "End Angle:" p1 = VDPro.Utility.GetLine(CenterPoint) If IsEmpty(p1) Then Exit Sub ' user canceled command eaFlag = True VDPro.Prompt "" Dim myEnt As vdEllipse ' Here the user has entered all information ' for the elliptic arc and this entity is added to the drawing Set myEnt = VDPro.ActiveDocument.Entities.AddEllipse(CenterPoint, Major, Minor) myEnt.EndAngle = EA myEnt.StartAngle = SA myEnt.MajorAngle = MajorAngl myEnt.Update myEnt.Invalidate End Sub Private Sub VDPro_CommandActionDraw(ByVal Render As VDProLib.vdRender, _ ByVal Action As VDProLib.VdConstCmdActions, _ ByVal referencePoint As VDProLib.vdxyz, _ ByVal currentPoint As VDProLib.vdxyz, Cancel As Integer) Dim ent As vdEllipse If flag Then ' the code below is executed only when the custom ellipse is being created Set ent = VDPro.CreateInstance(OBJ_ELLIPSE) ' This ent (elliptic arc) is drawn in the ent.CenterPoint = CenterPoint ' drawing but it is not added to the collection ent.MajorAngle = MajorAngl ent.MajorLength = Major ent.MinorLength = Minor If Not saFlag Then ent.StartAngle = VDPro.Utility.geomAngle(CenterPoint, currentPoint.Value) - MajorAngl SA = ent.StartAngle Else ent.StartAngle = SA End If If Not eaFlag Then ent.EndAngle = VDPro.Utility.geomAngle(CenterPoint, currentPoint.Value) - MajorAngl EA = ent.EndAngle Else ent.EndAngle = EA End If ent.MajorAngle = MajorAngl ent.Update Render.DrawEntity ent End If End Sub