Пример #1
0
def LocationShift(doc, point):
    cPoint = point
    basePt = doc.ActiveProjectLocation.GetProjectPosition(XYZ(0, 0, 0))
    ew = basePt.EastWest
    ns = basePt.NorthSouth
    ele = basePt.Elevation
    angle = basePt.Angle
    basexyz = [ew, ns, ele, angle]
    rotationTransform = Transform.CreateRotation(XYZ.BasisZ, angle)
    translationVector = XYZ(ew, ns, ele)
    translationTransform = Transform.CreateTranslation(translationVector)
    finalTransform = translationTransform.Multiply(rotationTransform)
    aPoint = Transform.CreateRotation(XYZ.BasisZ, angle).OfPoint(XYZ(cPoint.X, cPoint.Y, cPoint.Z))
    bPoint = XYZ(aPoint.X + ew, aPoint.Y + ns, aPoint.Z + ele)
    return(bPoint)
Пример #2
0
def CreateCubeStrut(csdname, csdwidth, csdlength, csdheight, csdstart,
                    csdrotation, scdthickness):
    #print(csdname)
    vector = XYZ(0, 0, csdheight * -1)
    pp = Plane.CreateByNormalAndOrigin(vector, csdstart)

    trans = Transform.CreateRotationAtPoint(vector, csdrotation, csdstart)

    point1 = csdstart + XYZ(csdwidth / 2, csdlength / 2, 0)
    point2 = csdstart + XYZ(csdwidth / 2 * -1, csdlength / 2, 0)
    point3 = csdstart + XYZ(csdwidth / 2 * -1, csdlength / 2 * -1, 0)
    point4 = csdstart + XYZ(csdwidth / 2, csdlength / 2 * -1, 0)

    profileorigion = CurveLoop().Create([
        Line.CreateBound(point1, point2),
        Line.CreateBound(point2, point3),
        Line.CreateBound(point3, point4),
        Line.CreateBound(point4, point1)
    ])

    finalProfile = CurveLoop.CreateViaTransform(profileorigion, trans)
    geo = GeometryCreationUtilities.CreateExtrusionGeometry([finalProfile],
                                                            vector, csdheight)
    ele = DirectShape.CreateElement(doc, ElementId(-2000151))
    ele.SetShape([geo])
    ele.SetName(csdname)
    return ele.Id
curview = doc.ActiveView

if isinstance(curview, View3D) and curview.IsSectionBoxActive:
    try:
        ref = uidoc.Selection.PickObject(ObjectType.Face)
        el = doc.GetElement(ref.ElementId)
        face = el.GetGeometryObjectFromReference(ref)
        box = curview.GetSectionBox()
        norm = face.ComputeNormal(UV(0, 0)).Normalize()
        boxNormal = box.Transform.Basis[0].Normalize()
        angle = norm.AngleTo(boxNormal)
        axis = XYZ(0, 0, 1.0)
        origin = XYZ(box.Min.X + (box.Max.X - box.Min.X) / 2,
                     box.Min.Y + (box.Max.Y - box.Min.Y) / 2, 0.0)
        if norm.Y * boxNormal.X < 0:
            rotate = Transform.CreateRotationAtPoint(axis, Math.PI / 2 - angle,
                                                     origin)
        else:
            rotate = Transform.CreateRotationAtPoint(axis, angle, origin)
        box.Transform = box.Transform.Multiply(rotate)
        t = Transaction(doc, 'Orient Section Box to Face')
        t.Start()
        curview.SetSectionBox(box)
        uidoc.RefreshActiveView()
        t.Commit()
    except:
        pass
elif isinstance(curview, View3D) and not curview.IsSectionBoxActive:
    TaskDialog.Show("pyRevit", "The section box for View3D isn't active.")
else:
    TaskDialog.Show("pyRevit",
                    "You must be on a 3D view for this tool to work.")
Пример #4
0

__doc__ = 'Select the shared point of the model '\
          'This is helpful check project info'

# input ---------------------
path = 'C:\\Users\\loum\\Documents\\Pyscripts\\'
ew = doc.ActiveProjectLocation.GetProjectPosition(XYZ(
    0, 0, 0)).EastWest * float(-1.0)
ns = doc.ActiveProjectLocation.GetProjectPosition(XYZ(
    0, 0, 0)).NorthSouth * float(-1.0)
