Drawing strings in Rhinoceros 6.0


(G Migliorelli) #1

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;
}

(Dale Fugier) #2

Hi @gm_user,

Just curious, since you want to draw text from within a conduit, is there a reason you are making a text object instead of just calling one of the five CRhinoDisplayPipeline::DrawString methods?

– Dale


(G Migliorelli) #3

Hi Dale,
for the specific case DrawString works fine but indeed I was interested in using texts for annotations too,
which underwent remarkable changes in Rhinoceros 6.0.

Thanks!


(Dale Fugier) #4

Hi @gm_user,

Just to be clear, you want to draw CRhinoText objects in a conduit? Or are you just trying to create CRhinoText objects and add them to the document?

Thanks,

– Dale


(G Migliorelli) #5

Within a conduit, if possible, will be more useful to me.

But if this is not advisable, I’ll try and use the code to create objects. I suppose this can make things easier.

Regards