예제 #1
0
def main():
    path = rs.GetObject("Select Ramp Path", rs.filter.curve, True)
    if path is None: return

    if 'ramp-widthDefault' in sc.sticky:
        widthDefault = sc.sticky['ramp-widthDefault']
    else:
        widthDefault = 36
    if 'ramp-slopeDefault' in sc.sticky:
        slopeDefault = sc.sticky['ramp-slopeDefault']
    else:
        slopeDefault = 8.333

    width = rs.GetReal("Ramp Clear Width", widthDefault, minimum=36)
    if width is None: return
    slope = rs.GetReal("Ramp slope (e.g. 8.33%(1:12) is 8.33)", slopeDefault)
    if slope is None: return

    sc.sticky['ramp-widthDefault'] = width
    sc.sticky['ramp-slopeDefault'] = slope

    rs.EnableRedraw(False)
    rampGeoList = Ramp_HeightSlope(path, width, slope / 100)
    try:
        layers.AddLayerByNumber(402, False)
        layerName = layers.GetLayerNameByNumber(402)

        rs.ObjectLayer(rampGeoList[0], layerName)
        try:
            if rampGeoList[2] is not None:
                layers.AddLayerByNumber(106, False)
                layerName = layers.GetLayerNameByNumber(106)

                rs.ObjectLayer(rampGeoList[2], layerName)
        except:
            pass
        result = True
    except:
        result = False

    utils.SaveFunctionData('Architecture-ramp', [
        width, slope,
        str([(pt.X, pt.Y, pt.Z) for pt in rs.CurveEditPoints(path)]), result
    ])

    rs.EnableRedraw(True)

    print rampGeoList[1]

    utils.SaveToAnalytics('architecture-ramp')
예제 #2
0
def CreateDesignOption():
    objs = rs.GetObjects("Select objects to create design option with",
                         preselect=True)
    if objs is None: return None
    try:
        date = utils.GetDatePrefix()
        origName = date + '_OPTION_00'
        defaultName = origName
        for i in range(100):
            defaultName = utils.UpdateString(defaultName)
            if origName == defaultName:
                break
            if rs.IsBlock(defaultName) == False:
                break

        looping = True
        while looping:
            designOptionName = rs.StringBox("Design Option Name", defaultName,
                                            "Create Design Option")
            if designOptionName is None: return None
            if rs.IsBlock(designOptionName):
                print "Block name already exists"
            elif len(designOptionName) == 0:
                print "Must specify a name"
            else:
                looping = False
        block = rs.AddBlock(objs, (0, 0, 0), designOptionName, True)
        blockInstance = rs.InsertBlock(designOptionName, (0, 0, 0))

        #Add user text
        rs.SetUserText(blockInstance, 'Design Option History',
                       designOptionName)

        #Ensure 3_DESIGN OPTIONS already exists
        layers.AddLayerByNumber(3000, False)

        #Create new layer
        parentLayer = layers.GetLayerNameByNumber(3000)
        designOptionLayer = rs.AddLayer(parentLayer + "::" + designOptionName,
                                        color=utils.GetRandomColor())
        rs.ObjectLayer(blockInstance, designOptionLayer)
        utils.SaveFunctionData('Blocks-Create Design Option',
                               [__version__, designOptionName])
        return True
    except:
        print "Failed to create design option"
        utils.SaveFunctionData('Blocks-Create Design Option',
                               [__version__, '', 'Failed'])
        return None
예제 #3
0
def dimensionPline_Button():
    objects = rs.GetObjects("Select Curves to Dimension", filter = 4, preselect = True)
    if objects is None:return

    if 'dimPline-dist' in sc.sticky:
        distDefault = sc.sticky['dimPline-dist']
    else:
        distDefault = 60

    offsetDist = rs.GetInteger('Dimension offset distance (in.)', distDefault)
    if offsetDist is None: return

    sc.sticky['dimPline-dist'] = offsetDist

    #Load Anno style if it doesnt exist already
    if sc.doc.DimStyles.FindName('PCPA_12') is None:
        standards.LoadStyles()

    try:
        layers.AddLayerByNumber(8101)
        layerName = layers.GetLayerNameByNumber(8101)
        rs.CurrentLayer(layerName)
    except:
        pass


    rs.EnableRedraw(False)
    for obj in objects:
        if rs.IsCurve(obj):
            try:
                group, rc = dimensionPline(obj, offsetDist)
                utils.SaveFunctionData('Drawing-Dim Pline', [rs.DocumentPath(), rs.DocumentName(), rs.ObjectLayer(obj), rs.CurrentDimStyle(), offsetDist, rc])
            except:
                print "Unknown Error"
        else:
            print "Not a polyline"
    rs.EnableRedraw(True)
