# Drawing a spline

• THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 07/02/2011 at 05:58, xxxxxxxx wrote:

Okay so let's see fi I understand right.   I create the spline the way I did at teh top and because I point a point number in the allocation, that is the number of points I will have in teh spline,   then, I access those points through the points array like listed above?

~Shawn

• THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 07/02/2011 at 06:14, xxxxxxxx wrote:

Yes, that's correct so far. Please check the circle.cpp file of the SDK examples, especially the stuff in the GenerateCircle fucnction.

cheers,
Matthias

• THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 07/02/2011 at 06:34, xxxxxxxx wrote:

cool.. thanks Matthias.  I'll check it out when I get home tonight.,  :)

• THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 07/02/2011 at 10:55, xxxxxxxx wrote:

I looked at the Circle.cpp example. But It's dealing with creating a spline primitive. Not a new spline from scratch. So I'm still not sure how to properly create a spline from scratch.

This code will create a spline for me:
SplineObject *sp = SplineObject::Alloc(3, SPLINETYPE_LINEAR); // create a spline with 3 verts
if(!sp) return NULL;
doc->InsertObject(sp, NULL, NULL, 0); // Add it to the OM

Vector *gp = sp->GetPointW();// The point array of the spline
gp[0] = Vector(0,0,-100);// Place the first point here
gp[1] = Vector(0,0,0);// Place the second point here
gp[2] = Vector(0,0,100);// Place the third point here

But the problem is the spline doesn't show up properly in the view until I physically move the points around a little bit.

In Coffee you have to use this code with the spline class:
var vc = new(VariableChanged);
vc->Init(0,pointcount);
myspline->Message(MSG_POINTS_CHANGED,vc);

So I was wondering if I need to also use this same code in C++ for the splines to draw properly?
I'm having a hard time converting that to a C++ version.

-ScottA

• THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 07/02/2011 at 11:49, xxxxxxxx wrote:

probably because all points are created at world center?  That's just a guess.  I have to get home to see the docs to be sure.

• THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 07/02/2011 at 12:11, xxxxxxxx wrote:

The three vector lines of code place the points so they aren't at the origin. So that's not it.
I'm pretty sure the problem is C4D needs to be told that points have been changed for it to work properly. I just don't know how to write the C++ version of that.

BTW: I'm a Coffee user and new to the whole C++ API thing. But I've learned a lot from your posts. So keep posting those questions and code snippets.

• THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 07/02/2011 at 12:23, xxxxxxxx wrote:

Howdy,

``````sp->Message(MSG_UPDATE);
``````

...after you change the points.

Cactus Dan

• THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 07/02/2011 at 13:10, xxxxxxxx wrote:

@ScottA:
You forgot to set the points back to the SplineObject. I'm just using Coffe, so i can't give you the C++ code, but it should be similiar to what i said in the second post.

``````sp->SetPoints(gp);
``````

Btw: As far as I know, one have to use VariableChanged only when the SplineObject has tags on it like a selectiontag for e.g. which depends on the points of it's Object.

• THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 07/02/2011 at 13:40, xxxxxxxx wrote:

Thanks Dan. That seems to help.
I'm also using Vista64 without Aero enabled. Which causes draw issues in C4D for me.
That was also making the spline look like it wasn't there, when it really was there.

So this whole VariableChanged stuff for splines is only for things with tags on them then?
I just want to make sure I understand how the spline class works.

-ScottA

• THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 07/02/2011 at 13:48, xxxxxxxx wrote:

Howdy,

In C++, there is no SetPoints() function. Calling the GetPointW() function returns a pointer to the points array, giving you direct access to the points.

In the documentation for the MSG_UPDATE:

#### MSG_UPDATE_<_h4_>_

