Exemple #1
0
def ptCheck(a):
    #determines if the submitted point is a point object in space or array value
    #if object is 
    
    #designation implemented to determine if it is not a point object
    designation = 0
    
    try:
        if rs.ObjectType(a) == 1: #collect point object value
            b = rs.coerce3dpoint(a)
        elif rs.ObjectType(a)!= 1: #item is not a point
            designation = 1
    except:
        #item already an array object for use
        b = a
    
    #exporting value
    if designation == 0:
        return b
    #not a point object
    else:
        rs.UnselectAllObjects()
        print "Collecting point value but is another object type"
        rs.SelectObject(a)
        exit()
Exemple #2
0
def get_breps_on_layer(layername):
    buildings = rs.ObjectsByLayer(layername)
    breps = []
    for b in buildings:
        if rs.ObjectType(b) == 16 or rs.ObjectType(b) == 1073741824:
            breps.append(b)
    return breps
Exemple #3
0
def brep_or_crv(guids):
    #probably want to add extrusions, type 1073741824, as if they are breps
    c = [x for x in guids if rs.ObjectType(x) == 4]
    b = [
        x for x in guids
        if (rs.ObjectType(x) == 16 or rs.ObjectType(x) == 1073741824)
    ]
    return c, b
Exemple #4
0
    def _is_element(cls, object_guid):
        """Receives:
            object_guid     guid. The guid of an object
        Returns:
            value           boolean. True, if the object is a line or a 
                            textdot. False, otherwise

                            ## Identify hatch annotation ##
        """
        curve_type = 4
        textdot_type = 8192
        value = (rs.ObjectType(object_guid) == curve_type
                 or rs.ObjectType(object_guid) == textdot_type)
        return value
 def _make_element_lists(self, guids):
     """Receives a list of guids:
         [guid, ...]
     Returns lists of coords, lines, and textdots:
         (   [(num, num, num), ...], 
             [((num, num, num), (num, num, num)), ...],
             [((num, num, num), str), ...]
         )
     """
     coords, lines, lpoints = [], [], []
     line_type = 4
     textdot_type = 8192
     # if not type(guids) == list:
     #     guids = []
     for guid in guids:
         guid_type = rs.ObjectType(guid)
         if guid_type == line_type:
             line_coords = self._get_line_coords(guid)
             lines.append(line_coords)
             for coord in line_coords:
                 coords.append(coord)
         elif guid_type == textdot_type:
             coord = self._get_coord(guid)
             label = self._get_label(guid)
             coords.append(coord)
             lpoint = (coord, label)
             lpoints.append(lpoint)
     element_lists = (coords, lines, lpoints)
     return element_lists
Exemple #6
0
def checkCurvePosition(objs):
    layers = []
    selection = []
    for obj in objs:
        if rs.IsCurve(obj):
            if not isCurveOnCPlane(obj):
                # print "Curve {} not on Cplane".format(obj)
                selection.append(obj)
                appendLayer(layers, obj)

        elif rs.IsPoint(obj):
            if not isPointOnCplane(obj):
                # print "Curve {} not on Cplane".format(obj)
                rs.SelectObject(obj)
                appendLayer(layers, obj)
        else:
            print "object {} is not a curve or point. {}".format(
                obj, rs.ObjectType(obj))

    if len(selection) > 0:
        rs.SelectObjects(selection)

    # when an object is found on > 0 layers, prompt for proceed
    if len(layers) > 0:
        msg = "there were non-planar or elevated curves found on layers:\n"
        for layer in layers:
            msg = msg + "- " + layer + " \n"

        msg = msg + '\n Do you want to proceed?'

        if rs.MessageBox(msg, 1) != 1:
            return False

    # else
    return True