예제 #4
0
def importCAD(filePath, scaleDWG = False):
    explodeBlockBoo = True

    #setup the layers
    importLayerNumber = 6000
    importLayerObj = layers.AddLayerByNumber(importLayerNumber, False)
    importLayerName = layers.GetLayerNameByNumber(importLayerNumber)

    #Shorten cad file name
    fileNameExt = os.path.basename(filePath)
    fileName = os.path.splitext(fileNameExt)[0]

    #create layer name
    time = utils.GetDatePrefix()
    iter = "01"
    layerName = time+"_"+fileName+"_"+iter

    #Check if this layer already exists
    while rs.IsLayer(importLayerName + "::" + time + "_" + fileName + "_" + iter):
        iterInt = int(iter)+1
        if len(str(iterInt))<2:
            iter = "0" + str(iterInt)
        else:
            iter = str(iterInt)

    elementLayerName = importLayerName + "::" + time + "_" + fileName + "_" + iter
    elementLayer = rs.AddLayer(elementLayerName)

    rs.CurrentLayer(elementLayer)

    #get intial list of all layers in the file
    currentLayers = rs.LayerNames()

    rs.Command('_-Import "' + filePath + '" _IgnoreThickness=Yes _ModelUnits=Inches _Enter', False)

    #get new layers added
    endLayersNames = rs.LayerNames()
    newLayers = diff(endLayersNames, currentLayers)

    for layer in newLayers:
        rs.ParentLayer(layer, elementLayer)
        objects = rs.ObjectsByLayer(layer)
        if rs.IsLayerEmpty(layer):
            rs.DeleteLayer(layer)
        else:
            for obj in objects:
                if rs.IsDimension(obj):
                    rs.DeleteObject(obj)
                elif rs.IsHatch(obj):
                    rs.DeleteObject(obj)

    #Get all the imported geometry
    allObjects = []
    finalLayers = rs.LayerChildren(rs.CurrentLayer())
    blockNames = []
    for finalLayer in finalLayers:
        layerObjects = rs.ObjectsByLayer(finalLayer)
        for layerObject in layerObjects:
            if rs.IsBlockInstance(layerObject):
                blockNames.append(rs.BlockInstanceName(layerObject))
                allObjects.append(rs.ExplodeBlockInstance(layerObject, True))
            else:
                allObjects.append(layerObject)
    finalAllObjects = list(flatten(allObjects))

    for eachBlock in blockNames:
        try:
            rs.DeleteBlock(eachBlock)
        except:
            pass

    #Scale objects
    if scaleDWG:
        rs.ScaleObjects(finalAllObjects, [0,0,0], [.001, .001, .001])

    #Collapse layers
    try:
        rootLay = sc.doc.Layers.FindId(rs.coerceguid(rs.LayerId(elementLayerName)))
        rootLay.IsExpanded = False
    except:
        pass
    print "Import Successful"
    return finalAllObjects
