TurboCAD Forums

The Ultimate Resource for TurboCAD Knowledge

Register
 
All posts discussing pricing or where to buy TurboCAD will be deleted.

Bezier Curve - why doesn't this work?
Read 4105 times
* September 13, 2009, 06:16:54 PM
Copy the code below into a Button1_Clicked call back.  I can draw straight lines, but the Bezier curve doesn't work.  The SKK is thin on this - how do you make a curve?

One the cool side, check out how I draw to a dedicated layer, so I can run the script on an existing program but keep the output separated.

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim TCApp As IMSIGX.Application
        Dim TCDraw As IMSIGX.Drawing
        Dim TCGraphics As IMSIGX.Graphics, tmp As IMSIGX.Graphics
        Dim OutputLayer As IMSIGX.Layer
        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("VBOut")
        If OutputLayer Is Nothing Then
            OutputLayer = TCDraw.Layers.Add("VBOut")
        End If
        OutputLayer.Clear()
        ' This works - 3 lines connecting 3 points
        OutputLayer.AddLineSingle(0, 0, 0, 0, 1, 0)
        OutputLayer.AddLineSingle(0, 1, 0, 1, 1, 0)
        OutputLayer.AddLineSingle(1, 1, 0, 1, 0, 0)
        ' This doesn't work
        tmp = OutputLayer.AddCurveBezier(0, 0, 0)
        tmp.addnext(0, 2, 0)
        tmp.addnext(2, 2, 0)
        tmp.addnext(2, 0, 0)
        tmp.finish()
        'This doesn't work either
        OutputLayer.AddCurveBezier(0, 0, 0)
        OutputLayer.addnext(0, 3, 0)
        OutputLayer.addnext(3, 3, 0)
        OutputLayer.addnext(3, 0, 0)
        OutputLayer.finish()

    End Sub

Logged


* September 14, 2009, 01:00:28 PM
#1
Well, it looks like the docs are way out of whack on how to draw a Bezier. One more thing I'll need to fix. :)

Here is a VBScript snippet that works -- should be easily translatable to VB.net. If you get stuck, let me know and I'll get you on track. But basically, you use AddCurveBezier to start the curve, then directly add the subsequent nodes to the graphic's vertices collection.

Dim TCApp
Dim TCDraw
Dim TCGraphic
Dim TCVerts

Set TCApp = GetObject("", "TurboCAD.Application")
Set TCDraw = TCApp.Drawings.Add("")
Set TCGraphic = TCDraw.Graphics.AddCurveBezier(0, 0, 0)
Set TCVerts = TCGraphic.Vertices
TCVerts.Add 0, 3, 0, True '(x, y, z, pendown)
TCVerts.Add 3, 3, 0, True
TCVerts.Add 3, 0, 0, True
TCGraphic.Draw

Logged


* September 15, 2009, 09:53:50 AM
#2
Hey, that worked great, thanks!!! (Except the curve renders so slow I'm sticking to my straight-line approximations)

Logged