Exemple #7
0
def main():
    msg = "Select polysurface objects to export data"
    objs = rs.GetObjects(msg, 16, preselect=True)
    if not objs: return
    extrusions = []
    rs.UnselectAllObjects()
    for obj in objs:
        if rs.ObjectType(obj) == 1073741824:
            extrusions.append(obj)
    if len(extrusions) > 0:
        rs.SelectObjects(extrusions)
        resp = rs.MessageBox(
            "Selected objects will be converted to polysurfaces.\n Press OK to continue, Cancel to abort",
            1)
        if resp == 1:
            rs.Command("ConvertExtrusion _Enter")
            rs.UnselectAllObjects()
        else:
            return
    keys = [i.name for i in ATTRS if i.isEditable]
    makeDetail(keys, objs)
    details = []
    spec = dict([])
    ids = dict([])
    for obj in objs:
        detail = Detail(obj)
        details.append(detail)
    spec = Specification([], details)
    dialog = SpecDialog()
    dialog.setData(spec)
    rs.UnselectAllObjects()
    Rhino.UI.EtoExtensions.ShowSemiModal(dialog, Rhino.RhinoDoc.ActiveDoc,
                                         Rhino.UI.RhinoEtoApp.MainWindow)
Exemple #8
0
    def collect_data_density(self):
        """Collect the existing density mesh in the density layer.

		Parameters
		----------

		Returns
		-------

		"""

        objects = rs.ObjectsByLayer('density')

        if objects is not None:

            if len(objects) == 1:
                if rs.ObjectType(objects[0]) == 32:

                    vertices, faces = RhinoGeometry.from_guid(
                        objects[0]).get_vertices_and_faces()
                    self.density_mesh = Mesh.from_vertices_and_faces(
                        vertices, faces)

                else:
                    print 'the object in the density layer is not a mesh'

            elif len(objects) > 1:
                print 'too many objects in the density layer'
Exemple #9
0
def main():
    object_id = rs.GetObject("Select an object to sort")
    if object_id is None: return

    object_type = rs.ObjectType(object_id)
    if object_type is None: return

    layer_name = "Unsorted"
    if object_type == 1 or object_type == 2:
        layer_name = "Points"
    elif object_type == 4:
        layer_name = "Curves"
    elif object_type == 8 or object_type == 16:
        layer_name = "PolySurfaces"
    elif object_type == 32:
        layer_name = "Meshes"
    elif object_type == 256:
        layer_name = "Lights"
    elif object_type == 512 or object_type == 8192:
        layer_name = "Annotations"
    elif object_type == 2048 or object_type == 4096:
        layer_name = "Blocks"

    if not rs.IsLayer(layer_name):
        rs.AddLayer(layer_name)
    rs.ObjectLayer(object_id, layer_name)
 def _get_line_specs_and_lpoint_specs(self, guids):
     """Receives a list of guids:
         [guid, ...]
     Returns a list of coord-coord pairs and a list of coord-label pairs:
         (   [((num, num, num), (num, num, num)), ...],
             [((num, num, num), str), ...]
         )
     """
     line_specs = []
     lpoint_specs = []
     line_type = 4  ##  limit to straight lines
     annotation_type = 512
     textdot_type = 8192
     for guid in guids:
         guid_type = rs.ObjectType(guid)
         if guid_type == line_type:
             line_spec = self._get_line_spec(guid)
             line_specs.append(line_spec)
         elif guid_type == annotation_type:
             point = rs.TextObjectPoint(guid)
             x, y, z = point[0], point[1], point[2]
             coord = (x, y, z)
             label = rs.TextObjectText(guid)
             lpoint_spec = (coord, label)
             lpoint_specs.append(lpoint_spec)
         elif guid_type == textdot_type:
             coord, label = self._get_lpoint_spec(guid)
             lpoint_spec = (coord, label)
             lpoint_specs.append(lpoint_spec)
     return (line_specs, lpoint_specs)
