当前位置: 首页>>代码示例>>Python>>正文


Python utility.coerceguid函数代码示例

本文整理汇总了Python中utility.coerceguid函数的典型用法代码示例。如果您正苦于以下问题:Python coerceguid函数的具体用法?Python coerceguid怎么用?Python coerceguid使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了coerceguid函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: IsDetail

def IsDetail(layout, detail):
    """Verifies that a detail view exists on a page layout view
    Parameters:
      layout: title or identifier of an existing page layout
      detail: title or identifier of an existing detail view
    Returns:
      True if detail is a detail view
      False if detail is not a detail view
      None on error
    """
    layout_id = rhutil.coerceguid(layout)
    views = scriptcontext.doc.Views.GetViewList(False, True)
    found_layout = None
    for view in views:
        if layout_id:
            if view.MainViewport.Id==layout_id:
                found_layout = view
                break
        elif view.MainViewport.Name==layout:
            found_layout = view
            break
    # if we couldn't find a layout, this is an error
    if found_layout is None: return scriptcontext.errorhandler()
    detail_id = rhutil.coerceguid(detail)
    details = view.GetDetailViews()
    if not details: return False
    for detail_view in details:
        if detail_id:
            if detail_view.Id==detail_id: return True
        else:
            if detail_view.Name==detail: return True
    return False
开发者ID:howllone,项目名称:rhinopython,代码行数:32,代码来源:view.py

示例2: MeshBooleanSplit

def MeshBooleanSplit(input0, input1, delete_input=True):
    """Performs a boolean split operation on two sets of input meshes
    Parameters:
      input0, input1 = identifiers of meshes
      delete_input[opt] = delete the input meshes
    Returns:
      list of identifiers of new meshes on success
      None on error
    """
    id = rhutil.coerceguid(input0)
    if id: input0 = [id]
    id = rhutil.coerceguid(input1)
    if id: input1 = [id]
    meshes0 = [rhutil.coercemesh(id, True) for id in input0]
    meshes1 = [rhutil.coercemesh(id, True) for id in input1]
    if not meshes0 or not meshes1: raise ValueError("no meshes to work with")
    newmeshes = Rhino.Geometry.Mesh.CreateBooleanSplit(meshes0, meshes1)
    rc = []
    for mesh in newmeshes:
        id = scriptcontext.doc.Objects.AddMesh(mesh)
        if id!=System.Guid.Empty: rc.append(id)
    if rc and delete_input:
        input = input0 + input1
        for id in input:
            id = rhutil.coerceguid(id, True)
            scriptcontext.doc.Objects.Delete(id, True)
    scriptcontext.doc.Views.Redraw()
    return rc
开发者ID:nhfoley,项目名称:rhinopython,代码行数:28,代码来源:mesh.py

示例3: CurrentDetail

def CurrentDetail(layout, detail=None, return_name=True):
    """Returns or changes the current detail view in a page layout view
    Parameters:
      layout = title or identifier of an existing page layout view
      detail[opt] = title or identifier the the detail view to set
      return_name[opt] = return title if True, else return identifier
    Returns:
      if detail is not specified, the title or id of the current detail view
      if detail is specified, the title or id of the previous detail view
      None on error
    """
    layout_id = rhutil.coerceguid(layout)
    page = None
    if layout_id is None: page = scriptcontext.doc.Views.Find(layout, False)
    else: page = scriptcontext.doc.Views.Find(layout_id)
    if page is None: return scriptcontext.errorhandler()
    rc = None
    active_viewport = page.ActiveViewport
    if return_name: rc = active_viewport.Name
    else: rc = active_viewport.Id
    if detail:
        id = rhutil.coerceguid(detail)
        if( (id and id==page.MainViewport.Id) or (id is None and detail==page.MainViewport.Name) ):
            page.SetPageAsActive()
        else:
            if id: page.SetActiveDetail(id)
            else: page.SetActiveDetail(detail, False)
    scriptcontext.doc.Views.Redraw()
    return rc
开发者ID:howllone,项目名称:rhinopython,代码行数:29,代码来源:view.py

示例4: MatchMaterial

