TurboCAD Forums

The Ultimate Resource for TurboCAD Knowledge

Register
 
Be sure your post is relevant to the current discussion.  Create a new topic within the appropriate board if you are unsure.

VBA reference available ?
Read 3038 times
* October 27, 2014, 03:58:35 PM
Hi there,

I'm using turbocad V10 and want to create some 3D objects (gears at the moment). I've looked at the createGear macro in the SDK but I'm lost when I try to modify it for my purposes as I can't find any documentation for the objects

eg

***
Dim ActDr As Drawing
Dim Grs As Graphics
Dim grfThis As Graphic
Dim Vers As Vertices
Dim Ver As Vertex
Dim grChild As Graphic
    Set App = IMSIGX.Application
    Set ActDr = App.ActiveDrawing
Dim Space%
    Space = ActDr.Properties("TileMode")
    If Space <> 1 Then
        MsgBox ("This macros works only in Modal Space")
        Exit Sub
    End If
    Set Grs = ActDr.Graphics
    Set grfThis = Grs.Add(7)
Dim Pi#
    Pi = 3.14159265
Dim X0#, Y0#, Z0#
    X0 = 5#
    Y0 = 5#
    Z0 = 0#
    frmGear.Show
.
.
***

What does '7' mean in
   Set grfThis = Grs.Add(7) ?

obviously a type of object , but where can I find a description of what number I should use for an "Irregular polygon" ?

I've searched the net without result for a description of the relevant types, can anyone help ?

thanks
Steve

Logged


* October 28, 2014, 06:27:06 AM
#1
Hello Steve
Use the tcsdk.chm which used to be in the sdk-folder.
Try a chm2doc converter cause there is no search function in this old chm

Creating Graphics of Different Types
The Graphics and some of the other collections allow you to create Graphic objects of different types.  Each of the basic Graphic subtypes in TurboCAD has one or more "shortcut" methods exposed by the Graphics collection.  Each method lets you specify the resulting geometry in different ways.  For example you can create a circle by specifying its center and radius, by two points on its diameter, etc.  In addition the more general Graphics.Add method lets you create an "empty" graphic of an arbitrary subtype and then modify its vertex coordinates and child graphics after it has been created.
Examples for a few common Graphics.AddXXX methods:
Dim gr1 As IMSIGX.Graphic
Set gr1 = drw.Graphics.AddLineSingle(5, 5, 0, 5, 10, 0)


Dim gr2 As IMSIGX.Graphic
Set gr2 = drw.Graphics.AddLineRectangle(5, 5, 0, 15, 10, 0)


Dim verts As IMSIGX.Vertices
Dim gr3 As IMSIGX.Graphic
Set gr3 = drw.Graphics.AddLineIrregularPolygon(10, 5, 0)
Set verts = gr3.Vertices
verts.Add 10, 15, 0
verts.Add 15, 15, 0
verts.Add 15, 20, 0
verts.Add 5, 20, 0
verts.Add 5, 5, 0
verts.AddClose

----------------------------------------

In case I´m not sure which is a right syntax I use the macro recorder. Normally a pretty useless thing within TC but you can record what you click.
N this case
For Polyline: Start "Insert|Line|Polyline"
For irregularPolygon: Start "Insert|Line|IrregularPolygon"

That is not the Syntax you can directly use within VBA, but it is very close to it.

--------------------------------

The newer versions have more .chm – files in the sdk-folder
This is from the
IMSIGXReference.chm  (.chm with search function)

ImsiPolyType enum
Send Feedback


Enumerated values for AddPolys.
 Syntax
Visual Basic (Declaration)
Enum ImsiPolyType
'Usage example
Dim value as ImsiPolyType = ImsiPolyType.imsiPointList
Visual C++
enum ImsiPolyType;
//Usage example
ImsiPolyType value = ImsiPolyType.imsiPointList;
 Members
   Member name   Member value   Description
   imsiPointList   0   Points describes 1 polyline. Result polyline is open.
   imsiLineList   1   Points is a Line List (each pair of points describes a polyline). Result polyline is open.
   imsiLineStrip   2   Points is a Line Strip (describes 1 polyline). Result polyline is open.
   imsiTriangleList   3   Points describe Triangles List (each 3 points describe a polyline). Result polyline is closed.
   imsiTriangleStrip   4   Points describe Trianges Strip (Triangle has two last points from previous one + next point from list). Result polyline is closed.
   imsiTriangleFan   5   Points describe Trianges Strip (Triangle has two last points from previous one + next point from list. The last triangle uses points of the first triangle). Result polyline is closed.
   imsiQuadList   6   Points describe Quadrants List (each 4 points describe a polyline). Result polyline is closed.
   imsiIrregPolygon   7   Points describe a irregular polygon. Result polyline is closed.