Exemple #11
0
    def from_guid(guid):
        """Create a ``RhinoGeometry`` instance of the correct type based on a given guid.

        Parameters
        ----------
        guid : str or System.Guid
            The *guid* of the Rhino object.

        Returns
        -------
        RhinoPoint
            If the type of the Rhino object is ``rs.filter.point``.
        RhinoCurve
            If the type of the Rhino object is ``rs.filter.curve``.
        RhinoMesh
            If the type of the Rhino object is ``rs.filter.mesh``.
        RhinoSurface
            If the type of the Rhino object is ``rs.filter.surface``.

        Examples
        --------
        .. code-block:: python

            import compas
            import compas_rhino

            from compas.datastructures import Mesh
            from compas_rhino.geometry import RhinoGeometry

            mesh = Mesh.from_json(...)

            mesh.update_default_vertex_attributes(constraint=None)

            # interesting stuff happens here

            for key, attr in mesh.vertices(True):
                guid = attr['constraint']

                if guid:
                    constraint = RhinoGeometry.from_guid(guid)
                    xyz = constraint.closest_point(mesh.get_vertex_attributes(key, 'xyz'))
                    mesh.set_vertex_attributes(key, 'xyz', xyz)

            # more interesting stuff happens here

        """
        otype = rs.ObjectType(guid)

        if otype == rs.filter.point:
            return RhinoPoint(guid)

        if otype == rs.filter.curve:
            return RhinoCurve(guid)

        if otype == rs.filter.mesh:
            return RhinoMesh(guid)

        if otype == rs.filter.surface:
            return RhinoSurface(guid)
Exemple #12
0
def layer_objects_types(layer):
    object_types = []
    layer_objects = rs.ObjectsByLayer(layer)
    for object in layer_objects:
        object_type = rs.ObjectType(object)
        object_types.append(object_type)
    object_types = list(set(object_types))
    return object_types
def print_info(guid):
    curve = 4
    block = 4096
    object_type = rs.ObjectType(guid)
    if object_type == curve:
        string = get_curve_info(guid)
    elif object_type == block:
        string = get_block_info(guid)
    print(string)
Exemple #14
0
def find_constraint(name):
    rail = None
    if name:
        guids = compas_rhino.get_objects(name=name)
        if len(guids) == 1:
            otype = rs.ObjectType(guids[0])
            if otype == rs.filter.curve:
                rail = find_object(guids[0])
    return rail
    def ConvertPolysurfaceToSurface(self, polysurface):
        """
        converts polysurfaces to surface and returns False and surface
        if the argument is a polysurface. Returns True and the argument
        type if it is not a polysurface. Polysurfaces are made by SplitBrep
        We can't use normal functions on them. So, we have to turn them
        into seperate surfaces with ExplodePolysurfaces. SplitBrep function is
        used in RemoveSurfacesOutsideOfBox().
        An auxilliary method to trim extruding fractures.

        Parameters
        ----------
        ploysurface: GUID
            guid of a Rhino surface
        """
        # Confirm this is a polysurface
        if rs.ObjectType(polysurface) != 16:
            return [False, [polysurface]]  # false, not a ploysurface
        # unjoins the polysurface and get identifiers of he separate surfaces
        surfaces = rs.ExplodePolysurfaces(polysurface)

        # Sometimes, the function ExplodePolysurfaces makes polysurfaces.
        # If it did, call this function again on those surfaces!
        non_poly_surfaces = []
        for surf in surfaces:
            # check if polysurface was created instead of surface
            if rs.ObjectType(surf) == 16:
                # convert the object to surface using its GUID once more,
                # incase polysurface was created
                # NB: RECURSIVE
                additional_split_surfaces = ConvertPolysurfaceToSurface(
                    surf)[1]
                for new_surf in additional_split_surfaces:
                    non_poly_surfaces.append(new_surf)
                    # self.new_fractures.append(new_surf)
            else:
                non_poly_surfaces.append(surf)
                # self.new_fractures.append(surf)

        # Delete the old polysurface
        rs.DeleteObject(polysurface)

        return [True, non_poly_surfaces]
Exemple #16
0
def get_annotation():
    prompt_for_annotation = 'Select objects'
    guids = rs.GetObjects(prompt_for_annotation)
    print('number of objects: %i' % len(guids))
    for guid in guids:
        print('object type: %i' % rs.ObjectType(guid))
        if rs.IsText(guid):
            print('text: %s' % rs.TextObjectText(guid))
        elif rs.IsTextDot(guid):
            print('text dot: %s' % rs.TextDotText(guid))
        else:
            print('guid is not text')