def MatchMaterial(source, destination):
    """Copies the material definition from one material to one or more objects
    Parameters:
      source = source material index -or- identifier of the source object.
        The object must have a material assigned
      destination = indentifier(s) of the destination object(s)
    Returns:
      number of objects that were modified if successful
      None if not successful or on error
    """
    source_id = rhutil.coerceguid(source)
    source_mat = None
    if source_id:
        rhobj = rhutil.coercerhinoobject(source_id, True, True)
        source = rhobj.Attributes.MaterialIndex
    mat = scriptcontext.doc.Materials[source]
    if not mat: return scriptcontext.errorhandler()
    destination_id = rhutil.coerceguid(destination)
    if destination_id: destination = [destination]
    ids = [rhutil.coerceguid(d) for d in destination]
    rc = 0
    for id in ids:
        rhobj = scriptcontext.doc.Objects.Find(id)
        if rhobj:
            rhobj.Attributes.MaterialIndex = source
            rhobj.Attributes.MaterialSource = Rhino.DocObjects.ObjectMaterialSource.MaterialFromObject
            rhobj.CommitChanges()
            rc += 1
    if rc>0: scriptcontext.doc.Views.Redraw()
    return rc
开发者ID:Agnestan,项目名称:rhinopython,代码行数:30,代码来源:material.py

示例5: DeleteObjects

def DeleteObjects(object_ids):
    """Deletes one or more objects from the document
    Parameters:
      object_ids: identifiers of objects to delete
    Returns:
      Number of objects deleted
    """
    rc = 0
    id = rhutil.coerceguid(object_ids, False)
    if id: object_ids = [id]
    for id in object_ids:
        id = rhutil.coerceguid(id, True)
        if scriptcontext.doc.Objects.Delete(id, True): rc+=1
    if rc: scriptcontext.doc.Views.Redraw()
    return rc
开发者ID:acormier,项目名称:rhinoscriptsyntax,代码行数:15,代码来源:object.py

示例6: HideObjects

def HideObjects(object_ids):
    """Hides one or more objects
    Parameters:
      object_ids: identifiers of objects to hide
    Returns:
      Number of objects hidden
    """
    id = rhutil.coerceguid(object_ids, False)
    if id: object_ids = [id]
    rc = 0
    for id in object_ids:
        id = rhutil.coerceguid(id, True)
        if scriptcontext.doc.Objects.Hide(id, False): rc += 1
    if rc: scriptcontext.doc.Views.Redraw()
    return rc
开发者ID:acormier,项目名称:rhinoscriptsyntax,代码行数:15,代码来源:object.py

示例7: ObjectName

def ObjectName(object_id, name=None):
    """Returns or modifies the name of an object
    Parameters:
      object_id = id or ids of object(s)
      name[opt] = the new object name. If omitted, the current name is returned
    Returns:
      If name is not specified, the current object name
      If name is specified, the previous object name
      If object_id is a list, the number of objects changed
    """
    id = rhutil.coerceguid(object_id, False)
    rhino_object = None
    rhino_objects = None
    if id:
        rhino_object = rhutil.coercerhinoobject(id, True, True)
    else:
        rhino_objects = [rhutil.coercerhinoobject(id, True, True) for id in object_id]
        if not rhino_objects: return 0
        if len(rhino_objects)==1:
            rhino_object = rhino_objects[0]
            rhino_objects = None
    if name is None: #get the name
        if rhino_objects: raise Exception("name required when object_id represents multiple objects")
        return rhino_object.Name
    if rhino_objects:
        for rh_obj in rhino_objects:
            attr = rh_obj.Attributes
            attr.Name = name
            scriptcontext.doc.Objects.ModifyAttributes(rh_obj, attr, True)
        return len(rhino_objects)
    rc = rhino_object.Name
    if not type(name) is str: name = str(name)
    rhino_object.Attributes.Name = name
    rhino_object.CommitChanges()
    return rc
开发者ID:acormier,项目名称:rhinoscriptsyntax,代码行数:35,代码来源:object.py

示例8: ObjectMaterialSource

def ObjectMaterialSource(object_ids, source=None):
    """Returns or modifies the rendering material source of an object.
    Parameters:
      object_ids = one or more object identifiers
      source [opt] = The new rendering material source. If omitted and a single
        object is provided in object_ids, then the current material source is
        returned. This parameter is required if multiple objects are passed in
        object_ids
        0 = Material from layer
        1 = Material from object
        3 = Material from parent
    Returns:
      If source is not specified, the current rendering material source
      If source is specified, the previous rendering material source
      If object_ids refers to multiple objects, the number of objects modified
    """
    id = rhutil.coerceguid(object_ids, False)
    if id: # working with single object
        rhino_object = rhutil.coercerhinoobject(id, True, True)
        rc = int(rhino_object.Attributes.MaterialSource)
        if source is not None:
            rhino_object.Attributes.MaterialSource = System.Enum.ToObject(Rhino.DocObjects.ObjectMaterialSource, source)
            rhino_object.CommitChanges()
        return rc
    # else working with multiple objects
    if source is None: raise Exception("source is required when object_ids represents multiple objects")
    source = System.Enum.ToObject(Rhino.DocObjects.ObjectMaterialSource, source)
    for id in object_ids:
        rhino_object = rhutil.coercerhinoobject(id, True, True)
        rhino_object.Attributes.MaterialSource = source
        rhino_object.CommitChanges()
    return len(object_ids)
