Programmatically set height for linear dimension


I am trying to programmatically create some linear dimensions and I 've got stuck trying to set the size of the font and the arrow heads. Through Rhino’s user interface I do that from
Properties->Property overrides->Text Height and
Properties->Property overrides->Dimension Arrows.

Unfortunately I cannot find a method in the Sdk that allows me to do something equivalent (I am using the Rhino.NET SDK).

The last thing I tried was setting the height via OnLinearDimension::SetHeight method. Here is my code (tries to create a linear dimension along the x-axis given a bounding box) :

using namespace RMA::OpenNURBS;
using namespace RMA::Rhino;

void CalculateXDimension ( IOnBoundingBox^ bbox )
	On3dPoint^ pt000 = gcnew On3dPoint ( bbox->m_min );
	On3dPoint^ pt100 = gcnew On3dPoint ( bbox->m_max->x, bbox->m_min->y, bbox->m_min->z );
	OnPlane^	 plane = gcnew OnPlane ( pt000, gcnew On3dVector ( 0, 0, 1) );

	MRhinoLinearDimension^ dim = gcnew MRhinoLinearDimension ();
	dim->SetPlane ( plane );
	dim->SetPoint ( 0, gcnew On2dPoint(0,0) );

	System::Double u,v;
	plane->ClosestPointTo ( pt100, u, v );
	dim->SetPoint ( 2, gcnew On2dPoint(u,v) );


	// here I am trying to set the height but it doesn't seem to work.
	double textHeight = dim->m_linear_dimension->m_textheight;
	dim->m_linear_dimension->SetHeight ( textHeight*5 );

	RhUtil::RhinoApp()->ActiveDoc()->AddObject ( dim );


I 've tried a few other ways, including creating a dimension style and adding it to the document’s MRhinoDimStyleTable, then assigning by index to the my MRhinoLinearDimensionObject but didn’t work either.

Could you direct me what is the recommended way to achieve what I want? Any help will be greatly appreciated.


Hi Odysseas,

Let me know if this example gives you some guidance.

Just curious, why you writing in mixed mode C++. Looks painful…

Hi Dale,

Thank you very much, that worked!

Regarding C++/CLI, I agree, it’s a bit painful. Originally the purpose was to be able to use some C++ code we have. In practice, it hasn’t happened. And from Rhino we use only the .NET sdk, not the C++ sdk, so I guess we could be using C# instead, but somehow we got used to it :slight_smile:

Btw, here is the code with slight changes in order to use the .NET sdk, just in case anyone finds it useful:

void CalculateXDimension ( IOnBoundingBox^ bbox )
	MRhinoDimStyleTable^ dimStyleTable = RhUtil::RhinoApp()->ActiveDoc()->m_dimstyle_table;
	IRhinoDimStyle^ currentStyle = dimStyleTable->CurrentDimStyle();

	OnDimStyle^ childStyle = gcnew OnDimStyle ( currentStyle );
	System::String^ styleName = System::String::Empty;
	dimStyleTable->GetUnusedDimStyleName ( styleName );
	childStyle->SetName ( styleName );
	childStyle->SetTextHeight ( 12.0 );
	childStyle->SetArrowSize ( 12.0 );
	System::Int32 childStyleIndex = dimStyleTable->AddDimStyle ( childStyle, false );

	MRhinoLinearDimension^ dim = gcnew MRhinoLinearDimension();
	dim->SetStyleIndex ( childStyleIndex );

	// ...

Thanks again!

Calling C++ code from .NET is quite easy when you use Platform Invoke, or PInvoke.

Here is an example:

Hi Dale,

Thanks for sharing that, I 'll have a good look at it as soon as I get some time!