Пример #1
0
def get_plan_brep():
    #1. Get plan surface
    go = Rhino.Input.Custom.GetObject()
    go.GeometryFilter = Rhino.DocObjects.ObjectType.Brep

    default_thickness = sticky["defaultThickness"] if sticky.has_key(
        "defaultThickness") else 5.5
    opt_thickness = Rhino.Input.Custom.OptionDouble(default_thickness, 0.2,
                                                    1000)

    go.SetCommandPrompt(
        "Select floorplate outline surface to extract plan cuts")
    go.AddOptionDouble("FacadeThickness", opt_thickness)

    setup_GetObject(go)

    bHavePreselectedObjects = False

    while True:
        res = go.Get()
        if res == Rhino.Input.GetResult.Option:
            go.EnablePreSelect(False, True)
            continue
        elif res != Rhino.Input.GetResult.Object:
            return Rhino.Commands.Result.Cancel
        if go.ObjectsWerePreselected:
            bHavePreselectedObjects = True
            go.EnablePreSelect(False, True)
            continue
        break

    #set globals
    global THICKNESS
    THICKNESS = opt_thickness.CurrentValue
    sticky["defaultThickness"] = THICKNESS

    #Get brep representations of objects
    if go.ObjectCount != 1:
        return
    envelope_guid = go.Object(0).Object().Id

    return envelope_guid
Пример #2
0
def rc_unroll_ortho():

    go = Rhino.Input.Custom.GetObject()
    go.GeometryFilter = Rhino.DocObjects.ObjectType.Brep

    default_thickness = sticky["thickness"] if sticky.has_key(
        "thickness") else 5.5
    default_lid = sticky["lid"] if sticky.has_key("lid") else False

    opt_thickness = Rhino.Input.Custom.OptionDouble(default_thickness, 0.2,
                                                    1000)
    opt_lid = Rhino.Input.Custom.OptionToggle(default_lid, "No", "Yes")

    go.SetCommandPrompt(
        "Select breps to unroll. Breps must be orthogonal (faces at 90 degree angles)"
    )
    go.AddOptionDouble("Thickness", opt_thickness)
    go.AddOptionToggle("Lids", opt_lid)

    go.GroupSelect = True
    go.SubObjectSelect = False
    go.AcceptEnterWhenDone(True)
    go.AcceptNothing(True)
    go.EnableClearObjectsOnEntry(False)
    go.EnableUnselectObjectsOnExit(False)
    go.GroupSelect = True
    go.SubObjectSelect = False
    go.DeselectAllBeforePostSelect = False

    res = None
    bHavePreselectedObjects = False

    while True:
        res = go.GetMultiple(1, 0)

        #If new option entered, redraw a possible result
        if res == Rhino.Input.GetResult.Option:
            #print res
            go.EnablePreSelect(False, True)
            continue

        #If not correct
        elif res != Rhino.Input.GetResult.Object:
            return Rhino.Commands.Result.Cancel

        if go.ObjectsWerePreselected:
            bHavePreselectedObjects = True
            go.EnablePreSelect(False, True)
            continue

        break

    rs.EnableRedraw(False)

    LID = opt_lid.CurrentValue
    THICKNESS = opt_thickness.CurrentValue
    global LCUT_INDICES
    LCUT_INDICES = wla.get_lcut_layers()

    #Get geometry and object lists
    brep_obj_list = []
    brep_geo_list = []
    brep_ids_list = []
    for i in xrange(go.ObjectCount):
        b_obj = go.Object(i).Object()
        brep_obj_list.append(b_obj)
        #For Debug and reference...
        #brep_geo_list.append(b_obj.Geometry)
        #brep_ids_list.append(b_obj.Id)

    #get information for each piece to be output.
    #future implementation should use bounding dims and curves rather than dimension-based system.
    unrolled_brep_info = []
    lid_info = []

    SELECT_GUIDS = []
    for i, obj in enumerate(brep_obj_list):
        #geometry prep: convert extrusions to breps
        if str(obj.ObjectType) != "Brep":
            new_brep = wru.extrusion_to_brep(obj.Geometry)
        else:
            new_brep = obj.Geometry

        #pull the brep sides info for this solid
        this_brep_side_info = get_brep_sides_info(new_brep, THICKNESS)
        unrolled_brep_info.append(this_brep_side_info)
        num_sides = len(this_brep_side_info.dims)

        #pull the lid info for this solid
        if LID == True:
            this_brep_lid_info = get_brep_lid_info(new_brep, num_sides,
                                                   THICKNESS)
            lid_info.append(this_brep_lid_info)

    #get dims needed to place this solid's outline curves
    brep_output_bounding_heights = []
    for i, brep_side_info in enumerate(unrolled_brep_info):
        if LID == True:
            brep_output_bounding_heights.append(
                max(brep_side_info.boundingDims.y, lid_info[i].dims.y)
            )  #lid info needs to become a named tuple as well.
        else:
            brep_output_bounding_heights.append(brep_side_info.boundingDims.y)

    ybase = 0
    #each solid
    for i, brep_side_info in enumerate(unrolled_brep_info):
        top_label_text = wut.number_to_letter(i)
        prefix = top_label_text + "-"
        xbase = 0
        #each piece
        for j, piecedims in enumerate(brep_side_info.dims):
            face_label = prefix + str(brep_side_info.labelNums[j])
            rect = rs.AddRectangle([xbase, ybase, 0], piecedims.x, piecedims.y)
            dot = rs.AddTextDot(face_label, rs.CurveAreaCentroid(rect)[0])

            rs.ObjectLayer(dot, "XXX_LCUT_00-GUIDES")
            rs.ObjectLayer(rect, "XXX_LCUT_01-CUT")
            SELECT_GUIDS.extend([rect, dot])
            xbase += piecedims[0] + GAP_SIZE

        #add the lids
        if LID == True:

            #transform the lid curve to the basepoint
            lid_curve = lid_info[i].outline
            p1 = rs.WorldXYPlane()
            p2 = rs.PlaneFromNormal([xbase, ybase, 0], [0, 0, 1], [1, 0, 0])
            orient = Rhino.Geometry.Transform.ChangeBasis(
                rs.coerceplane(p2), rs.coerceplane(p1))
            lid_curve.Transform(orient)

            #add the curve to the document
            crv_1 = wru.add_curve_to_layer(lid_curve, LCUT_INDICES[1])
            crv_2 = rs.CopyObject(
                crv_1, [lid_info[i].dims.x + GAP_SIZE, 0, 0
                        ])  #change this to use a transform; it's nasty.

            #add text dot
            face_label_1 = prefix + str(len(brep_side_info.dims))
            face_label_2 = prefix + str(len(brep_side_info.dims) + 1)
            dot_1 = rs.AddTextDot(face_label_1, rs.CurveAreaCentroid(crv_1)[0])
            dot_2 = rs.AddTextDot(face_label_2, rs.CurveAreaCentroid(crv_2)[0])
            rs.ObjectLayer([dot_1, dot_2], "XXX_LCUT_00-GUIDES")

            SELECT_GUIDS.extend([crv_1, crv_2, dot_1, dot_2])

        top_label = rs.AddTextDot(top_label_text, brep_side_info.topLabelPt)
        rs.ObjectLayer(top_label, "XXX_LCUT_00-GUIDES")
        ybase += brep_output_bounding_heights[i] + GAP_SIZE * 4

    sticky["thickness"] = THICKNESS
    sticky["lid"] = LID

    rs.UnselectAllObjects()
    rs.SelectObjects(SELECT_GUIDS)
    rs.Redraw()
    rs.EnableRedraw(True)
