public RhinoObject[] GetSelectedObjects(ObjectType filter) { var page_pointer = RhinoPageHooks.UnmanagedIRhinoPagePointerFromPage(this); var object_count = 0; var array_pointer = UnsafeNativeMethods.IRhinoPropertiesPanelPage_GetObjects(page_pointer, (uint)filter, ref object_count); var rc = new List <RhinoObject>(); for (var i = 0; i < object_count; i++) { var pointer = UnsafeNativeMethods.IRhinoPropertiesPanelPage_GetObjectsAt(array_pointer, i); if (pointer == IntPtr.Zero) { continue; } var rhino_object = RhinoObject.CreateRhinoObjectHelper(pointer); if (rhino_object != null) { rc.Add(rhino_object); } } UnsafeNativeMethods.IRhinoPropertiesPanelPage_GetObjectsClear(array_pointer); return(rc.ToArray()); }
/// <summary> /// Get selected objects of a given type /// </summary> /// <typeparam name="T"></typeparam> /// <returns></returns> public T[] GetObjects <T>() where T : RhinoObject { var type = typeof(T); var filter = TypeFilter(type); var page_pointer = RhinoPageHooks.UnmanagedIRhinoPagePointerFromPage(Page); var object_count = 0; var array_pointer = UnsafeNativeMethods.IRhinoPropertiesPanelPage_GetObjects(page_pointer, (uint)filter, ref object_count); var rc = new List <T>(); for (var i = 0; i < object_count; i++) { var pointer = UnsafeNativeMethods.IRhinoPropertiesPanelPage_GetObjectsAt(array_pointer, i); if (pointer == IntPtr.Zero) { continue; } var rhino_object = RhinoObject.CreateRhinoObjectHelper(pointer) as T; if (rhino_object != null) { rc.Add(rhino_object); } } UnsafeNativeMethods.IRhinoPropertiesPanelPage_GetObjectsClear(array_pointer); return(rc.ToArray()); }
/// <summary> /// Return true if any of the selected objects match the given type /// </summary> /// <typeparam name="T"></typeparam> /// <param name="allMustMatch"> /// If true then every selected object must match the object type /// otherwise; only a single object has to be of the specified type /// </param> /// <returns></returns> public bool AnySelectedObject <T>(bool allMustMatch) where T : RhinoObject { var type = typeof(T); var filter = allMustMatch ? ObjectType.AnyObject : TypeFilter(type); var page_pointer = RhinoPageHooks.UnmanagedIRhinoPagePointerFromPage(this); var count = 0; var array_pointer = UnsafeNativeMethods.IRhinoPropertiesPanelPage_GetObjects(page_pointer, (uint)filter, ref count); for (var i = 0; i < count; i++) { var pointer = UnsafeNativeMethods.IRhinoPropertiesPanelPage_GetObjectsAt(array_pointer, i); if (pointer == IntPtr.Zero) { continue; } var obj = RhinoObject.CreateRhinoObjectHelper(pointer) as T; // If all objects must match and this object does not then return false if (allMustMatch && obj == null) { return(false); } // No requirement for all objects to match and this one does then just return true now if (!allMustMatch && obj != null) { return(true); } } return(allMustMatch && count > 0); }
/// <summary> /// Gets an array with the objects that belong to this instance definition. /// </summary> /// <returns>An array of Rhino objects. The returned array can be empty, but not null.</returns> /// <example> /// <code source='examples\vbnet\ex_instancedefinitionobjects.vb' lang='vbnet'/> /// <code source='examples\cs\ex_instancedefinitionobjects.cs' lang='cs'/> /// <code source='examples\py\ex_instancedefinitionobjects.py' lang='py'/> /// </example> public RhinoObject[] GetObjects() { int count = ObjectCount; RhinoObject[] rc = new RhinoObject[count]; for (int i = 0; i < count; i++) { IntPtr ptr = UnsafeNativeMethods.CRhinoInstanceDefinition_Object(m_doc.m_docId, m_index, i); rc[i] = RhinoObject.CreateRhinoObjectHelper(ptr); } return(rc); }
private static void CRhinoGripsEnabler_TurnOnGrips(IntPtr pRhinoObject, Guid enabler_id) { TurnOnGripsEventHandler handler; if (m_registered_enablers.TryGetValue(enabler_id, out handler)) { RhinoObject rhobj = RhinoObject.CreateRhinoObjectHelper(pRhinoObject); if (rhobj != null) { handler(rhobj); } } }
static private int OnWillBuild(int serialNumber, IntPtr pViewport, IntPtr pObject, Guid plugInId, int type) { try { var p = FromSerialNumber(serialNumber); if (p != null) { return(p.WillBuildCustomMeshes(new ViewportInfo(pViewport), RhinoObject.CreateRhinoObjectHelper(pObject), plugInId, type == 1) ? 1 : 0); } } catch (Exception ex) { Runtime.HostUtils.ExceptionReport(ex); } return(0); }
private static bool CustomGeometryFilter(IntPtr rhObject, IntPtr ptrGeometry, ComponentIndex componentIndex) { bool rc = true; if (g_active_go != null) { try { RhinoObject rh_object = RhinoObject.CreateRhinoObjectHelper(rhObject); GeometryBase geom = GeometryBase.CreateGeometryHelper(ptrGeometry, rh_object); rc = g_active_go.CustomGeometryFilter(rh_object, geom, componentIndex); } catch (Exception ex) { Runtime.HostUtils.ExceptionReport(ex); } } return(rc); }
static int OnBBox(int serialNumber, IntPtr pViewport, IntPtr pObject, Guid plugInId, int type, ref Point3d min, ref Point3d max) { try { var provider = FromSerialNumber(serialNumber); if (provider != null) { var bbox = provider.BoundingBox(new ViewportInfo(pViewport), RhinoObject.CreateRhinoObjectHelper(pObject), plugInId, type == 1); min = bbox.Min; max = bbox.Max; return(1); } } catch (Exception ex) { Runtime.HostUtils.ExceptionReport(ex); } return(0); }
/// <summary> /// Gets access to the internal GripOwner array of the TransformObjectList object. /// </summary> /// <returns>A /// n array of Rhino objects that are the owners of the grip objects the collection, /// or an empty array if there were no Rhino objects. /// </returns> /// <since>6.0</since> public RhinoObject[] GripOwnerArray() { int count = GripOwnerCount; if (count < 1) { return(new RhinoObject[0]); } RhinoObject[] rc = new RhinoObject[count]; IntPtr const_ptr_this = ConstPointer(); for (var i = 0; i < count; i++) { var ptr_grip_owner = UnsafeNativeMethods.CRhinoXformObjectList_GetGripOwner(const_ptr_this, i); rc[i] = RhinoObject.CreateRhinoObjectHelper(ptr_grip_owner); } return(rc); }
/// <summary> /// Explodes the instance reference into pieces. /// </summary> /// <param name="explodeNestedInstances"> /// If true, then nested instance references are recursively exploded into pieces /// until actual geometry is found. If false, an InstanceObject is added to /// the pieces out parameter when this InstanceObject has nested references. /// </param> /// <param name="pieces">An array of Rhino objects will be assigned to this out parameter during this call.</param> /// <param name="pieceAttributes">An array of object attributes will be assigned to this out parameter during this call.</param> /// <param name="pieceTransforms">An array of the previously applied transform matrices will be assigned to this out parameter during this call.</param> public void Explode(bool explodeNestedInstances, out RhinoObject[] pieces, out ObjectAttributes[] pieceAttributes, out Transform[] pieceTransforms) { IntPtr pConstThis = ConstPointer(); IntPtr pPieceList = UnsafeNativeMethods.CRhinoInstanceObject_Explode(pConstThis, explodeNestedInstances); int count = UnsafeNativeMethods.CRhinoInstanceObjectPieceArray_Count(pPieceList); pieces = new RhinoObject[count]; pieceAttributes = new ObjectAttributes[count]; pieceTransforms = new Transform[count]; for (int i = 0; i < count; i++) { Transform xform = new Transform(); ObjectAttributes attrs = new ObjectAttributes(); IntPtr pAttrs = attrs.NonConstPointer(); IntPtr pRhinoObject = UnsafeNativeMethods.CRhinoInstanceObjectPieceArray_Item(pPieceList, i, pAttrs, ref xform); pieces[i] = RhinoObject.CreateRhinoObjectHelper(pRhinoObject); pieceAttributes[i] = attrs; pieceTransforms[i] = xform; } UnsafeNativeMethods.CRhinoInstanceObjectPieceArray_Delete(pPieceList); }
/// <summary> /// returns an object used as part of this definition. /// </summary> /// <param name="index">0 <= index < ObjectCount.</param> /// <returns> /// Returns an object that is used to define the geometry. /// Does NOT return an object that references this definition.count the number of references to this instance. /// </returns> public RhinoObject Object(int index) { IntPtr ptr = UnsafeNativeMethods.CRhinoInstanceDefinition_Object(m_doc.m_docId, m_index, index); return(RhinoObject.CreateRhinoObjectHelper(ptr)); }