예제 #5
0
def AreaTag(obj, decPlaces):
    try:
        rhsrf = rs.coercesurface(obj)
        if rs.IsCurve(obj):
            if rs.IsCurvePlanar(obj) == False:
                return [0, False]
            if rs.IsCurveClosed(obj) == False:
                return [0, False]

        #get area
        if rs.UnitSystem() == 8:
            if rs.IsCurve(obj):
                area = rs.CurveArea(obj)[0]*0.0069444444444444
            else:
                area = rs.Area(obj)*0.0069444444444444
            areaText = utils.RoundNumber(area, decPlaces) + " SF"
        else:
            print "WARNING: Your units are not in inches"
            area = rs.CurveArea(obj)[0]
            areaText = area + ' ' + rs.UnitSystemName(False, True, True)

        #add annotation style
        dimStyle = sc.doc.DimStyles.FindName('PCPA_12')

        ###########################################################################
        #CURVES
        if rs.IsCurve(obj):
            if utils.IsRectangle(obj)[0]:
                #RECTANGLES
                srf = rs.AddPlanarSrf(obj)
                plane = HorizPlaneFromSurface(srf)
                rs.DeleteObject(srf)
            else:
                #OTHER CURVES
                srf = rs.AddPlanarSrf(obj)
                plane = HorizPlaneFromSurface(srf)
                rs.DeleteObject(srf)
        ###########################################################################
        #HATCHES
        elif rs.IsHatch(obj):
            rhobj = rs.coercegeometry(obj)
            boundaryCrvs = []
            crvs = rhobj.Get3dCurves(False)
            for crv in crvs:
                boundaryCrvs.append(crv)
            for crv in rhobj.Get3dCurves(True):
                boundaryCrvs.append(crv)
            srf = sc.doc.Objects.AddBrep(rc.Geometry.Brep.CreatePlanarBreps(boundaryCrvs)[0])
            plane = HorizPlaneFromSurface(srf)
            rs.DeleteObject(srf)
        ###########################################################################
        #SURFACES
        elif rs.IsSurface(obj):
            plane = HorizPlaneFromSurface(obj)

        ###########################################################################
        #OTHER/ERROR
        else:
            pts = rs.BoundingBox(obj)
            centerPoint = (pts[0] + pts[6]) / 2


        if dimStyle is not None:
            textHeight = dimStyle.TextHeight
            areaTag = rs.AddText(areaText, plane, height = textHeight, justification = 131074)
        else:
            areaTag = rs.AddText(areaText, plane, height = 1, justification = 131074)

        #Change layers
        hostLayer = layers.AddLayerByNumber(8103, False)
        rs.ObjectLayer(areaTag, layers.GetLayerNameByNumber(8103))
        return [area, True, areaTag]
    except:
        return [0, False]