Пример #3
0
def rc_plot_volumes(use_epsilon):

    go = Rhino.Input.Custom.GetObject()
    go.GeometryFilter = Rhino.DocObjects.ObjectType.Brep

    default_inplaceBool = sticky["inplaceBool"] if sticky.has_key(
        "inplaceBool") else False
    default_heightsBool = sticky["heightsBool"] if sticky.has_key(
        "heightsBool") else False

    opt_inplace = Rhino.Input.Custom.OptionToggle(default_inplaceBool, "No",
                                                  "Yes")
    opt_heights = Rhino.Input.Custom.OptionToggle(default_heightsBool, "No",
                                                  "Yes")

    go.SetCommandPrompt("Select breps to extract plan cuts")
    go.AddOptionToggle("InPlace", opt_inplace)
    go.AddOptionToggle("PrintPieceHeights", opt_heights)

    go.GroupSelect = True
    go.SubObjectSelect = False
    go.AcceptEnterWhenDone(True)
    go.AcceptNothing(True)
    go.EnableClearObjectsOnEntry(False)
    go.EnableUnselectObjectsOnExit(False)
    go.GroupSelect = True
    go.SubObjectSelect = False
    go.DeselectAllBeforePostSelect = False

    res = None
    bHavePreselectedObjects = False

    while True:
        res = go.GetMultiple(1, 0)
        #If new option entered, redraw a possible result
        if res == Rhino.Input.GetResult.Option:
            # print res
            go.EnablePreSelect(False, True)
            continue
        #If not correct
        elif res != Rhino.Input.GetResult.Object:
            return Rhino.Commands.Result.Cancel
        if go.ObjectsWerePreselected:
            bHavePreselectedObjects = True
            go.EnablePreSelect(False, True)
            continue
        break

    rs.EnableRedraw(False)

    DIRPT1 = rs.coerce3dpoint([0, 0, 0])
    DIRPT2 = rs.coerce3dpoint([1, 0.001, 0])
    global BOOL_HEIGHTS
    global LCUT_INDICES
    global SORTDIR
    BOOL_HEIGHTS = opt_heights.CurrentValue
    LCUT_INDICES = wla.get_lcut_layers()
    SORTDIR = DIRPT2 - DIRPT1

    #Get boolean for "inplace"
    INPLACE = opt_inplace.CurrentValue

    #Get brep representations of objects
    brep_geo_list = []
    for i in xrange(go.ObjectCount):
        b_obj = go.Object(i).Object()
        brep_geo_list.append(b_obj.Geometry)

    #...brep conversion may be necessary
    new_brep_list = []
    for i, geo in enumerate(brep_geo_list):
        if geo.GetType() != Rhino.Geometry.Brep:
            new_brep_list.append(wru.extrusion_to_brep(geo))
        else:
            new_brep_list.append(geo)

    #set base for output.
    xbase = 0
    ybase = 0
    #set the amount to move up from the bottom of the brep for cutting the lower outline.
    #this should be replaced by a projection of the bottom face of the brep.
    epsilon = D_TOL * 2

    select_items = []

    centroids = [
        c.GetBoundingBox(rs.WorldXYPlane()).Center for c in new_brep_list
    ]
    brep_collection = zip(centroids, new_brep_list)
    brep_collection = sorted(brep_collection, sortcompare)
    _, new_brep_list = zip(*brep_collection)

    for i, brep in enumerate(new_brep_list):
        #get lowest curve info

        #get label prefix and bounding dims for this brep
        bdims = wge.get_bounding_dims(brep)
        baseplane = rs.MovePlane(rs.WorldXYPlane(), [xbase, ybase, 0])
        label_letter = wut.number_to_letter(i)

        #prepare heights and labels for each section cut
        num_sections = 1
        remaining_thickness = 0
        cuts_at = [epsilon] if use_epsilon else [0]
        brep_label = label_letter
        section_labels = [label_letter]

        if BOOL_HEIGHTS == True:
            section_labels = [
                label + "\n" + str(round(bdims.Z, 1))
                for label in section_labels
            ]

        #get section information for each cut
        section_planes = get_brep_section_planes(brep, cuts_at)

        section_curves, section_dims = [[], []]
        for i, plane in enumerate(section_planes):
            curve, dims = [0, 0]
            if (not use_epsilon) and (i == 0):
                curve, dims = get_lowest_curve_info(brep, D_TOL * 2)
            else:
                curve, dims = get_section_curve_info_multi_no_ortho(
                    brep, plane)
            section_curves.append(curve)
            section_dims.append(dims)

        ##DO WORK HERE##
        drawing_planes = get_drawing_planes(section_dims, baseplane, GAP_SIZE)

        #place curves in drawing location
        for sp, dp, sc in zip(section_planes, drawing_planes, section_curves):
            if INPLACE == True:
                t = Rhino.Geometry.Transform.Translation(0, 0, 0)
            else:
                t = Rhino.Geometry.Transform.ChangeBasis(dp, sp)
            for c in sc:
                c.Transform(t)

        #THIS IS STILL A MESS: LABEL ADDING
        #draw curves and add text dots
        top_label_pt = get_brep_label_pt(brep)
        brep_textdot = rs.AddTextDot(brep_label, top_label_pt)
        rs.ObjectLayer(brep_textdot, "XXX_LCUT_00-GUIDES")

        label_pts = []
        for sc, label in zip(section_curves, section_labels):
            for i, c in enumerate(sc):
                crv = wru.add_curve_to_layer(c, LCUT_INDICES[1])
                select_items.append(crv)
                if i == 0:
                    label_pts.append(rs.CurveAreaCentroid(crv)[0])

        fab_tags = wfa.add_fab_tags(label_pts, section_labels, TEXTSIZE)
        for tag in fab_tags:
            rs.ObjectLayer(tag, "XXX_LCUT_02-SCORE")
            group_name = rs.AddGroup()
            rs.AddObjectsToGroup(tag, group_name)
        ybase += max([s.Y for s in section_dims]) + GAP_SIZE * 1

        for tag in fab_tags:
            select_items.extend(tag)

    sticky["inplaceBool"] = INPLACE
    sticky["heightsBool"] = BOOL_HEIGHTS

    rs.UnselectAllObjects()
    rs.SelectObjects(select_items)
    rs.Redraw()
    rs.EnableRedraw(True)
