Example #1
0
    def calcDistance(self, plane, editPoints):
        forDistance = []

        for i in range(len(editPoints)):
            if i == 0:
                forDistance.append(editPoints[0])
                forDistance.append(rs.DistanceToPlane(plane, editPoints[0]))
            else:
                tmpDistance = rs.DistanceToPlane(plane, editPoints[i])
                if tmpDistance > forDistance[1]:
                    forDistance[0] = editPoints[i]
                    forDistance[1] = tmpDistance

        self.distancePrinting = rs.DistanceToPlane(plane, forDistance[0])

        #adapt to Z Axis
        self.distancePrinting *= (1.0 /
                                  math.cos(math.radians(self.angleOfSurface)))

        if self.distancePrinting < 0:
            self.distancePrinting *= -1

        return
Example #2
0
def main():
    to_delete = []

    rs.ProjectOsnaps(False)

    positive_object = rs.GetObject("select positive object", 16)
    negative_object = rs.GetObject("select negative object", 16)
    rs.HideObject(negative_object)

    polysurface, face = GetSubSurface("select tenon surface")
    to_delete.append(face)

    normal = rs.VectorUnitize(rs.SurfaceNormal(face, (0.5, 0.5)))
    plane = rs.PlaneFromNormal(rs.EvaluateSurface(face, 0.5, 0.5), normal)
    rs.ViewCPlane(plane=plane)
    rs.ProjectOsnaps(True)

    tenon_rects = rs.GetObjects(message="select tenon curves", filter=4)

    tenon_faces = []
    for rect in tenon_rects:
        tenon_faces.append(rs.AddPlanarSrf(rect)[0])

    rs.ShowObject(negative_object)

    rs.ProjectOsnaps(False)
    height_pt = rs.GetPoint("enter height point")

    # compule a vector normal to plane of the desired height
    extrude_vec_a = rs.EvaluateSurface(face, 0.5, 0.5)
    dist = rs.DistanceToPlane(plane, height_pt)
    extrude_vec_b = [dist * el for el in normal]
    extrude_vec_b = rs.VectorAdd(extrude_vec_a, extrude_vec_b)
    extrude_curve = rs.AddCurve((extrude_vec_a, extrude_vec_b))
    to_delete.append(extrude_curve)

    tenons = []
    for tenon_face in tenon_faces:
        tenon = rs.ExtrudeSurface(tenon_face, extrude_curve)
        tenons.append(tenon)

    rs.BooleanUnion([positive_object] + tenons, delete_input=False)
    rs.BooleanDifference([negative_object], tenons, delete_input=False)

    to_delete.append(positive_object)
    to_delete.append(negative_object)

    rs.DeleteObjects(to_delete)
    rs.DeleteObjects(tenon_faces)
    rs.DeleteObjects(tenons)