elevation = doc.ActiveProjectLocation.GetProjectPosition(XYZ(
    0, 0, 0)).Elevation * float(-1.0)
angle = doc.ActiveProjectLocation.GetProjectPosition(XYZ(
    0, 0, 0)).Angle * float(-1.0)
rotationTransform = Transform.CreateRotation(XYZ.BasisZ, angle)
translationVector = XYZ(ew, ns, elevation)
translationTransform = Transform.CreateTranslation(translationVector)
finalTransform = translationTransform.Multiply(rotationTransform)
count = 0
outLst = []
# Just to be sure how many points will be created and each list are the same length
print(len(Pointdata.pointX))
print(len(Pointdata.pointY))
print(len(Pointdata.pointZ))

# Transaction Start
t = Transaction(doc, 'Add CLash Points')

# Clash point Creation
FSymbol = DB.FilteredElementCollector(doc) \
Пример #5
0
def run(sel, location_option):
    logger.info("Location option: %s " % location_option)
    docs = __revit__.Application.Documents
    # where to copy
    src_doc = __revit__.ActiveUIDocument.Document
    docs = filter(lambda d: not d.IsLinked and d != src_doc, docs)
    trg_docs = forms.SelectFromList.show(docs,
                                         name_attr='Title',
                                         title='Documents to paste selection',
                                         button_name='Paste',
                                         multiselect=True)
    null_point_src = None
    null_point_cat = None
    if location_option == "Project Base Point":
        null_point_cat = BuiltInCategory.OST_SharedBasePoint
    elif location_option == "Shared Site Point":
        null_point_cat = BuiltInCategory.OST_ProjectBasePoint

    if null_point_cat:
        null_point_src = FilteredElementCollector(
            src_doc).WhereElementIsNotElementType().OfCategory(
                null_point_cat).WhereElementIsNotElementType().ToElements()
        if len(null_point_src) == 0:
            logger.warning(
                "Point for location option wasn't found in source document. Default alignment will be used"
            )

    for trg_doc in trg_docs:
        logger.debug(trg_doc)
        logger.debug(len(trg_doc.Title))
        s = "Copy %d elements from %s to %s" % (len(sel), src_doc.Title,
                                                trg_doc.Title)
        print(s)
        # logger.info(s) # TODO Fix - cannot log cyrylic project name

        # Transform
        transform_vector = None
        if null_point_src:
            null_point_trg = FilteredElementCollector(
                trg_doc).WhereElementIsNotElementType().OfCategory(
                    null_point_cat).WhereElementIsNotElementType().ToElements(
                    )
            if len(null_point_trg) == 0:
                logger.warning(
                    "Point for location option wasn't found in target document. Document will be skipped"
                )
                continue
            # _transform_vector = null_point_trg[0].GetTransform().BasisX - null_point_src[0].GetTransform().BasisX
            print(null_point_trg[0].BoundingBox[null_point_trg[0]])
            transform_vector = Transform.CreateTranslation(
                null_point_trg[0].BoundingBox.Min -
                null_point_src[0].BoundingBox.Min)

        t = Transaction(
            trg_doc,
            __title__ + " - %d elements from %s" % (len(sel), src_doc.Title))
        t.Start()
        try:
            ElementTransformUtils.CopyElements(src_doc, List[ElementId](sel),
                                               trg_doc, transform_vector, None)
            t.Commit()
        except Exception as exc:
            t.RollBack()
            logger.error(exc)
Пример #6
0
if not clashPoint:
    print('Please Load the Clash Point Family')
    print(clashPoint.Family.Name)
    print(clashPoint)
    count = 0
    elements = []
    for el in Pointdata.pointX:
        x = float(Pointdata.pointX[count]) + ew
        y = float(Pointdata.pointY[count]) + ns
        z = float(Pointdata.pointZ[count]) + elevation
        clashName = str('No. ' + str(count + 1) + ' ID: ' +
                        Pointdata.clashName[count])
        clashwithID = str(Pointdata.otherFile[count] + ' ID: ' +
                          Pointdata.clashwithID[count])
        pnt = XYZ(x, y, z)
        bPnt = Transform.CreateRotation(XYZ.BasisZ, angle).OfPoint(pnt)
        print(bPnt)

        # Clash point creation
        boxes = doc.Create.NewFamilyInstance(
            bPnt, clashPoint, Structure.StructuralType.NonStructural)
        elements.append(boxes)

        boxes.LookupParameter('Clash Name').Set(clashName)
        boxes.LookupParameter('Clash with ID').Set(clashwithID)
        count += 1

    selSet = []

    for el in elements:
        selSet.append(el.Id)
