Quantcast
Channel: Rhino Developer - McNeel Forum
Viewing all articles
Browse latest Browse all 8532

Drawing strings in Rhinoceros 6.0

$
0
0

@gm_user wrote:

Hi all,
I followed one sample code of yours to draw strings, replacing my old code as it is reported below. The code is placed correctly within my conduit in the preview but, differently from the old one which worked fine in Rhinoceros, the new code does not draw anything.

Can you help finding the error with it? Thanks in advance,
Giovanna

**//old code (properly working for Rhino 5)**
//text_object->SetTextHeight(0.225*(2.0*(*vertexIt)->actualRadius));
//text_object->SetString(m_quotaString);
//text_object->SetPlane(m_plane);
//vp.SetDrawColor((*vertexIt)->isQuoteVisible?RGB(0,0,0):RGB(75,75,75)); 
// RGB(210,210,210));//text_object->Draw(dp);	

**// new code (unable to draw any string in Rhino 6)**
pTextObj = CreateText(*(RhinoApp().ActiveDoc()), myPoint, myPlane, myString, L"Times New Roman", 0.3*(2.0*(len), 0, 0.0, ON::TextVerticalAlignment::Bottom, ON::TextHorizontalAlignment::Left);

if (nullptr != pTextObj)
{
	vp.SetDrawColor(RGB(75, 75, 75)); 
	// RGB(210,210,210));
	pTextObj->Draw(dp);
	delete pTextObj;
	pTextObj = NULL;
}

where CreateText has been implemented as follows:

CRhinoText* CreateText(CRhinoDoc& doc, const ON_3dPoint& pt, ON_Plane plane, const wchar_t* text, const wchar_t* font_name, double height, int style, double rotate, ON::TextVerticalAlignment valign, ON::TextHorizontalAlignment halign)
{
	CRhinoText* rc = nullptr;

	if (!pt.IsValid() || nullptr == text || 0 == text[0])
		return rc;

	ON_wString face_name(font_name);
	if (face_name.IsEmpty())
		face_name = L"Arial";

	style = RHINO_CLAMP(style, 0, 3);
	const bool bBold = (0 != (style & 1));
	const bool bItalic = (0 != (style & 2));

	// Get a font managed by the application from the font characteristics.
	const ON_Font* font = ON_Font::GetManagedFont(face_name, bBold, bItalic);
	if (nullptr == font)
		return rc;

	height = fabs(height);

	// Get the current dimension style.
	const ON_DimStyle& parent_dimstyle = doc.m_dimstyle_table.CurrentDimStyle();

	// Create a new dimension style from properties.
	ON_DimStyle dim_style = ON_DimStyle::CreateFromProperties(
		parent_dimstyle,
		ON::AnnotationType::Text,
		font,
		ON_UNSET_VALUE,
		height,
		doc.UnitSystem(),
		valign,
		halign
	);

	// Create a new text object
	rc = doc.CreateTextObject(L"text", plane, pt, &dim_style);
	
	return rc;
}

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 8532

Trending Articles