Exemple #17
0
    def ptCheck(self, a):
        designation = 0

        try:
            if rs.ObjectType(a) == 1:  #collect point object value
                b = rs.coerce3dpoint(a)
            elif rs.ObjectType(a) != 1:  #item is not a point
                designation = 1
        except:
            #item already an array object for use
            b = a

        #exporting value
        if designation == 0:
            return b
        #not a point object
        else:
            rs.UnselectAllObjects()
            print "Collecting point value but is another object type"
            rs.SelectObject(a)
            exit()
Exemple #18
0
    def callback(k, args):

        mesh, constraints = args

        for vkey, constraint in constraints.items():
            if rs.ObjectType(constraint) == 1:
                x, y, z = RhinoPoint.from_guid(constraint).xyz
            elif rs.ObjectType(constraint) == 4:
                x, y, z = RhinoCurve.from_guid(constraint).closest_point(
                    mesh.vertex_coordinates(vkey))
            elif rs.ObjectType(constraint) == 8:
                x, y, z = RhinoSurface.from_guid(constraint).closest_point(
                    mesh.vertex_coordinates(vkey))
            elif rs.ObjectType(constraint) == 32:
                x, y, z = RhinoMesh.from_guid(constraint).closest_point(
                    mesh.vertex_coordinates(vkey))
            else:
                continue

            mesh.vertex[vkey]['x'] = x
            mesh.vertex[vkey]['y'] = y
            mesh.vertex[vkey]['z'] = z
    def get_allowed_geometry(self):
        """Returns geometry that is allowed in the current layer (point for nodes, line for beams etc.)"""

        objects = self.get_geometry()

        allowed_objects = []

        for obj in objects:

            if rs.ObjectType(obj) == gs.allowed_object_types[self.path[1]]:

                allowed_objects.append(obj)

        return allowed_objects
Exemple #20
0
 def _object_is_in_box(cls, object_guid, box_position, box_size):
     """Receives:
         object_guid     guid. The guid of an object
         box_position    Point3d. The position of the frame instance
         box_size        (num, num, num). The size of the frame block
     """
     curve_type = 4
     textdot_type = 8192
     if rs.ObjectType(object_guid) == curve_type:
         tail = rs.CurveStartPoint(object_guid)
         head = rs.CurveEndPoint(object_guid)
         points = [tail, head]
     elif rs.ObjectType(object_guid) == textdot_type:
         point = rs.TextDotPoint(object_guid)
         points = [point]
     else:
         pass
     value = True
     for point in points:
         if not cls._point_is_in_box(point, box_position, box_size):
             value = False
             break
     return value
Exemple #21
0
def get_object_types(guids):
    """Get the type of multiple objects.

    Parameters
    ----------
    guids : list[System.Guid]
        Object identifiers.

    Returns
    -------
    list[str]

    """
    return [rs.ObjectType(guid) for guid in guids]
Exemple #22
0
def input_objects():
    """Get input objects.

	Parameters
	----------

	Returns
	-------
	surfaces : list
		The guids of the surfaces
	points : list
		The guids of the points
	curves : list
		The guids of the curves

	"""

    input_objects = rs.ObjectsByLayer('input')
    surfaces = [obj for obj in input_objects if rs.ObjectType(obj) == 8]
    points = [obj for obj in input_objects if rs.ObjectType(obj) == 1]
    curves = [obj for obj in input_objects if rs.ObjectType(obj) == 4]

    return surfaces, points, curves
def main():
    objs = rs.GetObjects("select block", 0, True, True)
    print len(objs)

    for obj in objs:
        if rs.ObjectType(obj) == 4096:
            name = rs.BlockInstanceName(obj)
            print rs.BlockDescription(name)
            children = rs.ExplodeBlockInstance(obj)
            text = rs.AddText(name, [0, 0, 0],
                              height=1.0,
                              font="Arial",
                              font_style=0,
                              justification=None)

            print type(children)

            children.Append(text)
            print children[0]