Пример #7
0
def CreateCurveDuct(name, width, height, thickness, startO, endO, middleO):
    #correction = XYZ(0, 0, height / 2)
    correction = XYZ(0, 0, 0)
    #print(name)
    start = startO + correction
    end = endO + correction
    middle = middleO + correction
    ele = ()
    if start.X == end.X and start.Y == end.Y and start.Z == end.Z:
        print("Curve error, start is the same as end")
        return None
    else:
        path = Arc.Create(start, end, middle)
        #print(name)
        #print(start)
        #print(end)
        #print(middle)
        #print(path.Center)
        pathCurve = CurveLoop().Create([path])
        pp = Plane.CreateByNormalAndOrigin(
            path.ComputeDerivatives(0, True).BasisX, start)
        profile1 = Arc.Create(pp, width / 2 + thickness, 0, math.pi)
        normalVec = path.ComputeDerivatives(0, True).BasisX
        interVector = XYZ((normalVec).Y * -1, (normalVec).X, 0)
        a = profile1.GetEndPoint(0)
        vector1 = a - start
        vector2 = XYZ((a - start).X, (a - start).Y, 0)
        # angle = vector2.AngleTo(vector1)
        angle = vector1.AngleOnPlaneTo(interVector, (end - start).Normalize())
        #print(angle)
        trans1 = Transform.CreateRotationAtPoint(
            path.ComputeDerivatives(0, True).BasisX, angle, start)
        trans2 = Transform.CreateRotationAtPoint(
            path.ComputeDerivatives(0, True).BasisX, angle * (-1), start)
        trans3 = Transform.CreateRotationAtPoint(
            path.ComputeDerivatives(0, True).BasisX,
            angle * (-1) + math.pi / 2, start)
        trans4 = Transform.CreateRotationAtPoint(
            path.ComputeDerivatives(0, True).BasisX, angle + math.pi / 2,
            start)
        b = profile1.GetEndPoint(1)
        profile2 = Arc.Create(pp, height / 2 + thickness, math.pi / 2,
                              math.pi * 3 / 2)
        c = profile2.GetEndPoint(0)
        d = profile2.GetEndPoint(1)
        point1 = a + c - start
        point2 = b + c - start
        point3 = b + d - start
        point4 = a + d - start

        numbers = {}
        list = []
        l1 = Line.CreateBound(point1, point2)
        l1Test1 = l1.CreateTransformed(trans1)
        l1Test2 = l1.CreateTransformed(trans2)
        l1Test3 = l1.CreateTransformed(trans3)
        l1Test4 = l1.CreateTransformed(trans4)
        numbers[abs(l1Test1.GetEndPoint(0).Z -
                    l1Test1.GetEndPoint(1).Z)] = trans1
        numbers[abs(l1Test2.GetEndPoint(0).Z -
                    l1Test2.GetEndPoint(1).Z)] = trans2
        numbers[abs(l1Test3.GetEndPoint(0).Z -
                    l1Test3.GetEndPoint(1).Z)] = trans3
        numbers[abs(l1Test4.GetEndPoint(0).Z -
                    l1Test4.GetEndPoint(1).Z)] = trans4
        list.append(abs(l1Test1.GetEndPoint(0).Z - l1Test1.GetEndPoint(1).Z))
        list.append(abs(l1Test2.GetEndPoint(0).Z - l1Test2.GetEndPoint(1).Z))
        list.append(abs(l1Test3.GetEndPoint(0).Z - l1Test3.GetEndPoint(1).Z))
        list.append(abs(l1Test4.GetEndPoint(0).Z - l1Test4.GetEndPoint(1).Z))
        list.sort()
        profileorigion = CurveLoop().Create([
            Line.CreateBound(point1, point2),
            Line.CreateBound(point2, point3),
            Line.CreateBound(point3, point4),
            Line.CreateBound(point4, point1)
        ])
        profile = CurveLoop.CreateViaTransform(profileorigion,
                                               numbers[list[0]])

        geo = GeometryCreationUtilities.CreateSweptGeometry(
            pathCurve, 0, path.GetEndParameter(0), [profile])
        ele = DirectShape.CreateElement(doc, ElementId(-2000151))
        ele.SetShape([geo])
        ele.SetName(name)
        return ele.Id