Example #3
0
    def detectParalellSurface(self):
        #fix layer height

        #self.paralellIntersectedCurve
        #self.indexParalellSurfaces

        explodedSurfaces = rs.ExplodePolysurfaces(self.addtiveObj)

        for surface in explodedSurfaces:
            #normals.append(rs.SurfaceNormal(surface))
            tmpNormal = rs.SurfaceNormal(surface, [0, 0])

            gotAngle = rs.VectorAngle(tmpNormal, self.normalVec)
            if gotAngle == 0 or gotAngle == 180:

                tmpPoints = rs.SurfaceEditPoints(surface)
                tmpPlane = rs.PlaneFromNormal(tmpPoints[0], self.normalVec)

                distance = rs.DistanceToPlane(tmpPlane, self.basePointForPlane)

                distance *= (1.0 / math.cos(math.radians(self.angleOfSurface)))
                print("distance")
                print(distance)

                paralellLayer = int(distance / self.fixedLayerHeight)
                if paralellLayer < 0:
                    paralellLayer *= -1

                if paralellLayer == int(
                        self.distancePrinting /
                        self.fixedLayerHeight) or int(distance) == 0:
                    continue

                self.indexParalellSurfaces.append(int(paralellLayer))
                print("paralellLayer")
                print(paralellLayer)
                print("layer num")
                print(self.distancePrinting / self.fixedLayerHeight)
                #there is object to delete
                self.paralellIntersectedCurves.append(
                    rs.JoinCurves(rs.DuplicateEdgeCurves(surface)))

        rs.DeleteObjects(explodedSurfaces)
        """
    for n in ListPts:
        NeiBeamList = []
        for l in ListBeams:
            EndL = rs.CurveEndPoint(l)
            StEl = rs.CurveStartPoint(l)
            if rs.Distance(n, EndL) < 0.2 or rs.Distance(n, StEl) < 0.2:
                NeiBeamList.append(l)

        LstNodeBeams.append(NeiBeamList)

    # Creating Nodes
    co = -1
    for Cen in ListPts:
        co = co + 1
        Gr = rs.WorldXYPlane()
        DistToGr = rs.DistanceToPlane(Gr, Cen)
        if DistToGr > 0:
            DistToGr = DistToGr
        else:
            DistToGr = 5
        BeLen = (1 / DistToGr) * 2
        BRad = BeLen / 3
        if BRad > 0.2:
            BRad = 0.2
        Axes = LstNodeBeams[co]
        Node = CreatingNodeFun(Cen, Axes, BRad, BeLen)

    # Creating Beams
    for Axe in ListBeams:
        Gr = rs.WorldXYPlane()
        EndPt = rs.CurveEndPoint(Axe)
def RunCommand( is_interactive ):
    print(__commandname__ + " v0.5.1")

    # ZERO_TOLERANCE = 1.0e-2
    ZERO_TOLERANCE = rs.UnitAbsoluteTolerance()
    myDebug = True
    unlockLayersDefault = False
    global plane
    plane = []
    selectedObjects = []
    selectedCounter = 0

    go = rc.Input.Custom.GetObject()
    go.SetCommandPrompt("Select Two Parallel Planar Surfaces")
    go.AlreadySelectedObjectSelect = False
    go.DeselectAllBeforePostSelect = False
    go.EnableClearObjectsOnEntry(False)
    # go.EnableUnselectObjectsOnExit(False)
    go.OneByOnePostSelect = True
    go.SubObjectSelect = True
    go.EnablePreSelect(False, True)
    # go.EnableClearObjectsOnEntry(False)

    # Filter object type
    geometryType = rc.DocObjects.ObjectType.Surface
    go.GeometryFilter = geometryType

    # Set up command option persistance memory
    if sc.sticky.has_key("distance_parallel_unlock"):
        unlockLayersDefault = sc.sticky["distance_parallel_unlock"]
    else:
        sc.sticky["distance_parallel_unlock"] = False
        unlockLayersDefault = sc.sticky["distance_parallel_unlock"]

    if sc.sticky.has_key("distance_parallel_msg_box"):
        messageBoxDefault = sc.sticky["distance_parallel_msg_box"]
    else:
        sc.sticky["distance_parallel_msg_box"] = False
        messageBoxDefault = sc.sticky["distance_parallel_msg_box"]

    # set up command options
    unlockLayers = rc.Input.Custom.OptionToggle(unlockLayersDefault, "Off", "On")
    go.AddOptionToggle("UnlockLayersAndObjects", unlockLayers)

    messageBox = rc.Input.Custom.OptionToggle(messageBoxDefault, "Off", "On")
    go.AddOptionToggle("ResultsInMessageBox", messageBox)

    unlockLayersPrevState = unlockLayers.CurrentValue
    messageBoxPrevState = messageBox.CurrentValue

    if unlockLayers.CurrentValue == 1:
        ul.unlockLayersAndObjects()


    while True:

        getResult = go.GetMultiple(selectedCounter+1,selectedCounter+1)
        # go.EnableClearObjectsOnEntry(False)
        # go.DeselectAllBeforePostSelect = False
        if getResult == rc.Input.GetResult.Cancel:
            clean_up_cancel()
            return rc.Commands.Result.Cancel
        #     clean_up_success()
        #     return go.CommandResult()
        if getResult == rc.Input.GetResult.Object:
            # Get the view that the point was picked in.
            view = go.View()
            selectedObjects = go.Objects()
            selectedCounter = len(selectedObjects)
            # get objects from selections
            objref = go.Object(selectedCounter-1)
            # get selected surface object
            obj = objref.Object()
            if not obj:
                # Why do?
                if myDebug :
                    msgOut("Object not selected.")
                clean_up_fail()
                return rc.Commands.Result.Failure
            try:
                surface = objref.Surface()
            except:
                msgOut("Surfaces within blocks are not always selectable. Polysurfaces can be selected, Extrusion cannot. Explode block for more selectability.")
                # try to continue and reselect
                clean_up_fail()
                return rc.Commands.Result.Failure
            if not surface:
                # why is this needed?
                if myDebug :
                    msgOut("No surface selected.")
                clean_up_fail()
                return rc.Commands.Result.Failure

            test, getPlane = surface.TryGetPlane(ZERO_TOLERANCE)
            if not test:
                msgOut("Surface is not planar.")
                # maybe continue or allow select of first surface again
                clean_up_fail()
                return rc.Commands.Result.Failure
            plane.append(getPlane)
            if selectedCounter == 2:
                # view.Redraw()
                break
            # loop until second surface selected or cancel
            continue
        # Command Options
        elif getResult == rc.Input.GetResult.Option:
            if unlockLayers.CurrentValue != unlockLayersPrevState:
                if unlockLayers.CurrentValue == 1:
                    sc.sticky["distance_parallel_unlock"] = True
                    unlockLayersPrevState = True
                    ul.unlockLayersAndObjects()
                else:
                    sc.sticky["distance_parallel_unlock"] = False
                    unlockLayersPrevState = False
                    ul.relockLayersAndObjects()
            elif messageBox.CurrentValue != messageBoxPrevState:
                if messageBox.CurrentValue == 1:
                    sc.sticky["distance_parallel_msg_box"] = True
                    messageBoxPrevState = True
                else:
                    sc.sticky["distance_parallel_msg_box"] = False
                    messageBoxPrevState = False
    	    go.EnablePreSelect(False, True)
            continue
        elif getResult == rc.Input.GetResult.Nothing:
            # needed?
            msgOut("Got nothing.")
            clean_up_fail()
            return rc.Commands.Result.Failure
            # break
        # end While

    clean_up_success()
    # Are planes parallel
    if ArePlanesParallel(plane[0], plane[1], ZERO_TOLERANCE) == False:
        msgOut("Surfaces are not parallel to each other.")
        clean_up_fail()
        return rc.Commands.Result.Failure
    # measure distance between planes
    # acually distance between plane[0] and point on plan[1]
    ParallelDistance = abs(rs.DistanceToPlane(plane[0], plane[1][0]))
    # output results
    unitsName = doc.GetUnitSystemName(True, True, True, False)
    ## fromating output decimal places not working for me
    # decimalPlaces = doc.DistanceDisplayPrecision
    # textOut = "Parallel Distance = {:." + str(decimalPlaces) +"f} " + unitsName
    rs.ClipboardText(ParallelDistance)
    textOut = "Parallel Distance = {:.4f} " + unitsName
    # msgOut(textOut.format(ParallelDistance))
    print(textOut.format(ParallelDistance))
    if sc.sticky["distance_parallel_msg_box"]:
        # view.Redraw()
        rs.MessageBox("the value is saved to your clipboard", 64, textOut.format(ParallelDistance))
    else:
        pass
        #delay enough to see last selected highlighting before commend ends
        #Doesn't always work. look for better way to do this
        # rs.Sleep(400)
    return rc.Commands.Result.Success
Example #6
0
    def setSurfaceForSlicing(self):
        explodedSurfaces = None

        editPoint = []
        explodedSurfaces = rs.ExplodePolysurfaces(self.addtiveObj)
        for i in explodedSurfaces:
            tmp = rs.SurfaceEditPoints(i)
            for j in tmp:
                editPoint.append(j)

        rs.CullDuplicatePoints(editPoint)

        minValue = []
        maxValue = []
        basePointForPlane = None
        basePointForDistance = None

        for i in range(len(editPoint)):
            if i == 0:
                basePointForPlane = editPoint[0]
                basePointForDistance = editPoint[0]

                for j in range(3):
                    minValue.append(editPoint[0][j])
                    maxValue.append(editPoint[0][j])
                continue

            else:
                if basePointForPlane[2] > editPoint[i][2]:
                    basePointForPlane = editPoint[i]
                if basePointForDistance[2] < editPoint[i][2]:
                    basePointForDistance = editPoint[i]

                for j in range(3):
                    if minValue[j] > editPoint[i][j]:
                        minValue[j] = editPoint[i][j]
                    elif maxValue[j] < editPoint[i][j]:
                        maxValue[j] = editPoint[i][j]

        #why?
        self.basePointForPlane = basePointForPlane

        plane = rs.PlaneFromNormal(basePointForPlane, self.normalVec)

        #calculating distance printing
        forDistance = []
        for i in range(len(editPoint)):
            if i == 0:
                forDistance.append(editPoint[0])
                forDistance.append(rs.DistanceToPlane(plane, editPoint[0]))
            else:
                tmpDistance = rs.DistanceToPlane(plane, editPoint[i])
                if tmpDistance > forDistance[1]:
                    forDistance[0] = editPoint[i]
                    forDistance[1] = tmpDistance

        self.distancePrinting = rs.DistanceToPlane(plane, forDistance[0])
        #adapt to Z Axis
        self.distancePrinting *= (1.0 /
                                  math.cos(math.radians(self.angleOfSurface)))

        if self.distancePrinting < 0:
            self.distancePrinting *= -1

        plane = rs.PlaneFromNormal(basePointForPlane, self.normalVec)

        pntForSur = []
        line = (minValue[0], minValue[1],
                minValue[2]), (minValue[0], minValue[1], maxValue[2])
        pntForSur.append(rs.LinePlaneIntersection(line, plane))
        line = (minValue[0], maxValue[1],
                minValue[2]), (minValue[0], maxValue[1], maxValue[2])
        pntForSur.append(rs.LinePlaneIntersection(line, plane))
        line = (maxValue[0], maxValue[1],
                minValue[2]), (maxValue[0], maxValue[1], maxValue[2])
        pntForSur.append(rs.LinePlaneIntersection(line, plane))
        line = (maxValue[0], minValue[1],
                minValue[2]), (maxValue[0], minValue[1], maxValue[2])
        pntForSur.append(rs.LinePlaneIntersection(line, plane))

        lineForSur = []

        for i in range(4):
            lineForSur.append(rs.AddLine(pntForSur[i], pntForSur[(i + 1) % 4]))

        self.sliceSurface = rs.AddEdgeSrf(lineForSur)

        #Delete lines used for making sliceSurface
        rs.DeleteObjects(lineForSur)
        rs.DeleteObjects(explodedSurfaces)