Exemple #24
0
    def from_guid(guid):
        """Create a ``RhinoGeometry`` instance of the correct type based on a given guid.

        Parameters
        ----------
        guid : str or System.Guid
            The *guid* of the Rhino object.

        Returns
        -------
        RhinoPoint
            If the type of the Rhino object is ``rs.filter.point``.
        RhinoCurve
            If the type of the Rhino object is ``rs.filter.curve``.
        RhinoMesh
            If the type of the Rhino object is ``rs.filter.mesh``.
        RhinoSurface
            If the type of the Rhino object is ``rs.filter.surface``.

        Examples
        --------
        >>>

        """
        from compas_rhino.geometry import RhinoPoint
        from compas_rhino.geometry import RhinoCurve
        from compas_rhino.geometry import RhinoMesh
        from compas_rhino.geometry import RhinoSurface

        otype = rs.ObjectType(guid)

        if otype == rs.filter.point:
            return RhinoPoint(guid)

        if otype == rs.filter.curve:
            return RhinoCurve(guid)

        if otype == rs.filter.mesh:
            return RhinoMesh(guid)

        if otype == rs.filter.surface:
            return RhinoSurface(guid)
Exemple #25
0
 def _get_line_specs_and_lpoint_specs(self, guids):
     """Receives a list of line or textdot guids:
         [guid, ...]
     Returns a list of coord-coord pairs and a list of coord-label pairs:
         (   [((num, num, num), (num, num, num)), ...],
             [((num, num, num), str), ...]
         )
     """
     line_specs = []
     lpoint_specs = []
     line_type = 4
     textdot_type = 8192
     for guid in guids:
         guid_type = rs.ObjectType(guid)
         if guid_type == line_type:
             line_spec = self._get_line_spec(guid)
             line_specs.append(line_spec)
         elif guid_type == textdot_type:
             coord, label = self._get_lpoint_spec(guid)
             lpoint_spec = (coord, label)
             lpoint_specs.append(lpoint_spec)
     return (line_specs, lpoint_specs)
 def classify_guids(cls, guids):             ##  05-28 09:06
     """Receives:
         guids           [guid, ...]. A list of guids
     Classifies the guids by type. Returns:
         (line_guids, lpoint_guids, text_guids, frame_guid)
                         line_guids: [line_guid, ...]
                         lpoint_guids: [lpoint_guid, ...]
                         text_guids: [text_guid, ...]
                         frame_guid
     """
     line_guids, lpoint_guids, text_guids = [], [], []
     line_type, lpoint_type, text_type = 4, 8192, 512
     for guid in guids:
         guid_type = rs.ObjectType(guid)
         if guid_type == line_type:
             line_guids.append(guid)
         elif guid_type == lpoint_type:
             lpoint_guids.append(guid)
         elif guid_type == text_type:
             text_guids.append(guid)
         else:
             pass
     return (line_guids, lpoint_guids, text_guids, frame_guid)