예제 #6
0
def AddTitleBlock(size):
    filelocations = config.GetDict()
    rs.EnableRedraw(False)
    if size == 11:
        offset = .354
        row1 = offset
        row2 = row1 * 2
        row3 = row1 * 3
        row4 = row1 * 4
        leftEdge = offset
        middle = 17 / 2
        rightEdge = 17 - offset

        pt1 = [leftEdge, row4]
        pt2 = [rightEdge, 11 - row1]
        txtBase1 = [middle, row2]
        txtBase2 = [leftEdge, row2]
        txtBase3 = [rightEdge, row2]
        txtBase4 = [leftEdge, row1]
        txtBase5 = [rightEdge, row1]

        lineSt = [leftEdge, row3]
        lineEnd = [rightEdge, row3]

        txtSizeL = .125
        txtSizeM = .094

        logoPlane = [13.834, .247, 0]
        logoWidth = 2.823
        logoHeight = .116

    elif size == 8:
        offset = .229
        row1 = offset
        row2 = row1 * 2
        row3 = row1 * 3
        row4 = row1 * 4
        leftEdge = offset
        middle = 11 / 2
        rightEdge = 11 - offset

        pt1 = [leftEdge, row4]
        pt2 = [rightEdge, 8.5 - row1]
        txtBase1 = [middle, row2]
        txtBase2 = [leftEdge, row2]
        txtBase3 = [rightEdge, row2]
        txtBase4 = [leftEdge, row1]
        txtBase5 = [rightEdge, row1]

        lineSt = [leftEdge, row3]
        lineEnd = [rightEdge, row3]

        txtSizeL = .125
        txtSizeM = .063

        logoPlane = [8.347, .157, 0]
        logoWidth = 2.434
        logoHeight = .100

    elif size == 18:
        offset = .5
        row1 = offset
        row2 = row1 * 2
        row3 = row1 * 3
        row4 = row1 * 4
        leftEdge = offset
        middle = 24 / 2
        rightEdge = 24 - offset

        pt1 = [leftEdge, row4]
        pt2 = [rightEdge, 18 - row1]
        txtBase1 = [middle, row2]
        txtBase2 = [leftEdge, row2]
        txtBase3 = [rightEdge, row2]
        txtBase4 = [leftEdge, row1]
        txtBase5 = [rightEdge, row1]

        lineSt = [leftEdge, row3]
        lineEnd = [rightEdge, row3]

        txtSizeL = .250
        txtSizeM = .125

        logoPlane = [19.627, .367, 0]
        logoWidth = 3.885
        logoHeight = .160

    layout = sc.doc.Views.GetPageViews()[-1]
    if layout is None: return

    sc.doc.Views.ActiveView = layout

    if rs.GetDocumentData(section="PCPA", entry="Project_Name") is None:
        rs.SetDocumentData(section="PCPA",
                           entry="Project_Name",
                           value="PROJECT TITLE")
    projectTitle = '%<DocumentText("PCPA\Project_Name")>%'

    if rs.GetDocumentData(section="PCPA", entry="Client_Name") is None:
        rs.SetDocumentData(section="PCPA",
                           entry="Client_Name",
                           value="Client Name")
    clientName = '%<DocumentText("PCPA\Client_Name")>%'

    #Add text
    textList = []
    textList.append(rs.AddText("Title", txtBase1, txtSizeL, justification=2))
    textList.append(
        rs.AddText(projectTitle, txtBase2, txtSizeL, justification=1))
    textList.append(
        rs.AddText('%<Date("MMMM d, yyyy")>%',
                   txtBase3,
                   txtSizeM,
                   justification=4))

    textList.append(rs.AddText(clientName, txtBase4, txtSizeM,
                               justification=1))

    #ADD Copyright
    copyright = 'COPYRIGHT ' + u"\u00a9" + ' %<Date("yyyy")>%'
    copyrightText = rs.AddText(copyright, txtBase5, txtSizeM, justification=4)

    #ADD Pelli Clarke Pelli
    pcp = 'Pelli Clarke Pelli'
    pcpText = rs.AddText(pcp, txtBase5, txtSizeM, justification=4)
    if rs.IsDimStyle('PCPA_10'):
        dimstyleID = sc.doc.DimStyles.FindName('PCPA_14')

    ##############
    #Just trying to change the dim style here
    #pcpRhobj = rs.coercerhinoobject(pcpText)
    #test = pcpRhobj.Attributes
    #pcpRhobj.CommitChanges()
    ##############

    #ADD Architects
    architects = 'Architects'
    architectsText = rs.AddText(architects,
                                txtBase5,
                                txtSizeM,
                                justification=4)

    #Horizontal line
    line = rs.AddLine(lineSt, lineEnd)

    #Add detail
    detail = rs.AddDetail(layout.ActiveViewportID, pt1, pt2,
                          "PCPA " + str(layout.PageName), 7)

    #Change layers AddLayerByNumber
    try:
        rs.ObjectLayer(line, layers.GetLayerNameByNumber(8204))
    except:
        pass
    try:
        rs.ObjectLayer(detail, layers.GetLayerNameByNumber(8106))
    except:
        pass
    try:
        for eachText in textList:
            rs.ObjectLayer(eachText, layers.GetLayerNameByNumber(8105))
    except:
        pass
    try:
        rs.ObjectLayer(copyrightText, layers.GetLayerNameByNumber(8211))
    except:
        pass
    try:
        rs.ObjectLayer(pcpText, layers.GetLayerNameByNumber(8210))
    except:
        pass
    try:
        rs.ObjectLayer(architectsText, layers.GetLayerNameByNumber(8211))
    except:
        pass
    rs.EnableRedraw(True)
예제 #7
0
def main():
    if (rs.UnitSystem() == 2):
        widthDefault = 1800
        widthMin = 900
        widthMax = 100000
        heightDefault = 5000
        heightMin = 300
    elif (rs.UnitSystem() == 4):
        widthDefault = 1.8
        widthMin = .9
        widthMax = 100.0
        heightDefault = 5.0
        heightMin = .30
    elif (rs.UnitSystem() == 8):
        widthDefault = 42
        widthMin = 36
        widthMax = 1000.0
        heightDefault = 120
        heightMin = 12
    else:
        print "Change your units to inches"
        return

    route = rs.GetObject("Select Stair Guide Curve", rs.filter.curve, True)
    if route is None: return

    if 'stair-widthDefault' in sc.sticky:
        widthDefault = sc.sticky['stair-widthDefault']
    if 'stair-heightDefault' in sc.sticky:
        heightDefault = sc.sticky['stair-heightDefault']

    width = rs.GetReal("Stair Width",
                       number=widthDefault,
                       minimum=widthMin,
                       maximum=widthMax)
    if width is None: return
    height = rs.GetReal("Stair Height",
                        number=heightDefault,
                        minimum=heightMin)
    if height is None: return

    sc.sticky['stair-widthDefault'] = width
    sc.sticky['stair-heightDefault'] = height

    try:
        stairGeo = stairHeight(route, width, height)
        result = True
    except:
        result = False

    try:
        layers.AddLayerByNumber(401, False)
        layerName = layers.GetLayerNameByNumber(401)

        rs.ObjectLayer(stairGeo, layerName)
    except:
        pass

    utils.SaveFunctionData('Architecture-Stair', [
        width, height,
        str([(pt.X, pt.Y, pt.Z) for pt in rs.CurveEditPoints(route)]), result
    ])

    utils.SaveToAnalytics('Architecture-Stair')
