I’m having some trouble adding text to an ONX_Model. Whenever I open the saved .3dm in Rhino, the text size is always 0.125 Decimal Inches. It doesn’t matter what I set the text height to on the ON_Text object or ON_DimScale object, it’s always 0.125 Decimal Inches.
Is there a sample anywhere showing the correct way to add text to a ONX_Model?
I’m using openNURBS 7.x. I’ve tried setting the text height on both the ON_Text and ON_DimStyle object, neither produce the result I’m looking for. I suspect I’m not adding the ON_DimStyle to the document correctly or the ID of the ON_DimStyle referenced by the ON_Text is changing after adding.
Here is a snippit of the last thing I tried. Here I’m just using the ID of the DimStyle before adding it to the model. I’ve also tried casting dimRef to a ON_DimStyle to retrieve the ID, but that didn’t work.
ONX_Model = ...;
ON_Text* pText = someText.Duplicate();
// Create the attributes
ON_3dmObjectAttributes *pObjAttribs = someAttributes.Duplicate();
pObjAttribs->SetName(L"some name");
pObjAttribs->SetColorSource(ON::color_from_object);
pObjAttribs->m_color.SetRGB(255, 0, 0);
// Create and add the DimStyle
// ON_DimStyle::DefaultMillimeterSmall fails here for some reason
ON_DimStyle* pTextDimStyle = pText->DimensionStyle(ON_DimStyle::SystemDimstyleFromIndex(-5)).Duplicate();
pTextDimStyle->SetTextHeight(20.0);
ON_ModelComponentReference dimRef = model.AddManagedModelGeometryComponent(pTextDimStyle, nullptr);
// Add the text to the document
pText->SetDimensionStyleId(pTextDimStyle->Id());
ON_ModelComponentReference ref = model.AddManagedModelGeometryComponent(pText, pObjAttribs);
I’m really not sure of the proper way to handle the ON_DimStyles. I’ve never worked with them before. My assumption is this that I need to create a new ON_DimStyle, set the text height, then add it to the ONX_Model. Then I need to get the ID of the newly added DimStyle and use ON_Text::SetDimensionStyleId to set the text ON_DimStyle before adding it to the ONX_Model. Is this correct?
I was able to create some text and a DimStyle and add them to a Rhino document just fine. But for whatever reason, I just can’t get it to work in openNURBS.
Here is an example of how to write text objects to a 3dm file using an ON_Model object. You should be a able to copy this into the openNURBS example_write project.