In the previous example, we created a cube.
Code: Select all
cb1 = p.CreateCube( 1, 2., 2., 2. )
p.SceneAddObject( cb1, e_tsxFALSE )
p.SceneDraw()
- void tsxGNodeSetLocation(tsxGNODE* pGNode, CtsxVector3f* loc)
Code: Select all
struct CtsxVector3f
{
float x, y, z;
};
Code: Select all
import ptsxpy as p
cb1 = p.CreateCube( 1, 2., 2., 2. )
p.SceneAddObject( cb1, e_tsxFALSE )
vec1 = Vec3f( 3., 4., 5. )
p.GNodeSetLocation( cb1, vec1.p )
p.SceneDraw()
Please don't confuse p.xxxxx with xxxxx.p. The former "p" is an alias name defined freely at the beginning of the script. If you declare it like "import ptsxpy as AAA" instead, then you can write like AAA.CreateCube() in following lines. On the other hand, you cannot replace the ".p" to other word (unless you change the ptsxpydef1.py).
When we mistakenly forget to add ".p" like "p.GNodeSetLocation( cb1, vec1 )", ptsxpy should report an error in the console window and terminate the execution of the script at the line.
As a side note, the reason why the author decided "p" as the standard alias name is that it is the initial of ptsxpy. I used "ptsx" as the alias in the early days of test phase but stopped to use and replace it with "p" because it's too long and disturb reading (make the readability worse).
Of course, you can also write as below if you would like to omit preceding "p." in all lines;
Code: Select all
from ptsxpy import *
cb1 = CreateCube( 1, 2., 2., 2. )
...
Now the cube moved to the specified coordinate (in the air), and tS hold it till it is deleted explicitly. The 12 byte memory area allocated by Vec3f() is freed automatically by its destructor when the class instance becomes a state "not used". For example, the more compact code below seems to be logical but should not work well because the memory area allocated as Vec3f instance might be freed before it is used by tS API;
Code: Select all
### WRONG CODE! Don't write like this!! ###
p.GNodeSetLocation( cb1, Vec3f( 5., 0., 0. ).p ) ### WRONG CODE! ###
Code: Select all
def __del__( self ):
Full list of predefined classes in ptsxpydef1.py file (of ptsxpy version 0.0.10) are;
Code: Select all
Vec3f
Vec2f
Vec3fArray
Axes3f
Txmx3f
BBox3f
WidgetReg
CollisionReport
Quaternion
ViewParam
WDG_CALLBACKS
Color
ColorArray
SurfaceProps
ProTexGranite
ProTexMarble
ProTexWood
TextureProps
BumpProps
Txmx2f
Rect
FaceVx
FaceVxArray
Face
FaceArray
Hole
UV
Edge
EdgeArray
LatticeVector
LatticeFloor
MatRectProps
DerivCurves
SubDivEdge
SubDivEdgeArray
SubDivFace
SubDivFaceArray
PhysEnvir
FloatColor
RenderToFileData
RenderData
Image
TextureFromLightingData
String
CharArray
Float
FloatArray
Double
DoubleArray
Long
LongArray
Ulong
Short
Ushort
IntArray
- Classes named xxxxArray allocate array of xxxx.
- Most classes have corresponding xxxx_p class that is inherited from xxxx class in order to give a type to a C++ pointer (i.e. regard a integer value as a pointer to specific struct) like cast of C/C++. For example, it's convenient in case that an API function fills a pointer in 4 byte memory area specified to its parameter and you use it as a pointer to Vec3f. Please read sample scripts for details.
- The name of most classes completely correspond to struct CtsxXXXX defined in tsxAPIxx.doc and header files, or to C/C++ types like float, long, etc.
- As a few exceptions: Vec3f allocates a struct CtsxVector3f, and Vec2f allocates a struct CtsxVector2f. The reason why the author didn't use "Vector3f" and "Vector2f" as their corresponding class name is; Because they are too long to use frequently.