Пример #4
0
def rc_layer_change():
    #get stickies
    default_layer_ind = sticky["defaultLayer"] if sticky.has_key(
        "defaultLayer") else 1
    default_opt_copy = sticky["defaultCopyOpt"] if sticky.has_key(
        "defaultCopyOpt") else False
    go = Rhino.Input.Custom.GetObject()
    go.GeometryFilter = Rhino.DocObjects.ObjectType.Curve
    opt_copy = Rhino.Input.Custom.OptionToggle(default_opt_copy, "No", "Yes")

    #Index is used for layer change.
    list_vals = ["Guides", "Cut", "Score", "LightScore", "Engrave"]
    opt_list = go.AddOptionList("DestinationLayer", list_vals,
                                default_layer_ind)
    go.SetCommandPrompt(
        "Select curves to move to layer or press Enter to add lasercut layers to document"
    )
    go.AddOptionToggle("CopyCurves", opt_copy)
    #go.AddOptionDouble("InnerThickness", opt_inner)

    go.GroupSelect = True
    go.SubObjectSelect = False
    go.AcceptEnterWhenDone(True)
    go.AcceptNothing(True)
    go.EnableClearObjectsOnEntry(False)
    go.EnableUnselectObjectsOnExit(False)
    go.GroupSelect = True
    go.SubObjectSelect = False
    go.DeselectAllBeforePostSelect = False

    res = None
    bHavePreselectedObjects = False
    while True:
        res = go.GetMultiple(1, 0)

        #If new option entered, redraw a possible result
        if res == Rhino.Input.GetResult.Option:
            go.EnablePreSelect(False, True)
            if go.OptionIndex() == opt_list:
                default_layer_ind = go.Option().CurrentListOptionIndex
            continue

        elif res == Rhino.Input.GetResult.Nothing:
            MANUAL = True
            get_lcut_layers()
            return None

        #If not correct
        elif res != Rhino.Input.GetResult.Object:
            return Rhino.Commands.Result.Cancel

        if go.ObjectsWerePreselected:
            bHavePreselectedObjects = True
            go.EnablePreSelect(False, True)
            continue

        break

    #option results
    DESTINATION_LAYER = list_vals[default_layer_ind]
    COPY_ORIGINALS = opt_copy.CurrentValue

    get_lcut_layers()

    #selected curve objects
    c_ids_list = []
    for i in xrange(go.ObjectCount):
        c_obj = go.Object(i).Object()
        c_ids_list.append(c_obj.Id)

    switcher = {
        0: "XXX_LCUT_00-GUIDES",
        1: "XXX_LCUT_01-CUT",
        2: "XXX_LCUT_02-SCORE",
        3: "XXX_LCUT_03-LSCORE",
        4: "XXX_LCUT_04-ENGRAVE",
    }

    sticky["defaultLayer"] = default_layer_ind
    sticky["defaultCopyOpt"] = COPY_ORIGINALS

    changed_crvs = change_object_layers(c_ids_list,
                                        switcher[default_layer_ind],
                                        COPY_ORIGINALS)
    rs.UnselectAllObjects()
    rs.SelectObjects(changed_crvs)
