Exemple #1
0
def main():
    """Main Script."""

    print("Running {fname} version {ver}...".format(fname=__name,
                                                    ver=__version))

    # STEP 0: Setup
    app = __revit__.Application
    doc = __revit__.ActiveUIDocument.Document
    uidoc = __revit__.ActiveUIDocument
    view = doc.ActiveView

    # STEP 1: Get all links in the revit model
    links = {}
    for document in app.Documents:
        if document.IsLinked:
            links[document.Title] = document

    # STEP 2: Let user select the linked document to copy from
    print("Please select the link to copy rooms from...")
    select_form = LinkSelectionForm(links=links)
    result = select_form.ShowDialog()
    print(result)
    if result == swf.DialogResult.OK:
        selected_link_title = select_form.comboBoxLink.SelectedItem
        selected_link = links[selected_link_title]

        # STEP 3: Get all Rooms from the selected link
        rooms = db.FilteredElementCollector(selected_link)\
                .OfCategory(db.BuiltInCategory.OST_Rooms)\
                .ToElements()
        print("Found {0} rooms in the linked document".format(len(rooms)))

        # STEP 4: Get Levels from the current model:
        levels = db.FilteredElementCollector(doc)\
                .OfCategory(db.BuiltInCategory.OST_Levels)\
                .WhereElementIsNotElementType()\
                .ToElements()
        print("Found {0} levels in the model.".format(len(levels)))

        # STEP 5: Create spaces for all placed Rooms in the selected link
        print("Creating spaces for all placed rooms in the selected link...")
        transaction = db.Transaction(doc)
        transaction.Start("{name} - v{ver}".format(name=__name, ver=__version))
        try:
            created_spaces = []
            for room in rooms:
                space_level = find_closest_level(levels, room.Level.Elevation)
                if room.Location:  # room is actually placed
                    location_point = room.Location.Point
                    insert_point = db.UV(location_point.X, location_point.Y)
                    created_space = doc.Create.NewSpace(
                        space_level, insert_point)
                    created_spaces.append(created_space)
                    # Save unique ID of source room in space parameter "Comments"
                    comment_param = created_space.get_Parameter(
                        db.BuiltInParameter.ALL_MODEL_INSTANCE_COMMENTS)
                    comment_param.Set(room.UniqueId)
            print("Created {0} spaces.".format(len(created_spaces)))
        except Exception as ex:
            print("Exception: {0}".format(ex))
            transaction.RollBack()
        else:
            transaction.Commit()
            print("Done.")
    else:
        print("No link selected, nothing to do.")
Exemple #2
0
import Autodesk.Revit.DB as DB


__doc__ = 'Reorients the current 3D view camera, perpendicular to the' \
          'selected face. This tool will set a sketch plane over the ' \
          'selected face for 3d drawing.'

face = selection.utils.pick_face()

if face and isinstance(curview, DB.View3D):
    t = DB.Transaction(doc, 'Orient to Selected Face')
    t.Start()

    # calculate normal
    if HOST_APP.is_newer_than(2015):
        normal_vec = face.ComputeNormal(DB.UV(0, 0))
    else:
        normal_vec = face.Normal

    # create base plane for sketchplane
    if HOST_APP.is_newer_than(2016):
        base_plane = DB.Plane.CreateByNormalAndOrigin(normal_vec, face.Origin)
    else:
        base_plane = DB.Plane(normal_vec, face.Origin)

    # now that we have the base_plane and normal_vec
    # let's create the sketchplane
    sp = DB.SketchPlane.Create(doc, base_plane)

    # orient the 3D view looking at the sketchplane
    curview.OrientTo(normal_vec.Negate())