TurboCAD Forums

SDK Corner => Sample SDK Projects => SDK General Discussion => Topic started by: MikeCrown on February 10, 2010, 04:00:30 AM

Title: Add Curve Spline
Post by: MikeCrown on February 10, 2010, 04:00:30 AM
Hi Everyone  ;D,
I'm trying to create a vb.net plugin to draw circles depending on data extracted from an excel sheet, however i've hit a bit of a hurdle.

What I'm wanting to do:
 - Create a Curved Spline
 - Add 4 Fit points (not control points), top bottom left right.
 - Close the spline (join the first and last points).

Heres what I have so far:
Code: [Select]
        tcDrawing = tcApp.ActiveDrawing
        tcView = tcDrawing.ActiveView
        tcGraphics = tcDrawing.Graphics
        Dim tcSpline = tcGraphics.AddCurveSpline(0, 10, 0)
        tcVertices = tcSpline.Vertices
        With tcVertices
            .Add(10, 0, 0, True, True)
            .Add(20, 10, 0, True, True)
            .Add(10, 20, 0, True, True)
        End With

What Happens:
This sort of works so long as the .AddClose is commented out, but then obviously the spline isn't closed.
And the vertices seem to be Control points rather than Fit points.

Any help would be greatly appreciated. I've been looking everywhere but cant seem to find any valid documentation.


Mike at Crowns

Title: Re: Add Curve Spline
Post by: ibruethsch on February 11, 2010, 07:01:33 AM
Hi Mike
I used the addcurvespline in a VB-Macro before. I remember it was not reliable, maybe a bug in the SDK.
I tested your example with very odd results.
Dim etc….
        Set tcspline = app.ActiveDrawing.Graphics.AddCurveSpline(0, 0, 0)
        Set tcvertex = tcspline.Vertices.Add(0, 10, 0)
        Set tcvertex = tcspline.Vertices.Add(10, 10, 0)
        Set tcvertex = tcspline.Vertices.Add(10, 0, 0)
        Set tcvertex = tcspline.Vertices.Add(5, -2, 0)
        Set tcvertex = tcspline.Vertices.Add(0, 0, 0)

        Set tcvertex = tcspline.Vertices.AddClose(1, 1, 1)



I add the vertex Endpoint = startpoint. Without that TC crashes.
Run the macro in Debug-modus it does what it should do. After selecting the Spline and moving it it is closed.
Running the macro in the normal Modus, or create an .exe an run that, TC crashes!!


[attachment deleted by admin]
Title: Re: Add Curve Spline
Post by: MikeCrown on February 12, 2010, 05:34:24 AM
Thanks for the reply,
However Im still at a loss as to how to use Splines.
I tried the code above and it drew something, then when I tried to select it (ctrl+a) I got a message saying "object extents are invalid, objects deselected" ???

Does anyone know of some documentation for the SDK?, all I can find is a help file in the SDK folder which  says
"The user must use subsequent Graphic.NextPoint calls to add segments to the Graphic object, and a Graphic.Finish call to complete the Graphic object."
As far as I can tell there arent any methods called NextPoint or Finish!
Title: Re: Add Curve Spline
Post by: kchapman on February 16, 2010, 09:32:37 PM
Hi Mike,

First, I'm sorry, but you can't draw fit-point splines through the SDK. There's not really an underlying fit spline type -- when you draw a "fit-point" spline manually, TurboCAD converts it to a control-point spline behind the scenes; just select it with the Editor tool after you've drawn it and you'll see what I mean.

Now, to draw a closed control-point spline, you're almost there -- you're setting all your points correctly. Just be sure to set the graphic's "SPLINECLOSED" property to 1. Then you won't get the sudden changes in shape after you select the spline.

Here's a VBScript example:
Code: [Select]
'Draws a closed control-point spline'
Dim app
Dim drw
Dim grf
Dim verts
Dim props
Set app = GetObject("", "TurboCAD.Application")
Set drw = app.Drawings.Add
Set grf = drw.Graphics.Add("TCW30Curve", "TCW30Curve")
Set verts = grf.Vertices
Set props = grf.Properties
props.Item("$SPLFRAME").Value = 0 'no visible control frame'
props.Item("$SPLINETYPE").Value = 0 '0=spline, 1=bezier'
props.Item("SPLINECLOSED").Value = 1 ' required if you want the spline to be closed.'
verts.Add 0, 0, 0
verts.Add 10, 0, 0
verts.Add 10, 10, 0
verts.Add 0, 10, 0
Set props = Nothing
Set verts = Nothing
Set grf = Nothing
Set drw = Nothing
Set app = Nothing
Title: Re: Add Curve Spline
Post by: MikeCrown on February 17, 2010, 05:40:08 AM
Thanks for the help, I shall try that code out shortly.
However I've managed to get Beziers working (same as my original code, only replacing AddCurveSpline with AddCurveBezier) so I'm using those now. Probably more appropriate for the shapes I'm making.

Mike at Crowns
Title: Re: Add Curve Spline
Post by: MikeCrown on February 19, 2010, 07:45:46 AM
Thanks for the reply, the code you suggested works well. ;)