Пример #5
0
def rc_unroll_ortho():
	
	go = Rhino.Input.Custom.GetObject()
	go.GeometryFilter = Rhino.DocObjects.ObjectType.Brep
	
	default_thickness = sticky["thickness"] if sticky.has_key("thickness") else 5.5
	default_lid = sticky["lid"] if sticky.has_key("lid") else False
	
	opt_thickness = Rhino.Input.Custom.OptionDouble(default_thickness,0.2,1000)
	opt_lid = Rhino.Input.Custom.OptionToggle(default_lid,"No","Yes")

	go.SetCommandPrompt("Select breps to unroll. Breps must be orthogonal (faces at 90 degree angles)")
	go.AddOptionDouble("Thickness", opt_thickness)
	go.AddOptionToggle("Lids", opt_lid)

	go.GroupSelect = True
	go.SubObjectSelect = False
	go.AcceptEnterWhenDone(True)
	go.AcceptNothing(True)
	go.EnableClearObjectsOnEntry(False)
	go.EnableUnselectObjectsOnExit(False)
	go.GroupSelect = True
	go.SubObjectSelect = False
	go.DeselectAllBeforePostSelect = False

	res = None
	bHavePreselectedObjects = False

	while True:
		res = go.GetMultiple(1,0)

		#If new option entered, redraw a possible result
		if res == Rhino.Input.GetResult.Option:
			#print res
			go.EnablePreSelect(False, True)
			continue

		#If not correct
		elif res != Rhino.Input.GetResult.Object:
			return Rhino.Commands.Result.Cancel

		if go.ObjectsWerePreselected:
			bHavePreselectedObjects = True
			go.EnablePreSelect(False, True)
			continue

		break

	rs.EnableRedraw(False)

	LID = opt_lid.CurrentValue
	global LCUT_INDICES, THICKNESS
	THICKNESS = opt_thickness.CurrentValue
	LCUT_INDICES = wla.get_lcut_layers()

	#Get geometry and object lists
	brep_obj_list = []
	brep_geo_list = []
	brep_ids_list = []
	for i in xrange(go.ObjectCount):
		b_obj = go.Object(i).Object()
		brep_obj_list.append(b_obj)
	
	#use world cplane
	current_cplane = sc.doc.Views.ActiveView.ActiveViewport.GetConstructionPlane()
	temp_cplane = current_cplane.Plane
	current_cplane.Plane = rs.WorldXYPlane()
	
	#get information for each piece to be output.
	#future implementation should use bounding dims and curves rather than dimension-based system.
	unrolled_brep_info = []
	lid_info = []
	
	SELECT_GUIDS = []
	
	#convert to breps
	input_brep_geo = []
	for i,obj in enumerate(brep_obj_list):
		#geometry prep: convert extrusions to breps
		if str(obj.ObjectType) != "Brep":
			new_brep = wru.extrusion_to_brep(obj.Geometry)
		else:
			new_brep = obj.Geometry
		input_brep_geo.append(new_brep)
	
	for geo in input_brep_geo:
		unroll_brep_with_thickness(geo)
	
	
	sticky["thickness"] = THICKNESS
	sticky["lid"] = LID
	
	current_cplane.Plane = temp_cplane
	rs.UnselectAllObjects()
	rs.SelectObjects(SELECT_GUIDS)
	rs.Redraw()
	rs.EnableRedraw(True)