Exemple #27
0
def processObject(object, parentInstances):
    global g_instances
    global g_instancesByName
    global g_parts
    global g_materials

    name = rs.ObjectName(object)
    if not name:
        name = "Unnamed"
    type = rs.ObjectType(object)
    layer = rs.ObjectLayer(object)

    if type == rs.filter.instance:
        type = rs.BlockInstanceName(object)

        xform = rs.BlockInstanceXform(object)

        # Seems like transforms are in global frame already
        # --> Probably due to exploding the block hierarchies...
        #for parent in reversed(parentInstances[1:]) :
        #    xform = parent["xform"] * xform

        subObjects = rs.ExplodeBlockInstance(object)

        fullName = name
        if len(parentInstances) > 1:
            for parent in parentInstances[1:]:
                fullName = parent["name"] + "." + fullName
        originalFullName = fullName

        appendixCtr = 1
        while fullName in g_instancesByName:
            fullName = format("%s+%d" % (originalFullName, appendixCtr))
            appendixCtr += 1
        if fullName != originalFullName:
            print("WARNING: Renamed %s => %s" % (originalFullName, fullName))

        instance = \
        {
               "name" : name,
           "fullName" : fullName,
               "type" : type,
              "xform" : xform,
            "parents" : list(parentInstances),
              "parts" : [],
            "touched" : False,
        }
        g_instances.append(instance)
        g_instancesByName[fullName] = instance

        for subObject in subObjects:
            processObject(subObject, parentInstances + [instance])
        return

    skipReason = None
    if rs.LayerLocked(layer):
        skipReason = "layer locked"
    elif not rs.LayerVisible(layer):
        skipReason = "layer hidden"
    elif type != rs.filter.polysurface and type != rs.filter.surface:
        skipReason = "bad type - " + typeStr[type]

    if skipReason:
        # make sure we can delete object by moving to current layer
        rs.ObjectLayer(object, rs.CurrentLayer())
        print("Skipping %s (%s)" % (str(object), skipReason))
    else:
        brep = rs.coercebrep(object)
        meshes = rc.Geometry.Mesh.CreateFromBrep(brep, g_meshParams)
        joinedMesh = rc.Geometry.Mesh()
        for mesh in meshes:
            joinedMesh.Append(mesh)
        joinedMesh.Reduce(0, False, 10, False)
        if not joinedMesh.Faces.ConvertQuadsToTriangles():
            print("WARNING: Failed to convert quads to tris for %s" %
                  (str(object)))
        if not joinedMesh.Compact():
            print("WARNING: Failed to compact %s" % (str(object)))

        materialSrc = rs.ObjectMaterialSource(object)
        if materialSrc == 0:
            materialIdx = rs.LayerMaterialIndex(rs.ObjectLayer(object))
        else:
            materialIdx = rs.ObjectMaterialIndex(object)

        material = rs.MaterialName(materialIdx)
        if not material:
            material = "None"
        g_materials[material] = materialIdx

        joinedMeshGuid = sc.doc.Objects.AddMesh(joinedMesh)
        rs.ObjectName(joinedMeshGuid, name)
        rs.ObjectMaterialSource(joinedMeshGuid, 1)
        rs.ObjectMaterialIndex(joinedMeshGuid, materialIdx)

        part = \
        {
                "name" : name,
                "mesh" : joinedMesh,
            "instance" : parentInstances[-1],
            "material" : material,
        }
        parentInstances[-1]["parts"].append(part)
        if not parentInstances[-1]["touched"]:
            for parentInstance in parentInstances:
                parentInstance["touched"] = True
        g_parts.append(part)

    rs.DeleteObject(object)