开发者ID:acormier,项目名称:rhinoscriptsyntax,代码行数:32,代码来源:object.py

示例9: ExplodeMeshes

def ExplodeMeshes(mesh_ids, delete=False):
    """Explodes a mesh object, or mesh objects int submeshes. A submesh is a
    collection of mesh faces that are contained within a closed loop of
    unwelded mesh edges. Unwelded mesh edges are where the mesh faces that
    share the edge have unique mesh vertices (not mesh topology vertices)
    at both ends of the edge
    Parameters:
      mesh_ids = list of mesh identifiers
      delete[opt] = delete the input meshes
    Returns:
      List of identifiers
    """
    id = rhutil.coerceguid(mesh_ids)
    if id: mesh_ids = [mesh_ids]
    rc = []
    for mesh_id in mesh_ids:
        mesh = rhutil.coercemesh(mesh_id, True)
        if mesh:
            submeshes = mesh.ExplodeAtUnweldedEdges()
            if submeshes:
                for submesh in submeshes:
                    id = scriptcontext.doc.Objects.AddMesh(submesh)
                    if id!=System.Guid.Empty: rc.append(id)
    if rc: scriptcontext.doc.Views.Redraw()
    return rc
开发者ID:nhfoley,项目名称:rhinopython,代码行数:25,代码来源:mesh.py

示例10: JoinMeshes

def JoinMeshes(object_ids, delete_input=False):
    """Joins two or or more mesh objects together
    Parameters:
      object_ids = identifiers of two or more mesh objects
      delete_input[opt] = delete input after joining
    Returns:
      identifier of newly created mesh on success
    Example:
      import rhinoscriptsyntax as rs
      objs = rs.GetObjects("Select meshes to join", rs.filter.mesh)
      if objs and len(objs)>1: rs.JoinMeshes(objs, True)
    See Also:
      JoinCurves
      JoinSurfaces
    """
    meshes = [rhutil.coercemesh(id,True) for id in object_ids]
    joined_mesh = Rhino.Geometry.Mesh()
    for mesh in meshes: joined_mesh.Append(mesh)
    rc = scriptcontext.doc.Objects.AddMesh(joined_mesh)
    if delete_input:
        for id in object_ids:
            guid = rhutil.coerceguid(id)
            scriptcontext.doc.Objects.Delete(guid,True)
    scriptcontext.doc.Views.Redraw()
    return rc
开发者ID:itrowa,项目名称:rhinoscriptsyntax,代码行数:25,代码来源:mesh.py

示例11: MeshArea

def MeshArea(object_ids):
    """Returns approximate area of one or more mesh objects
    Parameters:
      object_ids = identifiers of one or more mesh objects
    Returns:
      list containing 3 numbers if successful where
        element[0] = number of meshes used in calculation
        element[1] = total area of all meshes
        element[2] = the error estimate
      None if not successful
    Example:
      import rhinoscriptsyntax as rs
      obj = rs.GetObject("Select mesh", rs.filter.mesh )
      if obj:
      area_rc = rs.MeshArea(obj)
      if area_rc: print "Mesh area:", area_rc[1]
    See Also:
      MeshVolume
    """
    id = rhutil.coerceguid(object_ids)
    if id: object_ids = [object_ids]
    meshes_used = 0
    total_area = 0.0
    error_estimate = 0.0
    for id in object_ids:
        mesh = rhutil.coercemesh(id, True)
        if mesh:
            mp = Rhino.Geometry.AreaMassProperties.Compute(mesh)
            if mp:
                meshes_used += 1
                total_area += mp.Area
                error_estimate += mp.AreaError
    if meshes_used==0: return scriptcontext.errorhandler()
    return meshes_used, total_area, error_estimate
开发者ID:itrowa,项目名称:rhinoscriptsyntax,代码行数:34,代码来源:mesh.py

示例12: TextObjectStyle