Пример #6
0
def rc_Bridge():
    #get stickies
    default_bridge_size = sticky["defaultSize"] if sticky.has_key(
        "defaultSize") else 2
    default_bridge_border = sticky["defaultBorder"] if sticky.has_key(
        "defaultBorder") else 2
    default_bynum_bool = sticky["defaultByNum"] if sticky.has_key(
        "defaultByNum") else True

    go = Rhino.Input.Custom.GetObject()
    go.GeometryFilter = Rhino.DocObjects.ObjectType.Curve
    go.GeometryAttributeFilter = Rhino.Input.Custom.GeometryAttributeFilter.ClosedCurve

    opt_bridge_size = Rhino.Input.Custom.OptionDouble(default_bridge_size, 0.2,
                                                      1000)
    opt_bridge_border = Rhino.Input.Custom.OptionDouble(
        default_bridge_border, 0.2, 1000)
    opt_by_num = Rhino.Input.Custom.OptionToggle(default_bynum_bool,
                                                 "ByLength", "ByNumber")

    go.SetCommandPrompt("Select Curves for Bridging")
    go.AddOptionDouble("BridgeSize", opt_bridge_size)
    go.AddOptionDouble("BridgeBorder", opt_bridge_border)
    out_mode = go.AddOptionToggle("Mode", opt_by_num)

    go.GroupSelect = True
    go.SubObjectSelect = False
    go.AcceptEnterWhenDone(True)
    go.AcceptNothing(True)
    go.EnableClearObjectsOnEntry(False)
    go.EnableUnselectObjectsOnExit(False)
    go.GroupSelect = True
    go.SubObjectSelect = False
    go.DeselectAllBeforePostSelect = False

    res = None
    bHavePreselectedObjects = False

    while True:
        res = go.GetMultiple(1, 0)

        #If new option entered, redraw a possible result
        if res == Rhino.Input.GetResult.Option:
            # print res
            go.EnablePreSelect(False, True)
            continue

        #If not correct
        elif res != Rhino.Input.GetResult.Object:
            return Rhino.Commands.Result.Cancel

        if go.ObjectsWerePreselected:
            bHavePreselectedObjects = True
            go.EnablePreSelect(False, True)
            continue

        break

    CUT_LENGTH = opt_bridge_size.CurrentValue
    CUT_TOL = opt_bridge_border.CurrentValue
    BY_NUM = opt_by_num.CurrentValue

    #get properties of objects
    crv_max_length = 0
    crv_obj_list = []
    for i in xrange(go.ObjectCount):
        c_obj = go.Object(i).Object()
        crv_obj_list.append(c_obj)
        if i == 0:
            crv_max_length = c_obj.CurveGeometry.Domain.Mid
        else:
            crv_max_length = min(crv_max_length,
                                 c_obj.CurveGeometry.Domain.Mid)

    #add bridges by length or by number.
    if BY_NUM == True:
        default_segmentCount = sticky["defaultSegmentCount"] if sticky.has_key(
            "defaultSegmentCount") else 2

        rc, segment_count = Rhino.Input.RhinoGet.GetInteger(
            "Divide curves into how many segments?", True,
            default_segmentCount, 2, 500)
        if rc != Rhino.Commands.Result.Success:
            return rc
        m_addBridges(crv_obj_list, segment_count)
        sticky["defaultSegmentCount"] = segment_count
    else:
        default_segmentLength = sticky["defaultSegLength"] if (
            sticky.has_key("defaultSegLength")
            and sticky["defaultSegLength"] < crv_max_length
        ) else crv_max_length / 2
        s = "What approximate length would you like to target? The maximum for these curves is {0:.2f}".format(
            crv_max_length)
        rc, segment_length = Rhino.Input.RhinoGet.GetNumber(
            s, False, default_segmentLength, 0, crv_max_length)
        if rc != Rhino.Commands.Result.Success:
            return rc
        m_addBridges(crv_obj_list, segment_length, False)
        sticky["defaultSegLen"] = segment_length

    #display the bridges and request options.
    go = Rhino.Input.Custom.GetOption()
    opt_bridge_size = Rhino.Input.Custom.OptionDouble(CUT_LENGTH, 0.2, 1000)
    opt_bridge_border = Rhino.Input.Custom.OptionDouble(CUT_TOL, 0.2, 1000)

    go.SetCommandPrompt("Adjust Options. Enter to Continue.")
    go.AddOptionDouble("BridgeSize", opt_bridge_size)
    go.AddOptionDouble("BridgeBorder", opt_bridge_border)
    go.AcceptEnterWhenDone(True)
    go.AcceptNothing(True)

    #draw the preview.
    buffer_distance = CUT_LENGTH + CUT_TOL
    m_manage_discons(crv_obj_list, buffer_distance)
    preview_layers = m_showBridges(crv_obj_list, CUT_LENGTH, CUT_TOL)
    rs.Redraw()
    while True:
        res = go.Get()

        #If new option entered, redraw a possible result
        if res == Rhino.Input.GetResult.Option:
            for layer_ind in preview_layers:
                Rhino.DocObjects.Tables.LayerTable.Purge(
                    doc.ActiveDoc.Layers, layer_ind, True)
            CUT_LENGTH = opt_bridge_size.CurrentValue
            CUT_TOL = opt_bridge_border.CurrentValue
            buffer_distance = CUT_LENGTH + CUT_TOL
            m_manage_discons(crv_obj_list, buffer_distance)
            preview_layers = m_showBridges(crv_obj_list, CUT_LENGTH, CUT_TOL)
            rs.Redraw()
            continue

        #If not correct
        elif res == Rhino.Input.GetResult.Nothing:
            for layer_ind in preview_layers:
                doc.ActiveDoc.Layers
                Rhino.DocObjects.Tables.LayerTable.Purge(
                    doc.ActiveDoc.Layers, layer_ind, True)
            break

        for layer_ind in preview_layers:
            doc.ActiveDoc.Layers
            Rhino.DocObjects.Tables.LayerTable.Purge(doc.ActiveDoc.Layers,
                                                     layer_ind, True)
        return Rhino.Commands.Result.Failure

        break

    CUT_LENGTH = opt_bridge_size.CurrentValue
    CUT_TOL = opt_bridge_border.CurrentValue

    #Request output options.
    m_makeBridgeLines(crv_obj_list, CUT_LENGTH)

    sticky["defaultSize"] = CUT_LENGTH
    sticky["defaultBorder"] = CUT_TOL
    sticky["defaultByNum"] = BY_NUM
    return Rhino.Commands.Result.Success
