Esempio n. 1
0
def exportTEN_CAD():
    a = rs.GetObjects("Select Objects", preselect="True")
    b = rs.ScaleObjects(a, [0, 0, 0], [1000, 1000, 0], copy=True)
    rs.UnitSystem(2)

    savePath0 = rs.SaveFileName("Save", "Autocad (*.dwg)|*.dwg||")
    savePath1 = '"' + savePath0 + '"'
    rs.SelectObjects(b)
    rs.Command('_-Export ' + savePath1 + ' _Enter')
    rs.DeleteObjects(b)
    rs.UnitSystem(4)
    print "Exported"
    return None
Esempio n. 2
0
def convertTextToPolylines2(obj):

    # get object properties
    text = rs.TextObjectText(obj)
    pt = rs.TextObjectPoint(obj)
    origin = rs.coerce3dpoint([0, 0, 0])
    ht = rs.TextObjectHeight(obj)
    object_layer = rs.ObjectLayer(obj)
    plane = rs.TextObjectPlane(obj)

    diff = rs.coerce3dpoint([pt.X, pt.Y, pt.Z])

    p1 = rs.WorldXYPlane()
    #restore view cplane
    rs.ViewCPlane(None, p1)

    matrix = rs.XformRotation4(p1.XAxis, p1.YAxis, p1.ZAxis, plane.XAxis,
                               plane.YAxis, plane.ZAxis)

    rs.DeleteObject(obj)

    # split text at enters
    text = text.split('\r\n')
    opts = 'GroupOutput=No FontName="' + EXPORT_FONT + '" Italic=No Bold=No Height=' + str(
        ht)
    opts += " Output=Curves AllowOpenCurves=Yes LowerCaseAsSmallCaps=No AddSpacing=No "

    n_lines = len(text)

    origin.Y += 1.6 * ht * (len(text) - 1)

    polylines = []
    for item in text:
        rs.Command(
            "_-TextObject " + opts + '"' + item + '"' + " " + str(origin),
            False)
        polylines += rs.LastCreatedObjects()
        origin.Y -= ht * 1.6

    rs.ObjectLayer(polylines, object_layer)

    polylines = rs.ScaleObjects(polylines, (0, 0, 0), (0.7, 1, 1), True)

    # transform to old position
    rs.TransformObjects(polylines, matrix, copy=False)
    rs.MoveObjects(polylines, diff)

    return polylines
def send2CAD(objs, newCoord, CADinMeters):
    if CADinMeters:
        transVec = rs.VectorCreate(newCoord, [0,0,0])
    else:
        transVec = rs.VectorScale(newCoord, .001)
    newObjs = rs.CopyObjects(objs, transVec)
    
    if CADinMeters:
        rs.ScaleObjects(newObjs, [0,0,0], [.001,.001,.001])
        print  "scaled"
    
    rs.SelectObjects(newObjs)
    
    loc = " D:\\temp.dwg"
    
    rs.Command('_-Export '+loc+' _Enter')
    
    rs.DeleteObjects(newObjs)
    print "Sent"
    return None
Esempio n. 4
0
def exportPlanToCAD(chosenLevel, path):

    #Make sure layer is visible
    rs.LayerVisible("6_DRAWINGS", True)
    chosenChildren = rs.LayerChildren("6_DRAWINGS::" + chosenLevel)
    objects = []
    for chosenChild in chosenChildren:
        tempObjects = rs.ObjectsByLayer(chosenChild)
        for tempObject in tempObjects:
            objects.append(tempObject)
    if objects is None:
        return

    scaledObjects = rs.ScaleObjects(objects, [0, 0, 0], [1000, 1000, 0],
                                    copy=True)

    #Format Coordinate
    #    rawCoordinate = rs.GetDocumentData("Project Info", "CAD coordinate")
    #    coordinate = rawCoordinate.split(",")
    #    try:
    #        for i in range(0, 3):
    #            coordinate[i] = float(coordinate[i])
    #    except:
    #            coordinate = None
    #    if coordinate is None:
    #        print "CAD coordinate has an error"
    #
    #    else: #move all objects
    #        negVec = rs.VectorReverse(coordinate)
    #        rs.MoveObjects(scaledObjects, coordinate)

    rs.UnitSystem(2)

    savePath1 = '"' + path + '"'
    rs.SelectObjects(scaledObjects)
    rs.Command('_-Export ' + savePath1 + ' _Enter')
    rs.DeleteObjects(scaledObjects)
    rs.UnitSystem(4)
    print "Exported"
    return None
Esempio n. 5
0
    Eixo_de_Simetria = rs.AddLine(ptX1, ptAux)
