How to add ON_Annotation object to rhino

Hi;

const ON_Annotation* annotation = ON_Annotation::Cast(geometry);
			if (nullptr != annotation)
			{
				switch (annotation->Type())
				{
				case ON::AnnotationType::Aligned:
				{
					const ON_DimLinear* linearDim = ON_DimLinear::Cast(annotation);
					if (linearDim != nullptr)
					{
						RhinoApp().Print(L"0\n");
						CRhinoDimLinear* dim = new CRhinoDimLinear();
						dim->SetDimension(linearDim);
						dim->ModifyAttributes(*attribues, true, true);
						context.m_doc.AddObject(dim);
					}
				}
				break;
				case ON::AnnotationType::Rotated:
				{
					const ON_DimLinear* linearDim = ON_DimLinear::Cast(annotation);
					if (linearDim != nullptr)
					{
						RhinoApp().Print(L"1\n");
						CRhinoDimLinear* dim = new CRhinoDimLinear();
						dim->SetDimension(linearDim);
						dim->ModifyAttributes(*attribues, true, true);
						context.m_doc.AddObject(dim);
					}
				}
				break;
				case ON::AnnotationType::Angular:
				{
					const ON_DimAngular* angularDim = ON_DimAngular::Cast(annotation);
					if (angularDim != nullptr)
					{
						RhinoApp().Print(L"2\n");
						CRhinoDimAngular* dim = new CRhinoDimAngular();
						dim->SetDimension(angularDim);
						dim->ModifyAttributes(*attribues, true, true);
						context.m_doc.AddObject(dim);
					}
				}
				break;
				case ON::AnnotationType::Angular3pt:
				{
					const ON_DimAngular* angularDim = ON_DimAngular::Cast(annotation);
					if (angularDim != nullptr)
					{
						RhinoApp().Print(L"3\n");
						CRhinoDimAngular* dim = new CRhinoDimAngular();
						dim->SetDimension(angularDim);
						dim->ModifyAttributes(*attribues, true, true);
						context.m_doc.AddObject(dim);
					}
				}
				break;
				case ON::AnnotationType::Diameter:
				{
					const ON_DimRadial* radialDim = ON_DimRadial::Cast(annotation);
					if (radialDim != nullptr)
					{
						RhinoApp().Print(L"4\n");
						CRhinoDimRadial* dim = new CRhinoDimRadial();
						dim->SetDimension(radialDim);
						dim->ModifyAttributes(*attribues, true, true);
						context.m_doc.AddObject(dim);
					}
				}
				break;
				case ON::AnnotationType::Radius:
				{
					const ON_DimRadial* radialDim = ON_DimRadial::Cast(annotation);
					if (radialDim != nullptr)
					{
						RhinoApp().Print(L"5\n");
						CRhinoDimRadial* dim = new CRhinoDimRadial();
						dim->SetDimension(radialDim);
						dim->ModifyAttributes(*attribues, true, true);
						context.m_doc.AddObject(dim);
					}
				}
				break;
				case ON::AnnotationType::Text:
				{
					const ON_Text* text = ON_Text::Cast(annotation);
					if (text != nullptr)
					{
						RhinoApp().Print(L"6\n");
						ON_Text* mt = const_cast<ON_Text*>(text);
						CRhinoText* dim = new CRhinoText();
						dim->SetTextObject(mt);
						dim->ModifyAttributes(*attribues, true, true);
						context.m_doc.AddObject(dim);
					}
				}
				break;
				case ON::AnnotationType::Leader:
				{
					const ON_Leader* leader = ON_Leader::Cast(annotation);
					if (leader != nullptr)
					{
						RhinoApp().Print(L"7\n");
						CRhinoLeader* dim = new CRhinoLeader();
						dim->SetLeader(*leader);
						dim->ModifyAttributes(*attribues, true, true);
						context.m_doc.AddObject(dim);
					}
				}
				break;
				default:
					RhinoApp().Print(L"Unsupported annotation type.\n");
					break;
				}
			}

in my code, the RhinoApp().Print() funtion is run, but have no object add to rhino, why ?

hi, @suc_kiet i really suggest you to split your code in small parts and isolate your problem by posting the 'breaking point" where the API fail next to a working sample of few lines of code (just to be sure that the problem is surrounded )
if you don’t do that it’s just to cumbersome to start analyzing your code for an issue which might simply not be in your sample code… :expressionless: good luck and i know your pain lol

1 Like

hi,@ Julien Poivret, You are right, finally I have overcome this pain. :joy:

1 Like