Пример #7
0
def m_makeBridgeLines(crv_obj_list, cut_length):

    default_groupWithin = sticky["defaultGroupWithin"] if sticky.has_key(
        "defaultGroupWithin") else False
    default_groupBetween = sticky["defaultGroupBetween"] if sticky.has_key(
        "defaultGroupBetween") else False
    default_delete = sticky["defaultDelete"] if sticky.has_key(
        "defaultDelete") else False

    go = Rhino.Input.Custom.GetOption()
    opt_groupWithin = Rhino.Input.Custom.OptionToggle(default_groupWithin,
                                                      "No", "Yes")
    opt_groupBetween = Rhino.Input.Custom.OptionToggle(default_groupBetween,
                                                       "No", "Yes")
    opt_delete = Rhino.Input.Custom.OptionToggle(default_delete, "No", "Yes")

    go.SetCommandPrompt("Select Output Options")
    go.AddOptionToggle("GroupBetween", opt_groupBetween)
    go.AddOptionToggle("GroupWithin", opt_groupWithin)
    go.AddOptionToggle("DeleteOriginals", opt_delete)

    go.AcceptEnterWhenDone(True)
    go.AcceptNothing(True)

    res = None
    bHavePreselectedObjects = False

    while True:
        res = go.Get()

        #If new option entered, redraw a possible result
        if res == Rhino.Input.GetResult.Option:
            #print res
            continue

        #If not correct
        elif res == Rhino.Input.GetResult.Nothing:
            break

        return Rhino.Commands.Result.Failure

        break

    #Get geometry and object lists
    crv_geo_list = [x.CurveGeometry for x in crv_obj_list]

    l_index_cut = add_layer("XXX_LCUT_01-CUT", sd.Color.Red)
    l_index_score = add_layer("XXX_LCUT_02-SCORE", sd.Color.Blue)

    #MAIN GEOMETRY HANDLING. TO FUNCTION THIS OUT.
    fragment_guids = []
    for crv_obj, crv_geo in zip(crv_obj_list, crv_geo_list):
        bridge_params = retrieve_bridge_params(crv_obj, "lc_bridge_param")

        crv_bounds = (0, crv_obj.CurveGeometry.Domain.T1)
        sdoms = get_centered_subdomains(crv_bounds, bridge_params, cut_length)

        bridge_fragments = []
        #get little pieces... to add a loop to do big pieces. this currently might leave us with split-up fragments in places; may need to add a join command if two splits are made per pt.
        for pt in sdoms:
            for dom in pt:
                subcurve = []
                splitcurves = crv_geo.Split(dom[0])
                #if looped domain
                if dom[1] < dom[0]:
                    for crv in splitcurves:
                        if (abs(crv.Domain.T0 - dom[0])) < D_TOL:
                            subcurve.append(crv)
                        else:
                            newSplit = crv.Split(dom[1])
                            subcurve.append(newSplit[0])
                else:
                    for crv in splitcurves:
                        if (abs(crv.Domain.T0 - dom[0])) < D_TOL:
                            newSplit = crv.Split(dom[1])
                            subcurve.append(newSplit[0])
            bridge_fragments.extend(subcurve)

        #similar iteration through the complement domains. one fewer layer of depth because there are no sdoms split at the seam points (see if this is robust)
        c_sdoms = get_complement_domains(sdoms)
        cut_fragments = []
        for dom in c_sdoms:
            subcurve = []
            splitcurves = crv_geo.Split(dom[0])
            #if looped domain
            if dom[1] < dom[0]:
                for crv in splitcurves:
                    if (abs(crv.Domain.T0 - dom[0])) < D_TOL:
                        subcurve.append(crv)
                    else:
                        newSplit = crv.Split(dom[1])
                        subcurve.append(newSplit[0])
            else:
                for crv in splitcurves:
                    if (abs(crv.Domain.T0 - dom[0])) < D_TOL:
                        newSplit = crv.Split(dom[1])
                        #print newSplit
                        subcurve.append(newSplit[0])
            cut_fragments.extend(subcurve)

        thiscurve_fragments = []
        for item in cut_fragments:
            temp = item
            thiscurve_fragments.append(add_curve_to_layer(item, l_index_cut))
        for item in bridge_fragments:
            thiscurve_fragments.append(add_curve_to_layer(item, l_index_score))

        if opt_groupWithin.CurrentValue == True:
            sc.doc.Groups.Add(thiscurve_fragments)

        fragment_guids.extend(thiscurve_fragments)

    if opt_groupBetween.CurrentValue == True:
        sc.doc.Groups.Add(fragment_guids)

    rs.UnselectAllObjects()
    rs.SelectObjects(fragment_guids)
    sc.doc.Views.Redraw()

    sticky["defaultGroupWithin"] = opt_groupWithin.CurrentValue
    sticky["defaultGroupBetween"] = opt_groupBetween.CurrentValue
    sticky["defaultDelete"] = opt_delete.CurrentValue

    if opt_delete.CurrentValue == True:
        ids = [x.Id for x in crv_obj_list]
        rs.DeleteObjects(ids)
Пример #8
0
def rc_getinput():

    go = Rhino.Input.Custom.GetObject()
    go.GeometryFilter = Rhino.DocObjects.ObjectType.Brep

    default_thickness = sticky["Thickness"] if sticky.has_key(
        "Thickness") else 2
    default_borderThickness = sticky["borderThickness"] if sticky.has_key(
        "borderThickness") else 10
    default_borderBool = sticky["borderBool"] if sticky.has_key(
        "borderBool") else False

    opt_thickness = Rhino.Input.Custom.OptionDouble(default_thickness, 0.2,
                                                    1000)
    opt_borderthickness = Rhino.Input.Custom.OptionDouble(
        default_borderThickness, 0.2, 1000)
    opt_border = Rhino.Input.Custom.OptionToggle(default_borderBool, "No",
                                                 "Yes")

    go.SetCommandPrompt(
        "Select terrain surface. (Note: Border Mode is in beta and may fail)")
    go.AddOptionDouble("MaterialThickness", opt_thickness)
    go.AddOptionDouble("BorderThickness", opt_borderthickness)
    go.AddOptionToggle("Border", opt_border)

    go.GroupSelect = True
    go.SubObjectSelect = False
    go.AcceptEnterWhenDone(True)
    go.EnableClearObjectsOnEntry(False)
    go.EnableUnselectObjectsOnExit(False)
    go.GroupSelect = True
    go.SubObjectSelect = False
    go.DeselectAllBeforePostSelect = False

    res = None
    bHavePreselectedObjects = False

    while True:
        res = go.Get()
        #If new option entered, redraw a possible result
        if res == Rhino.Input.GetResult.Option:
            go.EnablePreSelect(False, True)
            continue
        #If not correct
        elif res != Rhino.Input.GetResult.Object:
            return Rhino.Commands.Result.Cancel
        if go.ObjectsWerePreselected:
            bHavePreselectedObjects = True
            go.EnablePreSelect(False, True)
            continue
        break

    #rs.EnableRedraw(False)
    global THICKNESS
    THICKNESS = opt_thickness.CurrentValue
    global BORDER_THICKNESS
    BORDER_THICKNESS = opt_borderthickness.CurrentValue
    global BORDER_BOOL
    BORDER_BOOL = opt_border.CurrentValue
    global LCUT_INDICES
    LCUT_INDICES = wla.get_lcut_layers()

    #set guides
    global SHORT_GUIDE, LONG_GUIDE
    SHORT_GUIDE = rs.AddLine([0, 0, 0], [0, 0, -THICKNESS])
    LONG_GUIDE = rs.AddLine([0, 0, 0], [0, 0, -THICKNESS * 4])
    rs.LockObjects([SHORT_GUIDE, LONG_GUIDE])

    #set layers
    global LCUT_IND
    LCUT_IND = wla.get_lcut_layers()

    #get topography object
    brep_obj = go.Object(0).Object()

    sticky["Thickness"] = THICKNESS
    sticky["borderThickness"] = BORDER_THICKNESS
    sticky["borderBool"] = BORDER_BOOL

    rs.LockObject(brep_obj.Id)
    building_brep_guids = rs.GetObjects("Select breps representing buildings",
                                        filter=16)
    engraving_crv_guids = rs.GetObjects("Select curves to engrave on terrain",
                                        filter=4)
    rs.UnlockObject(brep_obj.Id)

    return brep_obj, building_brep_guids, engraving_crv_guids