예제 #8
0
def PopulatePath():
    numObjects = 0
    type = None
    try:
        crvs = rs.GetObjects("Select curves to populate", rs.filter.curve,
                             True)
        if crvs is None: return None
        crvObjs = []
        for crv in crvs:
            crvObjs.append(rs.coercecurve(crv))

        #GET POPULATION TYPE
        type = GetPopulationType()
        if type is None: return None

        #GET BLOCK NAMES
        if type == 'Custom Block':
            blockNames, instances = GetCustomBlockNames()
        else:
            blockNames = GetBlockNames(type)
        if blockNames is None: return

        #GET NUMBER OF OBJECTS
        numObjects = GetNumObjects()
        if numObjects is None: return None

        rs.EnableRedraw(False)
        if type == '2D People' or type == '3D People':
            spacing = 42
        elif type == '2D Trees':
            spacing = 100
        elif type == '3D Trees':
            spacing = 200
        elif type == '3D Vehicles':
            spacing = 240
        else:
            spacing = GetCustomSpacing(
                blockNames[0])  #currently just selects the first block

        #GET PTS
        upVec = rc.Geometry.Vector3d(0, 0, 1)
        plane0 = rc.Geometry.Plane(rc.Geometry.Point3d(0, 0, 0), upVec)
        plane0.Rotate(math.pi / 2, upVec)
        crvData = []
        for i, crvObj in enumerate(crvObjs):
            lengths = []
            frames = []
            curveLength = crvObj.GetLength()
            counter = 0

            while len(frames) < numObjects:
                t = utils.Remap(random.uniform(0, 1), 0, 1, 0, curveLength)

                posOkay = True
                if len(lengths) > 0:
                    counter += 1
                    for eachPrevPos in lengths:
                        if abs(eachPrevPos - t) < spacing:
                            posOkay = False

                if posOkay:
                    lengths.append(t)
                    pt = crvObj.PointAtLength(t)
                    param = crvObj.LengthParameter(t)[1]
                    tan = crvObj.TangentAt(param)
                    xAxis = rc.Geometry.Vector3d.CrossProduct(tan, upVec)
                    xAxis.Reverse()
                    frames.append(rc.Geometry.Plane(pt, tan, xAxis))

                if counter > int(curveLength / numObjects):
                    print "Curve {}: Could only fit {} of the requested {} objects".format(
                        i, len(frames), numObjects)
                    break
            crvData.append(frames)

        scaleVariation = .1
        #PLACE THE BLOCKS
        for i, crvObj in enumerate(crvObjs):
            for i, frame in enumerate(crvData[i]):
                blockName = blockNames[random.randint(0, len(blockNames) - 1)]
                if TryLoadBlock(type, blockName):
                    xform = rc.Geometry.Transform.PlaneToPlane(plane0, frame)
                    eachBlock = rs.InsertBlock2(blockName, xform)
                    try:
                        if type == '2D People' or type == '3D People':
                            layerName = layers.GetLayerNameByNumber(2200)
                        elif type == '2D Trees' or type == '3D Trees':
                            layerName = layers.GetLayerNameByNumber(2300)
                        elif type == '3D Vehicles':
                            layerName = layers.GetLayerNameByNumber(2400)
                        elif type == 'Custom Block':
                            layerName = rs.ObjectLayer(instances[0])
                        else:
                            layers.AddLayerByNumber(2000)
                            layerName = layers.GetLayerNameByNumber(2000)
                        rs.ObjectLayer(eachBlock, layerName)

                        if type != '3D Vehicles':
                            xyScale = random.uniform(1 - scaleVariation,
                                                     1 + scaleVariation)
                            zScale = random.uniform(1 - scaleVariation,
                                                    1 + scaleVariation)
                        else:
                            xyScale = 1
                            zScale = 1
                        rs.ScaleObject(eachBlock, frame,
                                       (xyScale, xyScale, zScale))
                    except:
                        pass
        rs.EnableRedraw(True)
        result = True
    except:
        result = False

    utils.SaveFunctionData('Blocks-Populate Path',
                           [__version__, numObjects, type, result])