def DropBlockToSurface():
    try:

        obj = rs.GetObjects('Select Objects',
                            rs.filter.curve | rs.filter.instance
                            | rs.filter.mesh | rs.filter.surface
                            | rs.filter.subd | rs.filter.light
                            | rs.filter.polysurface,
                            preselect=True)
        srf = rs.GetObject('Select Surface')

        if obj:
            if srf:

                rs.EnableRedraw(False)

                # Check if srf is a mesh, if so convert to Nurb
                isMesh = rs.IsMesh(srf)
                if isMesh == True:
                    srf = rs.MeshToNurb(srf)

                # For each object send test rays up and down in Z coord
                # Move each object to the ray test that hits a srf
                for i in obj:
                    bndBox = rs.BoundingBox(i)
                    pt1 = bndBox[0]
                    pt2 = bndBox[2]
                    crv = rs.AddLine(pt1, pt2)

                    if crv:
                        midcrv = rs.CurveMidPoint(crv)
                        rs.DeleteObject(crv)

                    ray_pt_up = rs.ShootRay(srf,
                                            midcrv, (0, 0, 1),
                                            reflections=1)
                    ray_pt_down = rs.ShootRay(srf,
                                              midcrv, (0, 0, -1),
                                              reflections=1)

                    if ray_pt_up:
                        vector = rs.VectorCreate(ray_pt_up[1], midcrv)
                        rs.MoveObject(i, vector)

                    if ray_pt_down:
                        vector = rs.VectorCreate(ray_pt_down[1], midcrv)
                        rs.MoveObject(i, vector)

                # deleate any created srf
                if isMesh == True:
                    rs.DeleteObject(srf)
                rs.EnableRedraw(True)

    except:
        print("Failed to execute")
        rs.EnableRedraw(True)
        return
Esempio n. 2
0
    def setAdditiveObj(self):
        #set object to be additived
        #if selected obj isnt closed, return False

        tmp = rs.GetObject("Select object which you want additive")

        #adapt to unclosed polysurface
        if rs.IsMesh(tmp):
            self.addtiveObj = rs.MeshToNurb(tmp)

        elif rs.IsPolysurface(tmp):
            self.addtiveObj = tmp

        else:
            print("please select \"mesh\" or \"polysurface\"")

        return True
Esempio n. 3
0
    def setAdditiveObj(self):
        '''
        set object that is added
        when pick object, it must be mesh or polysurface
        if picked object is mesh, it will be converted to polysurface
        '''

        tmp = rs.GetObject("Pick a additive obj",
                           rs.filter.polysurface | rs.filter.mesh)

        if rs.IsMesh(tmp):
            self.additiveObj = rs.MeshToNurb(tmp)

        elif rs.IsPolysurface(tmp):
            self.additiveObj = tmp

        else:
            print("Please select \"mesh\" or \"polysurface\"")
            return False

        return True
Esempio n. 4
0
def ProjectCurvesToTIN():
    try:
        crvs = rs.GetObjects(message="Select curves to project",
                             filter=4,
                             group=True,
                             preselect=False,
                             select=False,
                             objects=None,
                             minimum_count=1,
                             maximum_count=0,
                             custom_filter=None)
        if not crvs:
            return
        obj = rs.GetObject("Select the TIN to project onto", 8 | 16 | 32)
        if not obj:
            return
        isMesh = rs.IsMesh(obj)
        zUpList = []
        zDownList = []

        rs.EnableRedraw(False)

        # Convert Mesh to Nurbs for ShootRay compatibility
        if isMesh == True:
            srf = rs.MeshToNurb(obj)
        if isMesh == False:
            srf = obj

        # Shoot ray from each grip point and move grips to reflection point
        for crv in crvs:
            rs.EnableObjectGrips(crv)
            grips = rs.ObjectGripLocations(crv)
            for grip in grips:

                zUp = rs.ShootRay(srf, grip, (0, 0, 1), 1)
                # if zUp != None:
                if zUp == None:
                    zUpList.append(False)
                else:
                    zUpList.append(zUp[1])

                zDown = rs.ShootRay(srf, grip, (0, 0, -1), 1)
                # if zDown != None:
                if zDown == None:
                    zDownList.append(False)
                else:
                    zDownList.append(zDown[1])

            rs.CopyObject(crv)  # Copy Existing curve

            # Find the right list to iterate over and insert existing points for any falses
            if all(x is False for x in zUpList):
                falseindex = [i for i, val in enumerate(zDownList) if not val]
                for i in falseindex:
                    # Replace False with existing grip location and closest Z value
                    closestPt = rs.BrepClosestPoint(srf, grips[i])
                    zDownList[i] = (grips[i].X, grips[i].Y, closestPt[0].Z)
                rs.ObjectGripLocations(crv, zDownList)
            else:
                falseindex = [i for i, val in enumerate(zUpList) if not val]
                for i in falseindex:
                    # Replace False with existing grip location and closest Z value
                    closestPt = rs.BrepClosestPoint(srf, grips[i])
                    zUpList[i] = (grips[i].X, grips[i].Y, closestPt[0].Z)
                rs.ObjectGripLocations(crv, zUpList)

            del zDownList[:]
            del zUpList[:]
            rs.EnableObjectGrips(crv, False)

        if isMesh == True:
            rs.DeleteObject(srf)

        rs.EnableRedraw(True)

    except:
        rs.EnableObjectGrips(crv, False)
        rs.DeleteObject(crv)
        rs.EnableRedraw(True)
        print("Failed to project curves")
        return