Пример #8
0
def CreateStraightDuct(csdname, csdwidth, csdheight, thickness, csdstartO,
                       csdendO, csdlength):
    #print(csdname)
    #correction = XYZ(0, 0, csdheight / 2)
    correction = XYZ(0, 0, 0)
    csdstart = csdstartO + correction
    csdend = csdendO + correction
    if (csdend - csdstart).GetLength() > 0.1:
        pp = Plane.CreateByNormalAndOrigin(csdend - csdstart, csdstart)
        profile1 = Arc.Create(pp, csdwidth / 2 + thickness, 0, math.pi)
        interVector = XYZ((csdend - csdstart).Y * -1, (csdend - csdstart).X, 0)
        a = profile1.GetEndPoint(0)
        b = profile1.GetEndPoint(1)
        profile2 = Arc.Create(pp, csdheight / 2 + thickness, math.pi / 2,
                              math.pi * 3 / 2)
        c = profile2.GetEndPoint(0)
        d = profile2.GetEndPoint(1)
        point1 = a + c - csdstart
        point2 = b + c - csdstart
        point3 = b + d - csdstart
        point4 = a + d - csdstart
        l1 = Line.CreateBound(point1, point2)

        vector1 = point1 - point2
        vector2 = XYZ((point1 - point2).X, (point1 - point2).Y, 0)
        #print(vector1)
        #print(vector2)
        angle = vector1.AngleOnPlaneTo(interVector,
                                       (csdend - csdstart).Normalize())
        #angle = vector2.AngleTo(vector1)
        #print(angle)
        #print(point1)
        #print(point2)
        trans1 = Transform.CreateRotationAtPoint(csdend - csdstart, angle,
                                                 csdstart)
        trans2 = Transform.CreateRotationAtPoint(csdend - csdstart,
                                                 angle * (-1), csdstart)
        trans3 = Transform.CreateRotationAtPoint(csdend - csdstart,
                                                 angle * (-1) + math.pi / 2,
                                                 csdstart)
        trans4 = Transform.CreateRotationAtPoint(csdend - csdstart,
                                                 angle + math.pi / 2, csdstart)
        #print(angle)
        #print(angle*(-1))
        #print(angle * (-1) + math.pi/2)
        #print(angle + math.pi / 2)

        #print(point4)
        profileorigion = CurveLoop().Create([
            Line.CreateBound(point1, point2),
            Line.CreateBound(point2, point3),
            Line.CreateBound(point3, point4),
            Line.CreateBound(point4, point1)
        ])
        #print(l1.GetEndPoint(0))
        #print(l1.GetEndPoint(1))

        numbers = {}
        list = []
        l1Test1 = l1.CreateTransformed(trans1)
        l1Test2 = l1.CreateTransformed(trans2)
        l1Test3 = l1.CreateTransformed(trans3)
        l1Test4 = l1.CreateTransformed(trans4)

        numbers[abs(l1Test1.GetEndPoint(0).Z -
                    l1Test1.GetEndPoint(1).Z)] = trans1
        numbers[abs(l1Test2.GetEndPoint(0).Z -
                    l1Test2.GetEndPoint(1).Z)] = trans2
        numbers[abs(l1Test3.GetEndPoint(0).Z -
                    l1Test3.GetEndPoint(1).Z)] = trans3
        numbers[abs(l1Test4.GetEndPoint(0).Z -
                    l1Test4.GetEndPoint(1).Z)] = trans4

        list.append(abs(l1Test1.GetEndPoint(0).Z - l1Test1.GetEndPoint(1).Z))
        list.append(abs(l1Test2.GetEndPoint(0).Z - l1Test2.GetEndPoint(1).Z))
        list.append(abs(l1Test3.GetEndPoint(0).Z - l1Test3.GetEndPoint(1).Z))
        list.append(abs(l1Test4.GetEndPoint(0).Z - l1Test4.GetEndPoint(1).Z))
        list.sort()
        finalProfile = CurveLoop.CreateViaTransform(profileorigion,
                                                    numbers[list[0]])
        geo = GeometryCreationUtilities.CreateExtrusionGeometry(
            [finalProfile], csdend - csdstart, csdlength)
        ele = DirectShape.CreateElement(doc, ElementId(-2000151))
        ele.SetShape([geo])
        ele.SetName(csdname)
        return ele.Id
    else:
        print("Duct too small")
        return None
