Welcome, Guest. Please login or register.
May 16, 2012, 04:33:03 pm
Home Help Search Login Register
News: Remember to do a search before you ask a question!!!

+  TurboCAD Forums
|-+  SDK Corner
| |-+  Contributions
| | |-+  VBA - Draw a Square Spline
« previous next »
Pages: [1] Go Down Print
Author Topic: VBA - Draw a Square Spline  (Read 2140 times)
bern11
Newbie
*
Posts: 3


« on: September 23, 2009, 06:40:10 am »

Check out this routine to draw a square spline.  You need textbox fields for # Teeth, OD, ID, and face angle (0 = square).  Now, anyone know how to make 'Join Polyline' work from VBA so I can join the segments automatically?  Right now I join them manually then extrude.


    Private Sub MakeGearBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MakeGearBtn.Click
        Dim TCApp As IMSIGX.Application
        Dim TCDraw As IMSIGX.Drawing
        Dim TCGraphics As IMSIGX.Graphics
        Dim OutputLayer As IMSIGX.Layer

        Dim iStatus As Integer, i As Integer
        Dim OD As Double, ID As Double, PA As Double, NumTeeth As Double
        Dim l12 As Double
        Dim phi1 As Double, phi2 As Double, dTheta As Double, theta As Double, tmp As Double
        Dim x0 As Double, y0 As Double, x1 As Double, y1 As Double
        Dim x2 As Double, y2 As Double, x3 As Double, y3 As Double


        StatusLbl.Text = "Status:  Drawing Spline"
        On Error Resume Next
        TCApp = GetObject(, "TurboCAD.Application")
        If TCApp Is Nothing Then
            TCApp = CreateObject("TurboCAD.Application")
            If TCApp Is Nothing Then
                StatusLbl.Text = "Status: Cannot Acces TurboCAD"
                Exit Sub
            End If
        End If
        TCApp.Visible = True
        If TCApp.Drawings.Count < 1 Then
            TCDraw = TCApp.Drawings.Add("Drawing1")
            If TCDraw Is Nothing Then
                StatusLbl.Text = "Status: Cannot Create a Drawing"
                Exit Sub
            End If
        Else
            TCDraw = TCApp.ActiveDrawing
        End If
        TCGraphics = TCDraw.Graphics
        OutputLayer = TCDraw.Layers("VBAOut")
        If OutputLayer Is Nothing Then
            OutputLayer = TCDraw.Layers.Add("VBAOut")
        End If
        OutputLayer.Clear()

        OD = ODTbx.Text
        ID = IDTbx.Text
        PA = (180 - PATbx.Text) * Math.PI / 180
        NumTeeth = NumTeethTbx.Text
        dTheta = 2 * Math.PI / NumTeeth

        ' Distance along face
        l12 = ID * Math.Cos(PA) + Math.Sqrt(OD ^ 2 - (ID * Math.Sin(PA)) ^ 2)
        phi1 = Math.Acos((OD ^ 2 + ID ^ 2 - l12 ^ 2) / (2 * OD * ID))
        phi2 = (dTheta - 2 * phi1) / 2

        x0 = 0
        y0 = ID
        theta = 0
        For i = 0 To (NumTeeth - 1)
            x1 = OD * Math.Cos(Math.PI / 2 - (theta + phi1))
            y1 = OD * Math.Sin(Math.PI / 2 - (theta + phi1))
            OutputLayer.AddLineSingle(x0, y0, 0, x1, y1, 0)
            x2 = OD * Math.Cos(Math.PI / 2 - (theta + phi1 + phi2))
            y2 = OD * Math.Sin(Math.PI / 2 - (theta + phi1 + phi2))
            OutputLayer.AddLineSingle(x1, y1, 0, x2, y2, 0)
            x3 = ID * Math.Cos(Math.PI / 2 - (theta + 2 * phi1 + phi2))
            y3 = ID * Math.Sin(Math.PI / 2 - (theta + 2 * phi1 + phi2))
            OutputLayer.AddLineSingle(x2, y2, 0, x3, y3, 0)
            theta = theta + dTheta
            x0 = ID * Math.Cos(Math.PI / 2 - theta)
            y0 = ID * Math.Sin(Math.PI / 2 - theta)
            OutputLayer.AddLineSingle(x3, y3, 0, x0, y0, 0)
        Next

        StatusLbl.Text = "Status: Ready"
    End Sub
Logged
John R
Beta Tester
Royal Member
*****
Posts: 5654


« Reply #1 on: September 23, 2009, 10:51:30 am »

re: ...anyone know how to make 'Join Polyline' work from VBA so I can join the segments automatically?  Right now I join them manually then extrude.

I know nothing about the SDK, but would it not be better to use the "Use Compound Profile" feature in the Simple Extrude tool, rather than the Join Polyline tool? Is "Use Compound Profile" even available, since it's turned Off in certain editions? 

Logged

John R.

V17 Designer, Deluxe, Platinum
V18 Designer, Deluxe, Platinum
V19 Designer, Deluxe, Basic, Platinum
RedSDK enabled
Vista64 SP2
Pages: [1] Go Up Print 
« previous next »
Jump to:  


Login with username, password and session length

Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!
Page created in 0.07 seconds with 17 queries.