To get this on your system simply install a new Demoversion.

Regards
Bernd



Logged


* October 28, 2014, 12:36:53 PM
#2
Thanks Bernd,

I found the tcsdk.chm file which I installed a long time ago and forgot about. I'll look for the other files you mentioned.

I think I'm on the right path now.

Steve

Logged


* October 29, 2014, 01:39:16 AM
#3
Hi all,

My task is to use VBA to create a crown gear wheel as a solid object.

The code below (Crown_Gear called by Test_Crown_Gear creates an irregular polygon with a series of vertexes which is inserted in the drawing, but does not appear when quality rendering is used, so is not a solid.

How do I convert this set of vertices into a solid object , preferably in code ?

Thanks

Steve

 ************************
'////////////////////////////////////////
'// Crown gear
'////////////////////////////////////////

Public Sub Crown_gear(xc As Double, yc As Double, zc As Double, outer_radius As Double, inner_radius As Double, tooth_height As Double, n_teeth As Integer)


  Dim angleStep As Double, i As Double, rads As Double
  Dim app As Application
  Dim ActDr As Drawing
  Dim Grs As Graphics
  Dim grfThis As Graphic
  Dim Vers As Vertices
  Dim Ver As Vertex

  Set app = GetObject("", "TurboCAD.Application")

  Set ActDr = app.ActiveDrawing

  Set Grs = ActDr.Graphics
  Set grfThis = Grs.Add("TCW60ACISSOLID")
  Dim grChild  As IMSIGX.Graphic
  Set grChild = Grs.AddLineIrregularPolygon(xc, yc, zc)
   
 
  Set Vers = grChild.Vertices
  angleStep = Pi * 2 / n_teeth
 
  Dim vArray(9, 2) As Double ' Vertex x,y,z values
  Dim AddOrder
  AddOrder = Array(0, 1, 2, 3, 0, 1, 8, 9, 0, 1, 8, 7, 2, 3, 6, 7, 8, 9, 6, 5, 4, 3, 6, 5, 4)
 
   
  For i = 0 To Pi * 2 Step angleStep
 
    rads = i
    vArray(0, 0) = xc + inner_radius * Cos(rads) ' x Value of vertex 0
    vArray(0, 1) = yc + inner_radius * Sin(rads) ' y value of vertex 0
    vArray(0, 2) = zc ' z Value of vertex 0
 
    vArray(1, 0) = xc + inner_radius * Cos(rads + angleStep * 3 / 16) ' x Value of vertex 1
    vArray(1, 1) = yc + inner_radius * Sin(rads + angleStep * 3 / 16) ' y value of vertex 1
    vArray(1, 2) = zc + tooth_height ' z Value of vertex 1
   
    vArray(2, 0) = xc + inner_radius * Cos(rads + angleStep * 9 / 16) ' x Value of vertex 2
    vArray(2, 1) = yc + inner_radius * Sin(rads + angleStep * 9 / 16) ' y value of vertex 2
    vArray(2, 2) = zc + tooth_height ' z Value of vertex 2
   
    vArray(3, 0) = xc + inner_radius * Cos(rads + angleStep * 3 / 4) ' x Value of vertex 3
    vArray(3, 1) = yc + inner_radius * Sin(rads + angleStep * 3 / 4) ' y value of vertex 3
    vArray(3, 2) = zc ' z Value of vertex 3
   
    vArray(4, 0) = xc + inner_radius * Cos(rads + angleStep) ' x Value of vertex 4
    vArray(4, 1) = yc + inner_radius * Sin(rads + angleStep) ' y value of vertex 4
    vArray(4, 2) = zc ' z Value of vertex 4
   
    vArray(5, 0) = xc + outer_radius * Cos(rads + angleStep) ' x Value of vertex 5
    vArray(5, 1) = yc + outer_radius * Sin(rads + angleStep) ' y value of vertex 5
    vArray(5, 2) = zc ' z Value of vertex 5
   
    vArray(6, 0) = xc + outer_radius * Cos(rads + angleStep * 3 / 4) ' x Value of vertex 6
    vArray(6, 1) = yc + outer_radius * Sin(rads + angleStep * 3 / 4) ' y value of vertex 6
    vArray(6, 2) = zc ' z Value of vertex 6
   
    vArray(7, 0) = xc + outer_radius * Cos(rads + angleStep * 9 / 16) ' x Value of vertex 6
    vArray(7, 1) = yc + outer_radius * Sin(rads + angleStep * 9 / 16) ' y value of vertex 6
    vArray(7, 2) = zc + tooth_height ' z Value of vertex 6
           
    vArray(8, 0) = xc + outer_radius * Cos(rads + angleStep * 3 / 16) ' x Value of vertex 0
    vArray(8, 1) = yc + outer_radius * Sin(rads + angleStep * 3 / 16) ' y value of vertex 0
    vArray(8, 2) = zc + tooth_height ' z Value of vertex 0
             
    vArray(9, 0) = xc + outer_radius * Cos(rads) ' x Value of vertex 0
    vArray(9, 1) = yc + outer_radius * Sin(rads) ' y value of vertex 0
    vArray(9, 2) = zc  ' z Value of vertex 0
                       
    ' Add the vertices to the polygon

    For j = 0 To UBound(AddOrder)
      Set Ver = Vers.Add(vArray(AddOrder(j), 0), vArray(AddOrder(j), 1), vArray(AddOrder(j), 2))
    Next j
   
   Next i
   
   Vers.AddClose
   grChild.Closed = True
   
   Set grfThis = Nothing
   Set app = Nothing
   Set ActDr = Nothing
   Set Grs = Nothing
   Set Vers = Nothing
   Set Ver = Nothing
   Set grChild = Nothing
   
   Debug.Print "Crown gear created"
   
End Sub

'////////////////////////////////////////////////////
Public Sub Test_Crown_Gear()
 
  Crown_gear 50, 50, 0, 15, 10, 3, 15
End Sub

'///////////////////////////////////////////////////

*********************************************

Logged


* November 08, 2014, 07:02:42 AM
#4
Hello Steve
I tried your code .
I had to substitute "Pi" with 3.14...
Here the same : only a Graphic Type Polyline  appear.
Maybe it has to do with the child graphic.

I found in the helpfile:
Using 3D Box Graphics (Regen)
Box Graphic Details
Part   Description
Type   TCW40CUBE
RegenType   (not available)
Normal Flags   Editable, Visible
Subtype Extended Properties   (none)
A box graphic is defined by exactly 4 vertices:
Box Graphic Vertices
Vertex Index   Description
0   Flags: PenUp, Linkable, Snappable, Selectable
X, Y, Z: Origin of box (one corner)
Bulge: False
1   Flags: PenUp, Linkable, Snappable, Selectable
X, Y, Z: First axis of box base
Bulge: False
2   Flags: PenUp, Linkable, Snappable, Selectable
X, Y, Z: Second axis of box base
Bulge: False
3   Flags: PenUp, Linkable, Snappable, Selectable
X, Y, Z: Third axis of box (Z axis)
Bulge: False
A box graphic has two direct child graphics, a DATA graphic that holds the box properties, and a TCW60ACISSOLID cosmetic graphic:
Box ACIS Solid Cosmetic Child Graphic
Part   Description
Type   TCW60ACISSOLID
RegenType   (not available)
Normal Flags   Cosmetic, Editable, Visible
Subtype Extended Properties   (none)
The ACIS Solid has no vertices itself, but has two children (grandchildren of the original box graphic): a DATA graphic that holds ACIS information and a SURFACE cosmetic graphic:
Box ACIS Solid Surface Cosmetic Child Graphic
Part   Description
Type   SURFACE
RegenType   (not available)
Normal Flags   Builtin, Cosmetic, Editable, Visible
Subtype Extended Properties   (none)
The surface has 24 vertices that describe the faces of the box:
Box ACIS Solid Surface Cosmetic Child Vertices
Vertex Index   Description
0 to 23   Flags: PenDown, Editable, Linkable, Snappable, Selectable
X, Y, Z: Vertex of box face.  Coordinates are defined relative to the center of the box.
Bulge: False

Maybe Tom Snapes macro can help you.
Description:

This shows how to add one box to the drawing, then add a second, smaller box. Then the smaller box is subtracted from the first to create a mortise.
http://www.bcitool.com/TCDRC/Pages/Page_00092.htm


regards
Bernd

Logged


* November 10, 2014, 01:15:02 PM
#5
Thanks Berndt,

I found a few of Tom Snape's macros which have given me some ideas (at least I think they are Tom's) at

http://throsn.tripod.com/downloads.html

And I thank him for those (Prisms and Lofts seems to be the most useful)

Hope they can help others struggling in this area.

Steve

Logged