Exemple #28
0
def main():
    global g_instances
    global g_parts
    global g_indent
    global g_materials

    #print(sys.version_info) # (2, 7, 0, 'beta', 0)

    dlg = rc.UI.SaveFileDialog()
    dlg.DefaultExt = "model"
    dlg.Filter = "RocketScience 3D Model (*.model)"
    dlg.InitialDirectory = os.path.dirname(sc.doc.Path)
    if not dlg.ShowSaveDialog(): return None

    selectedObjects = rs.SelectedObjects()

    objects = []
    origin = [0, 0, 0]

    for object in selectedObjects:
        name = rs.ObjectName(object)
        type = rs.ObjectType(object)
        if type == rs.filter.point:
            if name.startswith("Origin"):
                origin = rs.PointCoordinates(object)
        else:
            objects.append(object)

    print("Processing " + str(len(objects)) + " object(s)")
    print("Origin is [%.2f,%.2f,%.2f]" % (origin[0], origin[1], origin[2]))

    rootInstance = \
    {
            "name" : "*",
        "fullName" : "*",
            "type" : "*",
           "xform" : None,
         "parents" : [],
           "parts" : [],
         "touched" : False,
    }

    g_instances.append(rootInstance)

    objectsCopied = rs.CopyObjects(objects, rs.VectorScale(origin, -1))
    for object in objectsCopied:
        processObject(object, [rootInstance])

    output = open(dlg.FileName, "w")

    #output.write("# i <instance-type> <instance-name> "
    #    "<parent-instance-name>\n")
    #output.write("# x <x-axis-x> <y-axis-x> <z-axis-x> <translation-x>\n")
    #output.write("# x <x-axis-y> <y-axis-y> <z-axis-y> <translation-y>\n")
    #output.write("# x <x-axis-z> <y-axis-z> <z-axis-z> <translation-z>\n")
    #output.write("# m <material-name> <ambient> <diffuse> <emission>\n")
    #output.write("# p <part-name> <instance-name> <material-name> "
    #    "<vertices> <triangles>\n")
    #output.write("# v <pos-x> <pos-y> <pox-z> <norm-x> <norm-y> <norm-z>\n")
    #output.write("# t <vertex-1> <vertex-2> <vertex-3>\n")
    #output.write("\n")

    g_instances.sort(key=instanceSortKey)
    for instance in g_instances:
        parentCount = len(instance["parents"])

        indent = g_indent * (parentCount - 1)

        parentName = "*"
        if instance["parents"]:
            parentName = instance["parents"][-1]["name"]
        line = format(
            "i%s %s %s %s" %
            (indent, instance["type"], instance["fullName"], parentName))

        print(line)
        output.write(line + "\n")

        if parentCount < 1:
            xform = rc.Geometry.Transform(1.0)
        else:
            xform = instance["xform"]

        indent += "  "
        output.write("x " + indent + formatHexFloats(
            [xform.M00, xform.M01, xform.M02, xform.M03], True) + "\n")
        output.write("x " + indent + formatHexFloats(
            [xform.M10, xform.M11, xform.M12, xform.M13], True) + "\n")
        output.write("x " + indent + formatHexFloats(
            [xform.M20, xform.M21, xform.M22, xform.M23], True) + "\n")

    for materialName, materialIdx in g_materials.iteritems():
        material = sc.doc.Materials[materialIdx]

        ambient = material.AmbientColor
        diffuse = material.DiffuseColor
        emission = material.EmissionColor

        line = format(
            "m %s %s" %
            (materialName, formatColors([ambient, diffuse, emission])))

        print(line)
        output.write(line + "\n")

    g_parts.sort(key=partSortKey)
    for part in g_parts:
        mesh = part["mesh"]

        line = format(
            "p %s %s %s %d %d" %
            (part["name"], part["instance"]["fullName"], part["material"],
             mesh.Vertices.Count, mesh.Faces.Count))

        print(line)
        output.write(line + "\n")

        indent = "  "

        for vertexIdx in range(0, mesh.Vertices.Count):
            vertex = mesh.Vertices[vertexIdx]
            normal = mesh.Normals[vertexIdx]
            output.write("v " + indent + formatHexFloats(
                [vertex.X, vertex.Y, vertex.Z, normal.X, normal.Y, normal.Z]) +
                         "\n")

        line = lineInit = "t" + indent
        for faceIdx in range(0, mesh.Faces.Count):
            face = mesh.Faces[faceIdx]
            if not face.IsTriangle:
                print("WARNING: Non-triangle face %d" % (faceIdx))
            part = format(" %d %d %d" % (face.A, face.B, face.C))
            if len(line) + len(part) > 100:
                output.write(line + "\n")
                line = lineInit
            line += part
        if len(line) > 0:
            output.write(line + "\n")

    output.close()
Exemple #29
0
    print "rotation", rotations

    for ix in range(counts[0]):
        newobj = rs.CopyObject(obj, [spacings[0] * ix, 0, 0])
        bbox = rs.BoundingBox(newobj)
        if bbox:
            centroid = rs.PointSubtract(bbox[0], bbox[6])
            print bbox[6], bbox[0]
            print centroid
            rs.AddPoint(centroid)
        else:
            print "no bbox"

        # rs.RotateObject(newobj, )


obj = rs.GetObject()

if obj:
    ot = rs.ObjectType(obj)
    print(ot)

    if ot == 4 or 8 or 16 or 32:  # crv, srf, polysrf, mesh
        # if ot == 4: #curve
        # cent =
        main()
    else:
        rs.MessageBox(
            "incompatible object type (works only with curves, surfaces, polysurfaces, meshes)"
        )
Exemple #30
0
import rhinoscriptsyntax as rs

selected_objects = rs.GetObjects(
    'Select objects', rs.filter.curve + rs.filter.textdot)
print(type(selected_objects))
print('number of objects: %i' % len(selected_objects))
for object in selected_objects:
    object_type = rs.ObjectType(object)
    print('type: %s' % object_type)