Пример #9
0
def rc_plot_volumes(use_epsilon):
    #get sticky
    default_thickness = sticky["defaultThickness"] if sticky.has_key(
        "defaultThickness") else 5.5

    go = Rhino.Input.Custom.GetObject()
    go.GeometryFilter = Rhino.DocObjects.ObjectType.Brep

    opt_thickness = Rhino.Input.Custom.OptionDouble(default_thickness, 0.2,
                                                    1000)
    opt_sections = Rhino.Input.Custom.OptionToggle(False, "No", "Yes")
    opt_inplace = Rhino.Input.Custom.OptionToggle(False, "No", "Yes")
    opt_heights = Rhino.Input.Custom.OptionToggle(False, "No", "Yes")

    go.SetCommandPrompt("Select breps to extract plan cuts")
    go.AddOptionDouble("Thickness", opt_thickness)

    go.GroupSelect = True
    go.SubObjectSelect = False
    go.AcceptEnterWhenDone(True)
    go.AcceptNothing(True)
    go.EnableClearObjectsOnEntry(False)
    go.EnableUnselectObjectsOnExit(False)
    go.GroupSelect = True
    go.SubObjectSelect = False
    go.DeselectAllBeforePostSelect = False

    res = None
    bHavePreselectedObjects = False

    while True:
        res = go.GetMultiple(1, 0)
        #If new option entered, redraw a possible result
        if res == Rhino.Input.GetResult.Option:
            # print res
            go.EnablePreSelect(False, True)
            continue
        #If not correct
        elif res != Rhino.Input.GetResult.Object:
            return Rhino.Commands.Result.Cancel
        if go.ObjectsWerePreselected:
            bHavePreselectedObjects = True
            go.EnablePreSelect(False, True)
            continue
        break

    rs.EnableRedraw(False)

    global THICKNESS
    THICKNESS = opt_thickness.CurrentValue

    global LCUT_INDICES
    LCUT_INDICES = wla.get_lcut_layers()

    #Get brep representations of objects
    brep_geo_list = []
    for i in xrange(go.ObjectCount):
        b_obj = go.Object(i).Object()
        brep_geo_list.append(b_obj.Geometry)

    #...brep conversion may be necessary
    new_brep_list = []
    for i, geo in enumerate(brep_geo_list):
        if geo.GetType() != Rhino.Geometry.Brep:
            new_brep_list.append(wru.extrusion_to_brep(geo))
        else:
            new_brep_list.append(geo)

    #set base for output.
    xbase = 0
    ybase = 0
    #set the amount to move up from the bottom of the brep for cutting the lower outline.
    #this should be replaced by a projection of the bottom face of the brep.
    epsilon = D_TOL * 2

    select_items = []
    for i, brep in enumerate(new_brep_list):

        #get label prefix and bounding dims for this brep
        bdims = wge.get_bounding_dims(brep)
        baseplane = rs.MovePlane(rs.WorldXYPlane(), [xbase, ybase, 0])
        label_letter = wut.number_to_letter(i)
        label_prefix = label_letter + "-"

        #prepare heights and labels for each section cut
        num_sections = 1
        remaining_thickness = 0
        cuts_at = [epsilon] if use_epsilon else [0]
        brep_label = label_letter
        section_labels = [label_letter]

        num_sections, remaining_thickness, cuts_at = get_section_division(
            bdims.Z, THICKNESS)
        if use_epsilon: cuts_at[0] = epsilon
        brep_label = label_letter + " r: " + str(round(remaining_thickness, 2))
        section_labels = [label_prefix + str(i) for i in xrange(len(cuts_at))]

        #get section information for each cut
        section_planes = get_brep_section_planes(brep, cuts_at)

        #get lowest curve info
        section_curves, section_dims = [[], []]
        for i, plane in enumerate(section_planes):
            curve, dims = [0, 0]
            if (not use_epsilon) and (i == 0):
                curve, dims = get_lowest_curve_info(brep, D_TOL * 2)
            else:
                curve, dims = get_section_curve_info_multi_no_ortho(
                    brep, plane)
            section_curves.append(curve)
            section_dims.append(dims)

        ##DO WORK HERE##
        drawing_planes = get_drawing_planes(section_dims, baseplane, GAP_SIZE)

        #place curves in drawing location
        for sp, dp, sc in zip(section_planes, drawing_planes, section_curves):
            t = Rhino.Geometry.Transform.ChangeBasis(dp, sp)
            for c in sc:
                c.Transform(t)

        #THIS IS STILL A MESS: LABEL ADDING
        #draw curves and add text dots
        top_label_pt = get_brep_label_pt(brep)
        brep_textdot = rs.AddTextDot(brep_label, top_label_pt)
        rs.ObjectLayer(brep_textdot, "XXX_LCUT_00-GUIDES")

        label_pts = []
        for sc, label in zip(section_curves, section_labels):
            temp_area = 0
            for i, c in enumerate(sc):
                crv = wru.add_curve_to_layer(c, LCUT_INDICES[1])
                select_items.append(crv)
                if i == 0:
                    label_pts.append(rs.CurveAreaCentroid(crv)[0])
                    temp_area = rs.CurveArea(crv)
                else:
                    if rs.CurveArea(crv) > temp_area:
                        label_pts[-1] = rs.CurveAreaCentroid(crv)[0]
                        temp_area = rs.CurveArea(crv)

        fab_tags = wfa.add_fab_tags(label_pts, section_labels, TEXTSIZE)
        for tag in fab_tags:
            rs.ObjectLayer(tag, "XXX_LCUT_02-SCORE")
            group_name = rs.AddGroup()
            rs.AddObjectsToGroup(tag, group_name)

        ybase += max([s.Y for s in section_dims]) + GAP_SIZE * 1

        for tag in fab_tags:
            select_items.extend(tag)
        #THIS IS STILL A MESS: LABEL ADDING

    sticky["defaultThickness"] = THICKNESS

    rs.UnselectAllObjects()
    rs.SelectObjects(select_items)
    rs.Redraw()
    rs.EnableRedraw(True)
