示例#1
0
def generate_part_images(structure):
    global view_aspect
    w_l = conf['part_img_width']
    h_l = int(w_l / view_aspect)

    for iSub in xrange(len(structure)):
        subsystem = structure.keys()[iSub]
        v = structure[subsystem]
        utils.show_only(subsystem)
        utils.hide_children(subsystem)
        for iStep in xrange(len(v)):
            step = v.keys()[iStep]
            vv = v[step]
            stepnumeral = str(iSub + 1) + '.' + str(iStep + 1)
            rs.LayerVisible(step, True)
            for partkind, vvv in vv.items():
                rs.HideObjects(vvv)
            for partkind, vvv in vv.items():
                if len(vvv) >= 1:
                    part = vvv[0]
                    rs.ShowObject(part)
                    # create images
                    rs.RestoreNamedView(conf['persp_view'])
                    rs.ZoomExtents()
                    create_view_image(
                        conf['part_img_persp'] % (stepnumeral, partkind), w_l,
                        h_l)
                    rs.RestoreNamedView(conf['top_view'])
                    rs.ZoomExtents()
                    create_view_image(
                        conf['part_img_top'] % (stepnumeral, partkind), w_l,
                        h_l)
                    rs.RestoreNamedView(conf['front_view'])
                    rs.ZoomExtents()
                    create_view_image(
                        conf['part_img_front'] % (stepnumeral, partkind), w_l,
                        h_l)
                    rs.RestoreNamedView(conf['right_view'])
                    rs.ZoomExtents()
                    create_view_image(
                        conf['part_img_right'] % (stepnumeral, partkind), w_l,
                        h_l)
                    #
                    rs.HideObject(part)
            for partkind, vvv in vv.items():
                rs.ShowObject(vvv)
            rs.LayerVisible(step, False)
        # utils.show_children(subsystem)
        utils.show_step_children(subsystem)
    utils.show_blocks()
    utils.show_subsystems()
    rs.ZoomExtents()
示例#2
0
def create_image_set(stepnumeral, w, h):
    rs.RestoreNamedView(conf['persp_view'])
    rs.ZoomExtents()
    create_view_image(conf['step_img_persp'] % stepnumeral, w, h)
    rs.RestoreNamedView(conf['top_view'])
    rs.ZoomExtents()
    create_view_image(conf['step_img_top'] % stepnumeral, w, h)
    rs.RestoreNamedView(conf['front_view'])
    rs.ZoomExtents()
    create_view_image(conf['step_img_front'] % stepnumeral, w, h)
    rs.RestoreNamedView(conf['right_view'])
    rs.ZoomExtents()
    create_view_image(conf['step_img_right'] % stepnumeral, w, h)
示例#3
0
def export(structure):
    # create output dir if not exists
    if not os.path.exists(outdir):
        print "creating output dir: " + outdir
        os.makedirs(outdir)

    rs.CurrentLayer("Default")
    utils.show_blocks()
    utils.show_subsystems()
    rs.ZoomExtents()
    utils.hide_subsystems()
    utils.hide_non_subsystems()
    for subsystem, v in structure.items():
        utils.show_only(subsystem)
        for step, vv in v.items():
            for partkind, vvv in vv.items():
                rs.UnselectAllObjects()
                rs.SelectObjects(vvv)
                filename = utils.get_part_filename(subsystem,
                                                   utils.get_layer_tail(step),
                                                   partkind)
                outpath = os.path.join(outdir, filename)
                print "exporting step file: " + outpath
                rs.Command(
                    "_-Export " + outpath +
                    " Schema=AP214AutomotiveDesign ExportParameterSpaceCurves=Yes LetImportingApplicationSetColorForBlackObjects=Yes _Enter"
                )
示例#4
0
文件: capture.py 项目: tmshv/sisu
    def create_capture(self, view, file):
        command = self.get_command(file)

        if self.zoom_extents:
            rs.ZoomExtents(view, False)
        rs.CurrentView(view)
        rs.Command(command, False)