Must be sent if the bounding box has to be recalculated. (Otherwise you can use [MSG_CHANGE](file:///Users/danlibisch/Documentation/%20C4D%20Manuals/R10%20SDK/pages/c4d_baselist/enum_MSG_Atom845.html#msg_change5).)

... since the point's positions have been changed, the bounding box of the spline must be recalculated. I'm not exactly sure but I think some other things get updated, too, when that message is received. In any case, when a point object receives that message it seems to update the point positions.

By the way, an object's points are stored in a hidden variable tag (Tpoint), so every spline and polygon object has that hidden tag on it.

In the C++ documentation, if you go to the C4DAtom class and then to the Message() function of that class, you'll see a list of messages from the MSG_Atom with explanations of their use.

Cactus Dan

• THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 07/02/2011 at 13:59, xxxxxxxx wrote:

Oh, thanks, couldn't imagine it's different in C++, but now i know better. ;)

• THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 07/02/2011 at 14:05, xxxxxxxx wrote:

Howdy,

Yeah, coffee is very similar to c++, but from what I remember about coffee, there were more functions you had to call to perform an operation, where in c++ you simply performed the operation.

Cactus Dan

• THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 07/02/2011 at 16:04, xxxxxxxx wrote:

hey scott would you mind sharing with me the final working code you got.  The4 code above keeps making my c4d crash out.

Thanks,

Shawn

• THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 07/02/2011 at 21:11, xxxxxxxx wrote:

Sure. Here's the code again:

SplineObject *sp = SplineObject::Alloc(3, SPLINETYPE_LINEAR); // create a linear spline with 3 verts
if(!sp) return NULL;
doc->InsertObject(sp, NULL, NULL, 0); // Add it to the OM

Vector *gp = sp->GetPointW();// The point array of the spline
gp[0] = Vector(10,0,-100);// Place the first point here
gp[1] = Vector(0,0,0);// Place the first point here
gp[2] = Vector(-10,0,100);// Place the first point here
sp->Message(MSG_UPDATE);

I'm a little surprised that there's no code block formatting option for this forum. To make posting code snippets easier to read.

-ScottA

• THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 07/02/2011 at 21:30, xxxxxxxx wrote:

why not use [*code] [/*code](without * ) ?

• THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 08/02/2011 at 01:08, xxxxxxxx wrote:

Originally posted by xxxxxxxx

I'm a little surprised that there's no code block formatting option for this forum. To make posting code snippets easier to read.

There is, please check the BBCodes avaible for the forum:
http://www.plugincafe.com/forum/BBcodes.asp

cheers,
Matthias

• THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 08/02/2011 at 01:16, xxxxxxxx wrote:

Originally posted by xxxxxxxx

I looked at the Circle.cpp example. But It's dealing with creating a spline primitive. Not a new spline from scratch. So I'm still not sure how to properly create a spline from scratch

I was refering to this part of the circle.cpp example. It shows how to set up a Bezier spline.

``````
{
#define TANG 0.415

Real    sn,cs;
LONG    i,sub=4;

SplineObject *op = SplineObject::Alloc(sub*2,SPLINETYPE_BEZIER);
if (!op || !op->MakeVariableTag(Tsegment,2)) { blDelete(op); return NULL; }
op->GetDataInstance()->SetBool(SPLINEOBJECT_CLOSED,TRUE);

{
}

{
for (i=0; i<sub; i++)
{
SinCos(2.0*pi*i/Real(sub),sn,cs);

}
}

op->Message(MSG_UPDATE);

return op;
}
``````

op- >Message(MSG_UPDATE) is needed to update the object.

EventAdd() is used to update managers like the Object manager. So only have to call it when you add new objects to the scene for example.

cheers,
Matthias

• THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 08/02/2011 at 03:25, xxxxxxxx wrote:

Thanks Matthias.. That helped a ton.   I've got it figured out now.  :)

• THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 08/02/2011 at 08:13, xxxxxxxx wrote:

Thanks Matthias.

If it's something that you can easily do. Could you possibly add the code block icon to the top of the message creation window with the other icons?

If it's a hassle to enable it. Don't sweat it.

-ScottA

• THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 08/02/2011 at 09:41, xxxxxxxx wrote:

When I type in code examples I usually just type [*code] My Code [*/code] without the * as mentioned above.   :)