Пример #10
0
def rc_shl_box():
    #get stickies
    default_inner_thickness = sticky["defaultInThickness"] if sticky.has_key(
        "defaultInThickness") else 5.5
    default_outer_thickness = sticky["defaultOutThickness"] if sticky.has_key(
        "defaultOutThickness") else 2

    go = Rhino.Input.Custom.GetObject()
    go.GeometryFilter = Rhino.DocObjects.ObjectType.Brep

    opt_inner = Rhino.Input.Custom.OptionDouble(default_inner_thickness, 0.2,
                                                1000)
    opt_outer = Rhino.Input.Custom.OptionDouble(default_outer_thickness, 0.2,
                                                1000)

    go.SetCommandPrompt(
        "Select breps to be boxed or press Enter for manual dimensioning (Suggested: Inner 5.5, Outer 2)"
    )
    go.AddOptionDouble("InnerThickness", opt_inner)
    go.AddOptionDouble("OuterThickness", opt_outer)

    go.GroupSelect = True
    go.SubObjectSelect = False
    go.AcceptEnterWhenDone(True)
    go.AcceptNothing(True)
    go.EnableClearObjectsOnEntry(False)
    go.EnableUnselectObjectsOnExit(False)
    go.GroupSelect = True
    go.SubObjectSelect = False
    go.DeselectAllBeforePostSelect = False

    res = None
    bHavePreselectedObjects = False

    MANUAL = False
    while True:
        res = go.GetMultiple(1, 0)

        #If new option entered, redraw a possible result
        if res == Rhino.Input.GetResult.Option:
            # print res
            go.EnablePreSelect(False, True)
            continue
        elif res == Rhino.Input.GetResult.Nothing:
            MANUAL = True
        #If not correct
        elif res != Rhino.Input.GetResult.Object:
            return Rhino.Commands.Result.Cancel

        if go.ObjectsWerePreselected:
            bHavePreselectedObjects = True
            go.EnablePreSelect(False, True)
            continue

        break

    #set globals according to input
    T_IBOX = opt_inner.CurrentValue
    T_OBOX = opt_outer.CurrentValue

    rs.EnableRedraw(False)

    if MANUAL == False:
        #Get dimensions from geometry and object lists
        brep_obj_list = []  #not used but left in for reference
        brep_ids_list = []
        for i in xrange(go.ObjectCount):
            b_obj = go.Object(i).Object()
            brep_obj_list.append(b_obj)
            brep_ids_list.append(b_obj.Id)

        bb = rs.BoundingBox(brep_ids_list)

        bb_x = rs.Distance(bb[0], bb[1])
        bb_y = rs.Distance(bb[0], bb[3])
        bb_h = rs.Distance(bb[0], bb[4])

    else:
        #get stickies
        default_x = sticky["manualXDim"] if sticky.has_key(
            "manualXDim") else 200
        default_y = sticky["manualYDim"] if sticky.has_key(
            "manualYDim") else 250
        default_z = sticky["manualZDim"] if sticky.has_key(
            "manualZDim") else 150

        #Get dimensions manually
        result, bb_x = Rhino.Input.RhinoGet.GetNumber("X dimension?", True,
                                                      default_x)
        if result != Rhino.Commands.Result.Success: return result

        result, bb_y = Rhino.Input.RhinoGet.GetNumber("Y dimension?", True,
                                                      default_y)
        if result != Rhino.Commands.Result.Success: return result

        result, bb_h = Rhino.Input.RhinoGet.GetNumber("Z dimension?", True,
                                                      default_z)
        if result != Rhino.Commands.Result.Success: return result

    bb_w = min(bb_x, bb_y)
    bb_l = max(bb_x, bb_y)

    br = get_inner_box((bb_w, bb_l, bb_h), 0, T_IBOX, TOL_INSIDE)
    ORIGIN_OB = (0, rs.Distance(br[0], br[3]) + LCUT_GAP, 0)
    get_outer_box((bb_w, bb_l, bb_h), 0, T_IBOX, T_OBOX, TOL_INSIDE, ORIGIN_OB)

    #set stickies
    sticky["defaultInThickness"] = T_IBOX
    sticky["defaultOutThickness"] = T_OBOX
    sticky["manualXDim"] = bb_x
    sticky["manualYDim"] = bb_y
    sticky["manualZDim"] = bb_h

    rs.UnselectAllObjects()
    rs.SelectObjects(SELECT_GUIDS)
    rs.Redraw()
    rs.EnableRedraw(True)