示例#5
0
def __undo_usertext(sender, e):
    """custom undo event - may be removed if bug in Rhino is fixed"""
    actuel = (rs.GetDocumentData("ScaleModel", "scale"),
              rs.GetDocumentData("ScaleModel", "state"))
    e.Document.AddCustomUndoEvent("Undo ScaleModel", __undo_usertext, actuel)
    old = e.Tag
    print(old)
    print("returning to %s scale" % (old[1]))
    rs.SetDocumentData("ScaleModel", "scale", old[0])
    rs.SetDocumentData("ScaleModel", "state", old[1])
    rs.ZoomExtents()
示例#6
0
def generate_step_images(structure):
    global view_aspect
    w_l = conf['step_img_width']
    h_l = int(w_l / view_aspect)
    rs.CurrentLayer("Default")
    utils.show_blocks()
    utils.show_subsystems()
    rs.ZoomExtents()
    utils.hide_subsystems()
    utils.hide_non_subsystems()

    for iSub in xrange(len(structure)):
        subsystem = structure.keys()[iSub]
        v = structure[subsystem]
        if subsystem in conf['build_apart']:
            utils.hide_subsystems()
        rs.LayerVisible(subsystem, True)
        # utils.hide_non_subsystems()
        utils.hide_children(subsystem)
        for iStep in xrange(len(v)):
            step = v.keys()[iStep]
            vv = v[step]
            stepnumeral = str(iSub + 1) + '.' + str(iStep + 1)
            rs.LayerVisible(step, True)
            rs.UnselectAllObjects()
            rs.ObjectsByLayer(step, True)
            # create images
            create_image_set(stepnumeral, w_l, h_l)
        if subsystem in conf['build_apart']:
            # show all previous subsystems again
            rs.UnselectAllObjects()
            rs.InvertSelectedObjects()
            for sub in structure.keys():
                rs.LayerVisible(sub, True)
                if sub == subsystem:
                    break
            # images for subsystem installed
            finnumeral = str(iSub + 1) + '.' + str(len(v) + 1)
            create_image_set(finnumeral, w_l, h_l)
    # subsystem overview images
    for iSub in xrange(len(structure)):
        subsystem = structure.keys()[iSub]
        rs.UnselectAllObjects()
        # select subsystem and its step layers
        for child in rs.LayerChildren(subsystem):
            rs.ObjectsByLayer(child, True)
        finnumeral = str(iSub + 1) + '.0'
        create_image_set(finnumeral, w_l, h_l)
示例#7
0
def AgiImport(dirpath, file):
    """
    Create new rhino file, import mesh, split, then save.
    """
    objPath = dirpath + '\\' + file
    if os.path.exists(objPath) == False:
        print objPath
        return

    ## Open new template file ##
    template = rs.TemplateFile()
    cmd = "-_New "
    cmd += template + " "
    rs.Command(cmd)

    cmd = "-_Import "
    cmd += '"' + os.path.abspath(objPath) + '"' + " "
    cmd += "IgnoreTextures=No "
    cmd += "MapOBJToRhinoZ=Yes "
    cmd += "_Enter "
    rs.Command(cmd)

    rs.Command("SplitDisjointMesh ")

    meshes = rs.LastCreatedObjects()
    max = 0
    keep = None
    for guid in meshes:
        mesh = rs.coercemesh(guid)
        count = mesh.Faces.Count
        if count > max:
            keep = guid
            max = count

    if keep:
        meshes.remove(keep)
    rs.DeleteObjects(meshes)

    rs.ZoomExtents(all=True)

    cmd = "-_SaveAs "
    cmd += "SaveTextures=Yes "
    cmd += '"' + os.path.abspath(objPath).replace(".obj", ".3dm") + '"' + " "
    cmd += "_Enter "
    rs.Command(cmd)
    rs.DocumentModified(False)
    Rhino.RhinoApp.Wait()
示例#8
0
#Create group
rs.AddGroup("Legs")
rs.AddObjectsToGroup(Legs, "Legs")

#Construct the table top, draw offset curve
offset_crv = rs.OffsetCurve(Poly_top,
                            Cen_top,
                            -(offset_dist),
                            normal=None,
                            style=1)

rs.CurrentLayer("Tabletop")
#extrude Offset Curve
extruded_crv = rs.ExtrudeCurve(offset_crv, extrude_path)

#cap Extruded shape
closed_polysrf = rs.CapPlanarHoles(extruded_crv)

#Delete objects
erase = [A_lines, Poly_base, Poly_top, offset_crv]
rs.DeleteObjects(erase)

