CRhinoCommand::result CCommandPlugIn2Get::RunCommand( const CRhinoCommandContext& context ) { CRhinoGetObject go; go.SetCommandPrompt( L"Select object" ); go.GetObjects( 1, 1 ); if( go.CommandResult() != success ) return go.CommandResult(); const CRhinoObject* object = go.Object(0).Object(); if( 0 == object ) return failure; ON_3dPoint point; ON_wString string; bool rc = GetPlugInUserData( object, point, string ); if( rc ) { ON_wString pointstr; RhinoFormatPoint( point, pointstr ); RhinoApp().Print( L"point = %s, string = %s\n", pointstr, string ); } else { RhinoApp().Print( L"Failed!\n" ); } return success; }
CRhinoCommand::result CCommandSamplePrintGripLocations::RunCommand( const CRhinoCommandContext& context ) { CRhinoGetObject go; go.SetCommandPrompt( L"Select grips" ); go.SetGeometryFilter( CRhinoGetObject::grip_object ); go.GetObjects( 1, 0 ); if( go.CommandResult() != CRhinoCommand::success ) return go.CommandResult(); const int object_count = go.ObjectCount(); for( int i = 0; i < object_count; i++ ) { const CRhinoGripObject* grip = CRhinoGripObject::Cast( go.Object(i).Object() ); if( grip ) { ON_3dPoint point = grip->GripLocation(); ON_wString point_str; RhinoFormatPoint( point, point_str ); RhinoApp().Print( L"Grip %d = %s\n", i, point_str ); } } return CRhinoCommand::success; }
CRhinoCommand::result CCommandSampleQueryDiameterDimension::RunCommand( const CRhinoCommandContext& context ) { CRhGetDiameterDimensionObject go; go.SetCommandPrompt( L"Select diameter dimension" ); go.SetGeometryFilter( CRhinoGetObject::annotation_object ); go.GetObjects( 1, 1 ); if( go.CommandResult() != CRhinoCommand::success ) return go.CommandResult(); const CRhinoObjRef object_ref = go.Object(0); // Get the Rhino object const CRhinoObject* object = object_ref.Object(); if( 0 == object ) return CRhinoCommand::failure; // The Rhino object class for a diameter dimension is a CRhinoAnnotationObject const CRhinoAnnotationObject* annotation_object = CRhinoAnnotationObject::Cast( object ); if( 0 == annotation_object || annotation_object->Type() != ON::dtDimDiameter ) return CRhinoCommand::failure; // Get the Rhino object's geometry. For CRhinoAnnotationObject, this is a ON_Annotation2 object const ON_Annotation2* annotation = annotation_object->Annotation(); if( 0 == annotation ) return CRhinoCommand::failure; // The geometry for a diameter dimension is a ON_RadialDimension2 object, // which is derived from ON_Annotation2. const ON_RadialDimension2* radial_dim = ON_RadialDimension2::Cast( annotation ); if( 0 == radial_dim ) return CRhinoCommand::failure; // Report some parameters ON_wString point0_str, point1_str; RhinoFormatPoint( radial_dim->Dim3dPoint(0), point0_str ); RhinoFormatPoint( radial_dim->Dim3dPoint(1), point1_str ); RhinoApp().Print( L"Center point: %s\n", point0_str ); RhinoApp().Print( L"Arrowhead point: %s\n", point1_str ); RhinoApp().Print( L"Dimension text: %s\n", annotation_object->TextString() ); return CRhinoCommand::success; }
CRhinoCommand::result CCommandSampleSelectPolylineSegment::RunCommand( const CRhinoCommandContext& context ) { CRhGetPolylineObject go; go.SetCommandPrompt( L"Select polyline" ); go.GetObjects( 1, 1 ); if( go.CommandResult() != CRhinoCommand::success ) return go.CommandResult(); const CRhinoObjRef object_ref = go.Object(0); const CRhinoObject* object = object_ref.Object(); const ON_PolylineCurve* curve = ON_PolylineCurve::Cast( object_ref.Curve() ); if( 0 == object || 0 == curve ) return CRhinoCommand::failure; object->Select( false ); context.m_doc.Redraw(); CRhGetPolylineSegment gp( curve ); gp.SetCommandPrompt( L"Select polyline segment" ); gp.GetPoint(); if( gp.CommandResult() != CRhinoCommand::success ) return gp.CommandResult(); ON_3dPoint point = gp.Point(); int index0 = -1; int index1 = -1; if( gp.CalculatePolylineSegment(point, index0, index1) ) { ON_wString point_str; RhinoFormatPoint( point, point_str ); RhinoApp().Print( L"Curve point = %s\n", point_str ); RhinoApp().Print( L"Curve index0 = %d\n", index0 ); RhinoApp().Print( L"Curve index1 = %d\n", index1 ); } return CRhinoCommand::success; }
CRhinoCommand::result CCommandSamplePickTextDot::RunCommand( const CRhinoCommandContext& context ) { CGetTextDotObject go; go.SetCommandPrompt( L"Select text dots" ); go.GetObjects( 1, 0 ); if( go.CommandResult() != CRhinoCommand::success ) return go.CommandResult(); const int object_count = go.ObjectCount(); int i; for( i = 0; i < object_count; i++ ) { const ON_TextDot* p = ON_TextDot::Cast( go.Object(i).Geometry() ); if( p ) { ON_wString sPoint; RhinoFormatPoint( p->m_point, sPoint ); RhinoApp().Print( L"TextDot%d: point = (%s), text = \"%s\"\n", i, sPoint, p->m_text ); } } return CRhinoCommand::success; }
CRhinoCommand::result CCommandSampleGetPointOnMesh::RunCommand( const CRhinoCommandContext& context ) { // Pick a mesh CRhinoGetObject go; go.SetCommandPrompt( L"Select mesh" ); go.SetGeometryFilter( CRhinoGetObject::mesh_object ); go.GetObjects( 1, 1 ); if( go.CommandResult() != CRhinoCommand::success ) return go.CommandResult(); // Validate the pick const CRhinoMeshObject* mesh_object = CRhinoMeshObject::Cast( go.Object(0).Object() ); if( 0 == mesh_object ) return CRhinoCommand::failure; // Pick a point on the mesh ON_MESH_POINT point; int rc = RhinoGetPointOnMesh( mesh_object, L"Point on mesh", FALSE, point ); if( rc != 0 ) return CRhinoCommand::cancel; // Add the picked point and print results context.m_doc.AddPointObject( point.m_P ); RhinoApp().Print( L"Added point on face %d, with %g, %g, %g, %g as barycentric coordinates.\n", point.m_face_index, point.m_t[0], point.m_t[1], point.m_t[2], point.m_t[3] ); // Was the pick on a face? if( point.m_ci.m_type == ON_COMPONENT_INDEX::mesh_face ) { // Validate mesh if( point.m_mesh ) { ON_3dVector normal = ON_UNSET_POINT; // Does the mesh have face normals? if( point.m_mesh->HasFaceNormals() ) { // Get the face normal ON_3fVector normal = point.m_mesh->m_FN[point.m_ci.m_index]; } else { // Compute the face normal if( point.m_mesh->HasDoublePrecisionVertices() ) point.m_mesh->m_F[point.m_ci.m_index].ComputeFaceNormal( point.m_mesh->DoublePrecisionVertices().Array(), normal ); else point.m_mesh->m_F[point.m_ci.m_index].ComputeFaceNormal( point.m_mesh->m_V.Array(), normal ); } // Validate normal if( normal.IsValid() ) { // Add normal line, with arrow, and print results ON_Line line( point.m_P, point.m_P + normal ); ON_3dmObjectAttributes attributes; context.m_doc.GetDefaultObjectAttributes( attributes ); attributes.m_object_decoration = ON::end_arrowhead; context.m_doc.AddCurveObject( line, &attributes ); context.m_doc.Redraw(); ON_wString normal_str; RhinoFormatPoint( normal, normal_str ); RhinoApp().Print( L"Added line normal to face %d, with % as normal direction.\n", point.m_ci.m_index, normal_str ); } } } return CRhinoCommand::success; }