#caso seja uma linha
elif str(type(Eixo_de_Simetria)) == "<type 'Guid'>":
    #ptX1 = coordenadas do ponto de interceção da Curva com o eixo de simetria
    #prm1 = parametro da curva no ponto
    #count = conta o número de interceções
    ptX1, prm1, count = gh.CurveXLine(BzSup1, rs.coerceline(Eixo_de_Simetria))
    ptAux = gh.Move(ptX1, -eY)[0]
#caso o vão da viga seja definido pela variavel VigaDist
if VigaDist:
    ptobase = rs.CurveStartPoint(Curva)
    ptoAux = rs.LineClosestPoint(Eixo_de_Simetria, ptobase)
    dist1 = rs.Distance(ptobase, ptoAux)
    escala = (VigaDist / 2) / dist1
    escala = [escala, escala, escala]
    Curva, Eixo_de_Simetria = rs.ScaleObjects((Curva, Eixo_de_Simetria),
                                              ptobase, escala)
    #ptX1 = coordenadas do ponto de interceção da Curva com o eixo de simetria
    #prm1 = parametro da curva no ponto
    #count = conta o número de interceções
    BzSup1 = rs.coercecurve(Curva)
    ptX1, prm1, count = gh.CurveXLine(BzSup1, rs.coerceline(Eixo_de_Simetria))
    ptAux = gh.Move(ptX1, -eY)[0]
#desenha um seguimento no eixo de simetria da treliça
lAux = rs.coerceline(Eixo_de_Simetria)
cAux = rs.OffsetCurve(BzSup1, ptAux, HV1, eZ)
ptX2 = gh.CurveXLine(rs.coercecurve(cAux), lAux)[0]
#eixo do conector
EixoSimetria = rs.AddLine(ptX1, ptX2)
Eixos_do_Conector.append(EixoSimetria)
#----Linhas auxiliares dos Banzos Superiores----
#Ponto de corte (trim) do banzo sup. de V1
Esempio n. 6
0
def alingBlock(block_a, block_b, model_inside):
    """
    Scale box to the correct dimentions
    Align box a and what is inside to box b
    The dimention of the box is expected to be equal lenght
    :param block_a:
    :param block_b: block to align block_a to
    :param model_inside: models inside block_a
    """

    # Find center of box_a
    exp_a = rs.ExplodePolysurfaces(block_a)
    cen_a = Vector3d(0, 0, 0)
    for exp in exp_a:
        cen_a += rs.SurfaceAreaCentroid(exp)[0]
    cen_a /= 6.0

    # Find center of box_b
    exp_b = rs.ExplodePolysurfaces(block_b)
    cen_b = Vector3d(0, 0, 0)
    for exp in exp_b:
        cen_b += rs.SurfaceAreaCentroid(exp)[0]
    cen_b /= 6.0

    # Find side Lenght
    c = rs.DuplicateEdgeCurves(exp_a[0])
    L = float(rs.CurveLength(c[0]))

    def sqrt_length(a, b, c):
        return math.sqrt(a * a + b * b + c * c)

    def create_matrix(a, b, c, d):
        M = [[a[0], a[1], a[2], d[0]], [b[0], b[1], b[2], d[1]],
             [c[0], c[1], c[2], d[2]], [0, 0, 0, 1]]
        return M

    # find basic function of box_a
    basic_0 = cen_a - rs.SurfaceAreaCentroid(exp_a[0])[0]
    basic_0 /= sqrt_length(basic_0[0], basic_0[1], basic_0[2])

    basic_1 = rs.SurfaceAreaCentroid(exp_a[1])[0] - cen_a
    basic_1 /= sqrt_length(basic_1[0], basic_1[1], basic_1[2])

    basic_2 = cen_a - rs.SurfaceAreaCentroid(exp_a[4])[0]
    basic_2 /= sqrt_length(basic_2[0], basic_2[1], basic_2[2])

    # create tranformation matrix
    M = create_matrix(basic_0, basic_1, basic_2, [0, 0, 0])

    # scale
    rs.ScaleObjects([block_a] + model_inside, cen_a,
                    [200 / L, 200 / L, 200 / L])

    # move to [0,0,0]
    rs.MoveObjects([block_a] + model_inside, -cen_a)

    # rotate
    rs.TransformObjects([block_a] + model_inside, M)

    # move to object
    rs.MoveObjects([block_a] + model_inside, cen_b)

    rs.DeleteObjects(exp_a)
    rs.DeleteObjects(exp_b)

    rs.DeleteObjects(c)