#Redraw geometry
rs.EnableRedraw(True)

#zoom extents of drawn geometry
rs.ZoomExtents()

rs.CurrentLayer("Default")

print("***************Program succesful***************")
示例#9
0
# use rhinoscriptsyntax to get all the functions in one shot
import rhinoscriptsyntax as rs
import random
import time
import math
import Rhino

numCyls = rs.GetInteger("Number of sticks")
spread = rs.GetInteger("spread")

seed = rs.GetPoint("seed point")
print "seed point: ", seed[0], " / ", seed[1], " / ", seed[2]

pi = math.pi

if numCyls and spread and seed:

    for a in range(numCyls):
        x = seed[0]
        y = seed[1]
        z = seed[2]
        # points.append([seed[0], seed[1], seed[2]])
        offset = random.random() * spread
        stick = rs.AddCylinder([x + offset, y, z],
                               random.random() * 10,
                               random.random() * 0.5, True)
        rs.RotateObject(stick, seed, random.random() * 360)

    rs.ZoomExtents(view=None, all=True)
示例#10
0
def zoom_extents():
    rh.ZoomExtents(None, True)
示例#11
0
def rescale():
    # get current state and scale from DocumentData, if present or from user, if not
    print("Current Scale: 1:", rs.GetDocumentData("ScaleModel", "scale"))
    print("Current State: ", rs.GetDocumentData("ScaleModel", "state"))

    if rs.GetDocumentData("ScaleModel", "scale") and rs.GetDocumentData(
            "ScaleModel", "state"):
        scale = float(rs.GetDocumentData("ScaleModel", "scale"))
        oldechelle = scale
        state = rs.GetDocumentData("ScaleModel", "state")
        oldetat = state
    else:
        state = ""
        state = rs.ListBox(items=("Full-Scale", "Model Scale"),
                           message="Currently at what scale ?",
                           title="Scale Model",
                           default=state)
        if state is None:  # cancelled
            return
        oldetat = state
        if state == "Model Scale":
            scale = 250.
            scale = rs.GetReal("Current Scale 1:", scale, 0)
            oldechelle = scale
            if scale is None:  # cancelled
                return
        else:
            if state == "Full-Scale":
                scale = 1.
    previous_params = (str(scale), state)
    # get desired state and scale
    state = rs.ListBox(("Full-Scale", "Model Scale"),
                       "Currently %s. Choose new state" % (state), "Rescale",
                       state)
    if state == None:  # cancelled
        return

    if state == "Model Scale":
        if not scale: scale = 250.
        scale = rs.GetReal("New Scale 1:", scale, 0)
        if scale == None: return

    rs.SetDocumentData("ScaleModel", "scale", str(scale))
    rs.SetDocumentData("ScaleModel", "state", state)

    # scale geometry and dimensions
    dimstyles = rs.DimStyleNames()

    rs.EnableRedraw(False)

    if not oldetat == state:
        if state == "Full-Scale":
            rs.ScaleObjects(rs.AllObjects(), [0, 0, 0], [(scale), (scale),
                                                         (scale)])
            for dimstyle in dimstyles:
                rs.Command('_-ScaleDimstyle "' + dimstyle + '" ' + str(scale))

        else:
            rs.ScaleObjects(rs.AllObjects(), [0, 0, 0], [(1 / scale),
                                                         (1 / scale),
                                                         (1 / scale)])
            for dimstyle in dimstyles:
                rs.Command('_-ScaleDimstyle "' + dimstyle + '" ' +
                           str(1 / scale))

    else:
        if state == "Model Scale":
            rs.ScaleObjects(rs.AllObjects(), [0, 0, 0], \
                            [(oldechelle / scale), (oldechelle / scale), (oldechelle / scale)])
            for dimstyle in dimstyles:
                rs.Command('_-ScaleDimstyle "' + dimstyle + '" ' +
                           str(oldechelle / scale))
    sc.doc.AddCustomUndoEvent("Undo ScaleModel", __undo_usertext,
                              previous_params)
    print("New Scale: 1:", rs.GetDocumentData("ScaleModel", "scale"))
    print("New State: ", rs.GetDocumentData("ScaleModel", "state"))
    rs.EnableRedraw(True)

    rs.ZoomExtents(all=True)
示例#12
0
def zoom_extents():
    rs.ZoomExtents()