TurboCAD: Getting started with VBS first created 10/10/05 - last modified 15/10/05 Page Author: Ty Harness
IMSI have dropped VBA for TurboCAD in version 11 but VBS is left in its place to enable users to programmatically take control of TurboCAD.

This page will help show you how to begin using VBS with the TurboCAD application.

Firstly let's learn how to run the demo files.
  • Open TurboCAD
    and select the Internet palette and type the full path to your sample scripts folder:
    For TC10.51Pro its (drive):\Program Files\IMSI\TCWP105\SDK\Samples\VBS\WshScriptPack
    text here
    Figure 1 - The TurboCAD Internet Palette
    You should then see the test VBS files
    text here
    Figure 2 - Linking to a local directory
    and double left click on (say) TurboCAD test2.vbs
    text here
    Figure 3 - Double Left Button click to run a script

    And that's all there is to running a VBS file. This is simpler than running a VBA macro and you can point the Internet palette address to a network address where all the CAD personnel of your company can use the same script. You could even make a web page for the palette which might include other useful project information. It could be a good way of keeping the whole team updated.

    One of the drawbacks to VBS are the lack of Userforms (Modal forms) to VBA. Yes, you can call Msgbox and Inputbox but sometimes you may need a more complex dialog. One technique you could use is to write a web page with dhtml forms which have buttons,memo fields etc. There's a list of pros and cons below in table 1.






    VBS ProsVBS Cons
    Simple execution from TC Internet paletteSlow interpretation and execution
    Can be integrated into DHTML web formNo User Forms
    Familiar VB languageUser defined Types not available
    Plenty of Examples of how to use TC objects Some VB Keywords missing
    Free alternative to VBA No Editor/Debugger
    Table 1

    Another drawback with VBS compared with VBA is there is no editor - although it's not strictly a problem with VBS. You can use any text editor and like all the VB variations CR&LF separates the lines of source code instead of any other delimiter like the semicolon of C or Pascal.

    There are plenty of editors out-there MS Visual InterDev, AberSoft VbsEdit which both have intelli code and debugging. The free ones are just generally coloured syntax. If you are into programming there are some good examples out-there showing how to parse rich text. VBS documentation can be found at Microsoft MSDN
    text here
    Figure 4 - My own VBS editor

    For my first VBS file I'm going to convert one of my favorite VBA macros and test any speed difference in execution.
    text here
    Figure 5- Parabola Segments Macro Screen Shot
    The VBA code can be found on the Parabola Segments web page. The VBS code is shown below. The main difference is of how the TC application object must be stored as a variant, and the lack of user defined data types has forced me to use arrays and variants which is OK but UDTs are second nature for any VB, C, Delphi programmers these days.
    You'll need to copy and paste the vbs code below into a text editor and save it with a .vbs file extension. Use the Internet palette in TC and find the directory of the vbs file then just double click to run the code.
    The parabola segments simply draws lines and changes the info property and also adds text. One coordinate is calculated with trig functions sin and cos. The algorithm is timed after the the user has accepted the grid size and angle parameters. It's simply timed using the Now function to the nearest second.
    Grid Size Speed Test VBA vs VBS vs Pascal
    VBA VBS Pascal
    12<17NA
    24<115NA
    36<120NA
    48<122NA
    64<136NA
    128<166NA
    2561150NA
    5122342NA
    10246NTNA
    204810NTNA
    409621NTNA
    819243NTNA
    1638490NTNA
    Table 2 - Speed Test results - NT - Not Tested / NA - Not Available yet
    {As soon as I get the test results from the Pascal Script Engine I'll update the table}

    Conclusion
    As a whole I do think allowing the VBS scripting engine to connect to the TC application is a good idea. It's an ideal way to begin to take programmatic control of CAD. Take the above example which has a grid size of 512, and that means 1024 lines and 1024 items of text drawn in couple of mins - you can't draft that quick manually. The only downside is once you've become competent with the VBS - you'll need to make a massive leap to VB.net SDK - Good luck.
    '''''''''''''''''''''''''TyVBSTest.vbs''''''''''''''''''''''''''

    'TC globals
    Dim tcApp
    Dim tcDwgs
    Dim tcDwg
    Dim tcGrs
    Dim tcVw

    'Konstants
    Private Const PI = 3.1415927
    Private Const degtorad = 0.0174532



    'main code here************************************************
    Set tcApp = CreateObject("TurboCAD.Application")

    Set tcDwgs = tcApp.Drawings
    if (tcDwgs.Count > 0 ) then

    Set tcDwg = tcApp.ActiveDrawing
    Set tcVw = tcDwg.ActiveView
    Set tcGrs = tcDwg.Graphics

    t1 = now
    drawParbolaSegements
    tcVw.ZoomToExtents
    t2 = now
    end if

    MsgBox t1 & " " & t2 & " " & datediff("s",t1,t2)
    'MsgBox "Done"

    Set tcDwg = Nothing
    Set tcVw = Nothing
    Set tcGrs = Nothing
    Set tcDwgs = Nothing
    Set tcApp = Nothing
    '******************************************************************




    Sub drawParbolaSegements()
    dim x,y
    dim R
    dim Theta
    dim i

    n = InputBox("Number of units to evaluate", , 12 )
    Theta = InputBox("Angle of axes", , 60 )
    Theta =Theta*degtorad

    for i = 0 to n
    R = n - i
    x = R*cos(Theta)
    y = R*sin(Theta)

    set L = tcGrs.addlinesingle(i, 0 , 0 , x, y, 0 )
    L.Properties("Info").Value = i
    tcGrs.AddText i, i, - 1 , 0 , 0.4
    tcGrs.AddText i, x- 1 , y, 0 , 0.4
    next


    End sub



    [Home] [Mechanics] [Welding] [Software] [CAD] [Math]

    Tested in Firefox 1.07: FireFox homepage