-
Notifications
You must be signed in to change notification settings - Fork 9
Description
This documents a problem I found during some recent late night code development:
SUTextSetPoint can use three variants of leader types:
SUTextLeaderType_None
SUTextLeaderType_ViewBased
SUTextLeaderType_PushPin
In the following I assume that SUTextLeaderType_None is also a legal type, i.e. I assume that it is allowed to specify this value when using the SUTextSetPoint functionality.
SUTextSetPoint can be used in three ways: point, path and point/path. This report is specificly dealing with the path variant (where one connects to an entity).
The example code below will cause the problem, such that when opening the saved file, SketchUp will report "Something minor is messed up in your model..."
The Validity Checker says:
"Entity CText shoud be erased - done"
In honesty, I cannot say that I do trust the last part of message "done", because a subsequent SketchUp application exit gives a full-featured Bug Splat.
For the record I use:
SDK_WIN_x64_2020-0-363
SketchUp Pro 20.0.373
However, I believe this issue has been present for some time...
#define M_TO_MM(v) (unitConv * v)
std::string outfilename = { "test_ccode_text.skp" };
SUResult su_res;
size_t count;
double unitConv = (1000. / 25.4); // Dimensions in millimeter
SUInitialize();
SUModelRef model = SU_INVALID;
su_res = SUModelCreate(&model);
SUEntitiesRef model_entities = SU_INVALID;
su_res = SUModelGetEntities(model, &model_entities);
SUFontRef myFont;
su_res = SUModelGetNumFonts(model, &count);
if ((su_res == SU_ERROR_NONE) && (count > 0))
{
size_t n;
SUFontRef* pFonts = (SUFontRef*)malloc(count * sizeof(SUFontRef));
if (pFonts != NULL)
{
su_res = SUModelGetFonts(model, count, pFonts, &n);
if ((su_res == SU_ERROR_NONE) && (count == n))
{
for (n = 0; n < count; n++)
{
size_t i, j;
char s[64];
SUStringRef su_string = SU_INVALID;
su_res = SUStringCreate(&su_string);
if (su_res == SU_ERROR_NONE)
{
su_res = SUFontGetFaceName(*(pFonts + n), &su_string);
su_res = SUStringGetUTF8Length(su_string, &i);
su_res = SUStringGetUTF8(su_string, i, s, &j);
su_res = SUStringRelease(&su_string);
}
}
// Use the first font found
myFont = *(pFonts + 0);
}
}
free(pFonts); // FIXME
}
// Guidepoint (will be used as path)
SUPoint3D su_pt_1 = { M_TO_MM(2.0), M_TO_MM(2.0), M_TO_MM(2.0) };
SUGuidePointRef su_gp_1 = SU_INVALID;
su_res = SUGuidePointCreate(&su_gp_1, &su_pt_1);
su_res = SUEntitiesAddGuidePoints(model_entities, 1, &su_gp_1);
// Text to path
SUTextRef su_txt_1 = SU_INVALID;
su_res = SUTextCreate(&su_txt_1);
su_res = SUTextSetFont(su_txt_1, myFont);
su_res = SUTextSetString(su_txt_1, "Txt at path");
// su_res = SUTextSetLeaderType(su_txt_1, SUTextLeaderType_PushPin);
su_res = SUTextSetLeaderType(su_txt_1, SUTextLeaderType_None);
su_res = SUTextSetArrowType(su_txt_1, SUArrowClosed);
SUVector3D su_vec_1 = { M_TO_MM(0.0), M_TO_MM(0.0), M_TO_MM(1.0) };
su_res = SUTextSetLeaderVector(su_txt_1, &su_vec_1);
SUColor su_color_1 = { 0, 255, 0, 255 };
su_res = SUTextSetColor(su_txt_1, &su_color_1);
SUInstancePathRef su_path_1 = SU_INVALID;
su_res = SUInstancePathCreate(&su_path_1);
su_res = SUInstancePathSetLeaf(su_path_1, SUGuidePointToEntity(su_gp_1));
su_res = SUTextSetPoint(su_txt_1, NULL, su_path_1);
su_res = SUEntitiesAddTexts(model_entities, 1, &su_txt_1);
// Save
if (!SUIsInvalid(model)) {
if (outfilename.length() > 0) {
su_res = SUModelSaveToFile(model, outfilename.c_str());
}
su_res = SUModelRelease(&model);
SUSetInvalid(model);
}
SUTerminate();