Esempio n. 7
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
Esempio n. 8
0
def importTEN_CAD():
    savePath0 = rs.OpenFileName("Open", "Autocad (*.dwg)|*.dwg||")
    items = [["Units", "Meters", "Millimeters"]]
    defaults = [False]
    CADinMilli = rs.GetBoolean("Is that CAD file in meters or mm?", items,
                               defaults)[0]

    explodeBlockBoo = True

    if savePath0 is None:
        return
    rs.EnableRedraw(False)

    #setup the layers
    rs.AddLayer("7_REF")
    rs.AddLayer("CAD", parent="7_REF")

    fileNameExt = savePath0.split('\\')[-1]
    fileName = fileNameExt.split('.')[0]
    savePath1 = '"' + savePath0 + '"'

    #create layer name
    now = datetime.date.today()
    dateList = []
    if len(str(now.month)) > 1:
        month = str(now.month)
    else:
        month = "0" + str(now.month)
    if len(str(now.day)) > 1:
        day = str(now.day)
    else:
        day = "0" + str(now.day)
    time = str(now.year) + month + day
    layerName = time + "_" + fileName + "_01"
    children = rs.LayerChildren("7_REF::CAD")
    finalNums = []
    for child in children:
        num = rs.LayerName(child, fullpath=False).split("_")[-1]
        try:
            finalNums.append(int(num))
        except:
            finalNums.append(0)
    finalNums.sort()
    if rs.IsLayer("7_REF::CAD::" + layerName):
        num = int(finalNums[-1]) + 1
        if len(str(num)) < 2:
            finalNum = "0" + str(num)
        else:
            finalNum = str(num)
        layerName = time + "_" + fileName + "_" + finalNum
    par = rs.AddLayer("7_REF")
    cat = rs.AddLayer("CAD", parent=par)
    element = rs.AddLayer(layerName, parent=cat)
    rs.CurrentLayer(element)

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

    rs.Command('_-Import ' + savePath1 + ' _Enter')

    #get new layers added
    endLayersNames = rs.LayerNames()
    #newLayers = [item for item in currentLayers if item not in endLayersNames]
    newLayers = diff(endLayersNames, currentLayers)
    print newLayers

    for layer in newLayers:
        rs.ParentLayer(layer, element)
        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())
    for finalLayer in finalLayers:
        allObjects.append(rs.ObjectsByLayer(finalLayer))
    finalAllObjects = [item for sublist in allObjects for item in sublist]

    #Format Coordinate
    try:
        rawCoordinate = rs.GetDocumentData("Project Info",
                                           "CAD coordinate (X,Y,Z)")
    except:
        print "No CAD Coordinate specified in the Project Info"
        rawCoordinate = (0, 0, 0)
    coordinate = rawCoordinate.split(",")
    print "Aa"

    try:
        for i in range(0, 3):
            coordinate[i] = float(coordinate[i])
    except:
        coordinate = None
    if coordinate is None:
        print "CAD coordinate has an error"

    else:  #move all objects
        negVec = rs.VectorReverse(coordinate)
        rs.MoveObjects(finalAllObjects, negVec)

    if CADinMilli:
        rs.ScaleObjects(finalAllObjects, [0, 0, 0], [.001, .001, .001])

    importGroup = rs.AddGroup(str(layerName))

    rs.AddObjectsToGroup(finalAllObjects, importGroup)

    rs.ZoomSelected()
    print "Import EXECUTED"
    rs.EnableRedraw(True)
    return None
Esempio n. 9
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)
Esempio n. 10
0
    str12 = "_Angle=15 "
    str13 = "_AspectRatio=0 "
    str14 = "_Distance=0.01 "
    str15 = "_Grid=16 "
    str16 = "_MaxEdgeLength=0 "
    str17 = "_MinEdgeLength=0.0001 "
    str18 = "_Enter _Enter"

    strComb = str1 + str2 + str3 + str4 + str5 + str6 + str7 + str8 + str9 + str10
    strComb = strComb + str11 + str12 + str13 + str14 + str15 + str16 + str17 + str18

    return (strComb)


### Get objects to export ###
orig_obj = rs.GetObjects(message="Select objects to scale and export.",
                         filter=16)
obj_scale = rs.GetReal(message="Scale to export (____\" to 1')")
obj_scale = obj_scale * 1 / 12

current_UnitSystem = rs.UnitSystem()
rs.UnitSystem(2, True)

scaled_obj = rs.ScaleObjects(rs.CopyObjects(orig_obj), (0, 0, 0),
                             [obj_scale, obj_scale, obj_scale])

ExportSTLWithSettings(scaled_obj)

rs.DeleteObjects(scaled_obj)

rs.UnitSystem(current_UnitSystem, True)