コード例 #1
0
def delete_objects(guids, purge=None, redraw=True):
    """Delete multiple Rhino objects.

    Parameters
    ----------
    guids : list of GUID
    purge : None or bool, optional
        If None, the value of the global purge setting (:obj:`compas_rhino.PURGE_ON_DELETE`) will be used.
        If True, purge the objects from history after deleting.
        If False, delete but don't purge.
        Default is None.
    redraw : bool, optional
        If True, redrawing will be enabled and enacted.
        If False, redrawing will be disabled.
        Default is True.
    """
    if purge is None:
        purge = compas_rhino.PURGE_ON_DELETE
    if purge and purge_object:
        purge_objects(guids, redraw=redraw)
    else:
        rs.EnableRedraw(False)
        for guid in guids:
            if rs.IsObjectHidden(guid):
                rs.ShowObject(guid)
        rs.DeleteObjects(guids)
        if redraw:
            rs.EnableRedraw(True)
            sc.doc.Views.Redraw()
コード例 #2
0
def purge_objects(guids):
    for guid in guids:
        if rs.IsObjectHidden(guid):
            rs.ShowObject(guid)
        o = find_object(guid)
        purge_object(o.RuntimeSerialNumber)
    sc.doc.Views.Redraw()
コード例 #3
0
def purge_objects(guids, redraw=True):
    """Purge objects from memory.

    Parameters
    ----------
    guids : list[System.Guid]
        Object identifiers.
    redraw : bool, optional
        If True, redrawing will be enabled and enacted.
        If False, redrawing will be disabled.

    Returns
    -------
    None

    """
    if not purge_object:
        raise RuntimeError('Cannot purge outside Rhino script context')
    rs.EnableRedraw(False)
    for guid in guids:
        if rs.IsObject(guid):
            if rs.IsObjectHidden(guid):
                rs.ShowObject(guid)
            o = find_object(guid)
            purge_object(o.RuntimeSerialNumber)
    if redraw:
        rs.EnableRedraw(True)
        sc.doc.Views.Redraw()
コード例 #4
0
def delete_objects(guids, purge=True):
    if purge:
        purge_objects(guids)
    else:
        for guid in guids:
            if rs.IsObjectHidden(guid):
                rs.ShowObject(guid)
        rs.DeleteObjects(guids)
コード例 #5
0
def purge_objects(guids):
    if not purge_object:
        raise RuntimeError('Cannot purge outside Rhino script context')
    for guid in guids:
        if rs.IsObjectHidden(guid):
            rs.ShowObject(guid)
        o = find_object(guid)
        purge_object(o.RuntimeSerialNumber)
    sc.doc.Views.Redraw()
コード例 #6
0
ファイル: helpers.py プロジェクト: edwardyanxin/compas-RV2
def purge_objects(guids):
    rs.EnableRedraw(False)
    if not purge_object:
        raise RuntimeError('Cannot purge outside Rhino context.')
    for guid in guids:
        if rs.IsObject(guid):
            if rs.IsObjectHidden(guid):
                rs.ShowObject(guid)
            o = find_object(guid)
            purge_object(o.RuntimeSerialNumber)
コード例 #7
0
def ExportLighthouseSensorsToJSON(filename):
    print "Writing", filename

    #objectIds = rs.GetObjects("Select Sensors",rs.filter.curves,True,True)
    #if( objectIds==None ): return3

    # Find all circle and all lines in scene
    circles = []
    lines = []
    for obj in rs.AllObjects():
        # Skip hidden objects, and invisible layers
        # TODO: Recuse up layet hierarchy?
        if rs.IsObjectHidden(obj):
            continue
        layer = rs.ObjectLayer(obj)
        if layer and not rs.IsLayerVisible(layer):
            continue

        if rs.IsCurve(obj):
            if rs.IsCircle(obj):
                circles.append((obj, rs.CircleCenterPoint(obj)))
            elif rs.IsLine(obj):
                verts = rs.PolylineVertices(obj)
                if len(verts) == 2:
                    lines.append((obj, verts))

    print 'found', len(circles), 'sensor candidates (circles) in scene'
    print 'found', len(lines), 'sensor candidates (normals) in scene'

    modelJSON = {'modelNormals': [], 'modelPoints': []}

    # TODO: Better sort order? Perhaps based on winding around origin?
    for circleObj, circleCenter in reversed(circles):
        for line, lineVerts in lines:
            pos, normal = GetSensorPosAndNormal(circleCenter, lineVerts)
            if pos is None:
                continue
            else:
                modelJSON['modelNormals'].append([float(x) for x in normal])
                modelJSON['modelPoints'].append(
                    [float(x) / 1000.0 for x in pos])
                break
    modelJSON['channelMap'] = range(len(modelJSON['modelNormals']))

    print "Extracted", len(modelJSON['channelMap']), "sensors"

    if len(modelJSON['modelNormals']) > 0:
        outputFile = file(filename, 'w')
        jsonText = json.dumps(modelJSON, indent=4, sort_keys=True)
        outputFile.write(jsonText)
        outputFile.close()

        print "Wrote", filename
    else:
        print "Error: No sensors found in scene"
コード例 #8
0
 def __unlockObjects(self):
     # print("Objects unlocked")
     self.prevLockedObjects = []
     allIds = rs.LockedObjects()
     for id in allIds:
         if rs.IsObjectLocked(id):
             if not rs.IsObjectHidden(id):
                 self.prevLockedObjects.append(id)
                 rs.UnlockObject(id)
     self.objectUnLocked = True
     return
コード例 #9
0
def delete_objects(guids, purge=None):
    if purge is None:
        purge = compas_rhino.PURGE_ON_DELETE

    if purge and purge_object:
        purge_objects(guids)
    else:
        for guid in guids:
            if rs.IsObjectHidden(guid):
                rs.ShowObject(guid)
        rs.DeleteObjects(guids)
コード例 #10
0
def delete_objects(guids, purge=None):
    if purge is None:
        purge = compas_rhino.PURGE_ON_DELETE

    if purge and purge_object:
        purge_objects(guids)
    else:
        rs.EnableRedraw(False)
        for guid in guids:
            if rs.IsObjectHidden(guid):
                rs.ShowObject(guid)
        rs.DeleteObjects(guids)
        rs.EnableRedraw(True)
        sc.doc.Views.Redraw()
コード例 #11
0
def purge_objects(guids):
    """Purge objects from memory.

    Parameters
    ----------
    guids : list of GUID
    """
    if not purge_object:
        raise RuntimeError('Cannot purge outside Rhino script context')
    rs.EnableRedraw(False)
    for guid in guids:
        if rs.IsObject(guid):
            if rs.IsObjectHidden(guid):
                rs.ShowObject(guid)
            o = find_object(guid)
            purge_object(o.RuntimeSerialNumber)
    rs.EnableRedraw(True)
    sc.doc.Views.Redraw()
コード例 #12
0
ファイル: helpers.py プロジェクト: edwardyanxin/compas-RV2
def delete_objects(guids, purge=False):
    """Delete objects from the Rhino model space.

    Parameters
    ----------
    guids : list
        A list of object IDs.
    purge : bool, optional
        If ``True``, the objects are permanently deleted
        and cannot be restored through, for example, using *undo*.
        If ``False`` (default), the objects are deleted from the model space
        but can still be restored using Rhino's *undo* function.

    """
    rs.EnableRedraw(False)
    if purge and purge_object:
        purge_objects(guids)
    else:
        for guid in guids:
            if rs.IsObjectHidden(guid):
                rs.ShowObject(guid)
        rs.DeleteObjects(guids)