Пример #9
0
def AngleAdjustment(csdend, csdstart, csdwidth, csdheight, thickness):
    pp = Plane.CreateByNormalAndOrigin(csdend - csdstart, csdstart)
    interVector = XYZ((csdend - csdstart).Y * -1, (csdend - csdstart).X, 0)

    profile1 = Arc.Create(pp, csdwidth / 2 + thickness, 0, math.pi)
    #print(pp.XVec)
    #print(pp.YVec)
    a = profile1.GetEndPoint(0)
    b = profile1.GetEndPoint(1)
    profile2 = Arc.Create(pp, csdheight / 2 + thickness, math.pi / 2,
                          math.pi * 3 / 2)

    c = profile2.GetEndPoint(0)
    d = profile2.GetEndPoint(1)
    point1 = a + c - csdstart
    point2 = b + c - csdstart
    point3 = b + d - csdstart
    point4 = a + d - csdstart
    l1 = Line.CreateBound(point1, point2)

    vector1 = point1 - point2
    vector2 = XYZ((point1 - point2).X, (point1 - point2).Y, 0)
    vector3 = point1 - point4
    #print(vector1)
    #print(vector2)
    angle = vector1.AngleOnPlaneTo(interVector,
                                   (csdend - csdstart).Normalize())
    #print(angle)
    #print(point1)
    #print(point2)
    trans1 = Transform.CreateRotationAtPoint(csdend - csdstart, angle, point2)
    trans2 = Transform.CreateRotationAtPoint(csdend - csdstart, angle * (-1),
                                             point2)
    trans3 = Transform.CreateRotationAtPoint(csdend - csdstart,
                                             angle * (-1) + math.pi / 2,
                                             point2)
    trans4 = Transform.CreateRotationAtPoint(csdend - csdstart,
                                             angle + math.pi / 2, point2)
    #print(angle)
    #print(angle*(-1))
    #print(angle * (-1) + math.pi/2)
    #print(angle + math.pi / 2)

    #print(point4)
    profileorigion = CurveLoop().Create([
        Line.CreateBound(point1, point2),
        Line.CreateBound(point2, point3),
        Line.CreateBound(point3, point4),
        Line.CreateBound(point4, point1)
    ])
    #print(l1.GetEndPoint(0))
    #print(l1.GetEndPoint(1))

    numbers = {}
    list = []
    l1Test1 = l1.CreateTransformed(trans1)
    l1Test2 = l1.CreateTransformed(trans2)
    l1Test3 = l1.CreateTransformed(trans3)
    l1Test4 = l1.CreateTransformed(trans4)
    #print(l1Test1.GetEndPoint(0))
    #print(l1Test1.GetEndPoint(1))
    #print(l1Test2.GetEndPoint(0))
    #print(l1Test2.GetEndPoint(1))
    #print(l1Test3.GetEndPoint(0))
    #print(l1Test3.GetEndPoint(1))
    #print(l1Test4.GetEndPoint(0))
    #print(l1Test4.GetEndPoint(1))
    numbers[abs(l1Test1.GetEndPoint(0).Z - l1Test1.GetEndPoint(1).Z)] = trans1
    numbers[abs(l1Test2.GetEndPoint(0).Z - l1Test2.GetEndPoint(1).Z)] = trans2
    numbers[abs(l1Test3.GetEndPoint(0).Z - l1Test3.GetEndPoint(1).Z)] = trans3
    numbers[abs(l1Test4.GetEndPoint(0).Z - l1Test4.GetEndPoint(1).Z)] = trans4

    list.append(abs(l1Test1.GetEndPoint(0).Z - l1Test1.GetEndPoint(1).Z))
    list.append(abs(l1Test2.GetEndPoint(0).Z - l1Test2.GetEndPoint(1).Z))
    list.append(abs(l1Test3.GetEndPoint(0).Z - l1Test3.GetEndPoint(1).Z))
    list.append(abs(l1Test4.GetEndPoint(0).Z - l1Test4.GetEndPoint(1).Z))
    list.sort()