Example #1
0
        /// <summary>
        /// Perform the 'get' operation.
        /// </summary>
        /// <param name="polyline"></param>
        /// <returns></returns>
        /// <since>6.0</since>
        public Commands.Result Get(out Geometry.Polyline polyline)
        {
            IntPtr ptr_this = NonConstPointer();

            polyline = null;
            using (var points = new SimpleArrayPoint3d())
            {
                IntPtr ptr_points = points.NonConstPointer();
                var    rc         = (Commands.Result)UnsafeNativeMethods.RHC_RhinoGetPolyline2(ptr_this, ptr_points, IntPtr.Zero);
                if (rc == Commands.Result.Success)
                {
                    polyline = new Geometry.Polyline(points.ToArray());
                }
                return(rc);
            }
        }
Example #2
0
        /// <summary>
        /// Searches for locations where the distance from a RhinoObject, in one set of objects,
        /// is less than the specified distance to another RhinoObject in a second set of objects.
        /// This function uses the object's mesh to calculate the interferences.
        /// Acceptable object types include: BrepObject, ExtrusionObject, MeshObject, and SubDObject.
        /// </summary>
        /// <param name="setA">The first set of Rhino objects.</param>
        /// <param name="setB">The second set of Rhino objects.</param>
        /// <param name="distance">The largest distance at which a clash can occur.</param>
        /// <param name="meshType">The type of mesh to be used for the calculation.</param>
        /// <param name="meshingParameters">The meshing parameters used to generate meshes for the calculation.</param>
        /// <returns>An array of mesh interference object if successful, or an empty array on failure.</returns>
        public static MeshInterference[] Search(IEnumerable <RhinoObject> setA, IEnumerable <RhinoObject> setB, double distance, MeshType meshType, MeshingParameters meshingParameters)
        {
            using (var set_a_array = new Runtime.InternalRhinoObjectArray(setA))
                using (var set_b_array = new Runtime.InternalRhinoObjectArray(setB))
                {
                    var ptr_set_a        = set_a_array.NonConstPointer();
                    var ptr_set_b        = set_b_array.NonConstPointer();
                    var ptr_mp           = meshingParameters.ConstPointer();
                    var ptr_clash_events = UnsafeNativeMethods.RhObjectClashEventArray_New(); // new
                    var count            = UnsafeNativeMethods.RHC_CRhClashDetect_TestClash(ptr_set_a, ptr_set_b, distance, (int)meshType, ptr_mp, ptr_clash_events);

                    var rc = new MeshInterference[count];
                    for (var i = 0; i < count; i++)
                    {
                        var index_a        = -1;
                        var index_b        = -1;
                        var hit_points     = new SimpleArrayPoint3d(); // new
                        var ptr_hit_points = hit_points.NonConstPointer();
                        var mi             = new MeshInterference();
                        if (UnsafeNativeMethods.RhObjectClashEventArray_GetAt(ptr_clash_events, i, ref index_a, ref index_b, ptr_hit_points))
                        {
                            mi.IndexA    = index_a;
                            mi.IndexB    = index_b;
                            mi.HitPoints = hit_points.Count > 0 ? hit_points.ToArray() : new Point3d[0];
                        }
                        else
                        {
                            mi.IndexA    = -1;
                            mi.IndexB    = -1;
                            mi.HitPoints = new Point3d[0];
                        }
                        hit_points.Dispose(); // delete
                        rc[i] = mi;
                    }

                    UnsafeNativeMethods.RhObjectClashEventArray_Delete(ptr_clash_events); // delete
                    GC.KeepAlive(setA);
                    GC.KeepAlive(setB);
                    return(rc);
                }
        }