def TextObjectStyle(object_id, style=None):
    """Returns or modifies the font style of a text object
    Parameters:
      object_id = the identifier of a text object
      style [opt] = the font style. Can be any of the following flags
         0 = Normal
         1 = Bold
         2 = Italic
    Returns:
      if style is not specified, the current font style
      if style is specified, the previous font style
      None if not successful, or on Error
    """
    annotation = rhutil.coercegeometry(object_id, True)
    if not isinstance(annotation, Rhino.Geometry.TextEntity):
        return scriptcontext.errorhandler()
    fontdata = scriptcontext.doc.Fonts[annotation.FontIndex]
    if fontdata is None: return scriptcontext.errorhandler()
    rc = 0
    if fontdata.Bold: rc += 1
    if fontdata.Italic: rc += 2
    if style is not None and style!=rc:
        index = scriptcontext.doc.Fonts.FindOrCreate( fontdata.FaceName, (style&1)==1, (style&2)==2 )
        annotation.FontIndex = index
        id = rhutil.coerceguid(object_id, True)
        scriptcontext.doc.Objects.Replace(id, annotation)
        scriptcontext.doc.Views.Redraw()
    return rc
开发者ID:Agnestan,项目名称:rhinopython,代码行数:28,代码来源:geometry.py

示例13: ObjectPrintWidthSource

def ObjectPrintWidthSource(object_ids, source=None):
    """Returns or modifies the print width source of an object
    Parameters:
      object_ids = identifiers of object(s)
      source[opt] = new print width source
        0 = print width by layer
        1 = print width by object
        3 = print width by parent
    Returns:
      If source is not specified, the object's current print width source
      If source is specified, the object's previous print width source
      If object_ids is a list or tuple, the number of objects modified
    """
    id = rhutil.coerceguid(object_ids, False)
    if id:
        rhino_object = rhutil.coercerhinoobject(id, True, True)
        rc = int(rhino_object.Attributes.PlotWeightSource)
        if source is not None:
            rhino_object.Attributes.PlotWeightSource = System.Enum.ToObject(Rhino.DocObjects.ObjectPlotWeightSource, source)
            rhino_object.CommitChanges()
            scriptcontext.doc.Views.Redraw()
        return rc
    for id in object_ids:
        rhino_object = rhutil.coercerhinoobject(id, True, True)
        rhino_object.Attributes.PlotWeightSource = System.Enum.ToObject(Rhino.DocObjects.ObjectPlotWeightSource, source)
        rhino_object.CommitChanges()
    scriptcontext.doc.Views.Redraw()
    return len(object_ids)
开发者ID:acormier,项目名称:rhinoscriptsyntax,代码行数:28,代码来源:object.py

示例14: ShowObjects

def ShowObjects(object_ids):
    """Shows one or more objects. Hidden objects are not visible, cannot be
    snapped to and cannot be selected
    Parameters:
      object_ids: list of Strings or Guids representing ids of objects to show
    Returns:
      Number of objects shown
    """
    id = rhutil.coerceguid(object_ids, False)
    if id: object_ids = [id]
    rc = 0
    for id in object_ids:
        id = rhutil.coerceguid(id, True)
        if scriptcontext.doc.Objects.Show(id, False): rc += 1
    if rc: scriptcontext.doc.Views.Redraw()
    return rc
开发者ID:acormier,项目名称:rhinoscriptsyntax,代码行数:16,代码来源:object.py

示例15: GetMeshVertices

def GetMeshVertices(object_id, message="", min_count=1, max_count=0):
    """Prompts the user to pick one or more mesh vertices
    Parameters:
      object_id = the mesh object's identifier
      message[opt] = a prompt of message
      min_count[opt] = the minimum number of vertices to select
      max_count[opt] = the maximum number of vertices to select. If 0, the user must
        press enter to finish selection. If -1, selection stops as soon as there
        are at least min_count vertices selected.
    Returns:
      list of mesh vertex indices on success
      None on error
    """
    scriptcontext.doc.Objects.UnselectAll()
    scriptcontext.doc.Views.Redraw()
    object_id = rhutil.coerceguid(object_id, True)
    class CustomGetObject(Rhino.Input.Custom.GetObject):
        def CustomGeometryFilter( self, rhino_object, geometry, component_index ):
            return object_id == rhino_object.Id
    go = CustomGetObject()
    if message: go.SetCommandPrompt(message)
    go.GeometryFilter = Rhino.DocObjects.ObjectType.MeshVertex
    go.AcceptNothing(True)
    if go.GetMultiple(min_count,max_count)!=Rhino.Input.GetResult.Object: return None
    objrefs = go.Objects()
    rc = [item.GeometryComponentIndex.Index for item in objrefs]
    go.Dispose()
    return rc
开发者ID:atrevorhess,项目名称:rhinopython,代码行数:28,代码来源:userinterface.py


注:本文中的utility.coerceguid函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。