Ejemplo n.º 1
0
def get_tags_by_type(all_views):
    # find available tags in project
    tags_by_type = {}

    for cat_name, cat in switches.items():
        cl_tags = FilteredElementCollector(doc)
        tags = cl_tags.OfCategory(cat)

        # Find only current view tags, if not ShiftClick
        if not all_views:
            tags = tags.OwnedByView(doc.ActiveView.Id)

        tags = tags.WhereElementIsNotElementType().ToElements()

        tags = filter(lambda t: type(t) != FamilyInstance, tags)

        if len(tags) == 0:
            continue
        else:
            logger.debug("%d %s found" % (len(tags), cat_name))

            tags_by_view = {}

            for e in tags:
                v = e.OwnerViewId
                if not v:
                    continue

                if v not in tags_by_view.keys():
                    tags_by_view[v] = []
                tags_by_view[v].append(e)

            tags_by_type[cat_name] = tags_by_view

    return tags_by_type
Ejemplo n.º 2
0
def collect_spaces():
    """Collect all the spaces in the current Revit document."""
    document = DocumentManager.Instance.CurrentDBDocument
    collector = FilteredElementCollector(document)
    collector.OfCategory(BuiltInCategory.OST_MEPSpaces)
    room_iter = collector.GetElementIdIterator()
    room_iter.Reset()
    return tuple(document.GetElement(el_id) for el_id in room_iter)
Ejemplo n.º 3
0
def collectRooms(document=None):
    """Collect all the rooms in the current Revit document."""
    if not document:
        document = DocumentManager.Instance.CurrentDBDocument
    collector = FilteredElementCollector(document)
    collector.OfCategory(BuiltInCategory.OST_Rooms)
    roomIter = collector.GetElementIdIterator()
    roomIter.Reset()
    return tuple(document.GetElement(elId) for elId in roomIter)
Ejemplo n.º 4
0
def collect_curtain_panels():
    doc = DocumentManager.Instance.CurrentDBDocument

    collector = FilteredElementCollector(doc)
    collector.OfCategory(BuiltInCategory.OST_CurtainWallPanels)
    collector.OfClass(FamilyInstance)

    cw_element_collector = collector.GetElementIdIterator()
    cw_element_collector.Reset()

    cw_collector = (doc.GetElement(cw_id) for cw_id in cw_element_collector)
    return tuple(cw.ToDSType(True) for cw in cw_collector
                 if cw.Symbol.Family.Name == 'System Panel')
Ejemplo n.º 5
0
def selectDuplicateTags(selected_switch="OST_RoomTags"):
    uidoc = __revit__.ActiveUIDocument
    doc = __revit__.ActiveUIDocument.Document
    av = doc.ActiveView
    cl_tags = FilteredElementCollector(doc)
    tags = cl_tags.OfCategory(switches[selected_switch]
                              ).WhereElementIsNotElementType().ToElementIds()
    logger.debug(str(len(tags)) + " tags found")
    tags_dict = {}
    views_dict = []
    for eId in tags:
        e = doc.GetElement(eId)
        try:
            e.View
        except:
            logger.debug(str(eId) + " is element type")
            continue
        try:

            v = e.View
            #пропускает, если тэг не на текущем виде - оптимизировать через фильтр!
            if not __shiftclick__ and v.Id != av.Id:
                logger.debug(str(eId) + " not on active view" + v.Name)
                continue

            text = str(e.Room.Id) + "_" + str(v.Id)
            views_dict.append(int(str(e.View.Id)))
            if text not in tags_dict:
                tags_dict[text] = []
            tags_dict[text].append(int(eId.ToString()))
        except:
            logger.info(str(eId) + " unknown exception")

    ttags = []
    for t in tags_dict:
        if len(tags_dict[t]) > 1:
            i = 0
            tags_dict[t].sort()
            for tt in tags_dict[t]:
                if i != 0:
                    ttags.append(tt)
                i += 1

    ttags_text = ",".join(map(lambda x: str(x), ttags))

    selection = uidoc.Selection
    collection = List[ElementId](map(lambda x: ElementId(int(x)), ttags))

    selection.SetElementIds(collection)
    logger.info(str(len(ttags)) + " tags selected")
Ejemplo n.º 6
0
    def select_clouds(self, sender, args):
        self.my_window.Close()
        cl = FilteredElementCollector(doc)
        revclouds = cl.OfCategory(BuiltInCategory.OST_RevisionClouds).WhereElementIsNotElementType()
        
        # get selected revision
        srindex = self.my_listView_revisionList.SelectedIndex
        if srindex >= 0:
            sr = doc.GetElement(ElementId(self.revs[srindex]))
        else:
            return

        clouds = []
        
        for revcloud in revclouds:
            if revcloud.RevisionId.IntegerValue == sr.Id.IntegerValue:
                clouds.append(revcloud.Id)

        uidoc.Selection.SetElementIds(List[ElementId](clouds))
Ejemplo n.º 7
0
try:
    sel = []
    fromStyleLine = doc.GetElement(
        uidoc.Selection.PickObject(
            ObjectType.Element, 'Pick a line with the style to be replaced.'))
    fromStyle = fromStyleLine.LineStyle
    toStyleLine = doc.GetElement(
        uidoc.Selection.PickObject(ObjectType.Element,
                                   'Pick a line with the source style.'))
    toStyle = toStyleLine.LineStyle

    linelist = []

    cl = FilteredElementCollector(doc)
    cllines = cl.OfCategory(
        BuiltInCategory.OST_Lines
        or BuiltInCategory.OST_SketchLines).WhereElementIsNotElementType()
    for c in cllines:
        if c.LineStyle.Name == fromStyle.Name:
            linelist.append(c)
        # print( '{0:<10} {1:<25}{2:<8} {3:<15}'.format(c.Id, c.GetType().Name, c.LineStyle.Id, c.LineStyle.Name) )

    if len(linelist) > 100:
        verbose = False
    with Transaction(doc, 'Swap Line Styles') as t:
        t.Start()
        for line in linelist:
            if line.Category.Name != '<Sketch>' and line.GroupId < ElementId(
                    0):
                if verbose:
                    print('LINE FOUND:\t{0:<10} {1:<25}{2:<8} {3:<15}'.format(
Ejemplo n.º 8
0
import os.path
from pprint import pprint
import time
import itertools

from Autodesk.Revit.DB import FilteredElementCollector, BuiltInCategory, ViewType, ElementCategoryFilter
from Autodesk.Revit.UI import TaskDialog, TaskDialogCommonButtons
from Autodesk.Revit.UI.Selection import ISelectionFilter, ObjectType
from Autodesk.Revit.DB import BuiltInCategory, ElementId, XYZ, ElementTransformUtils
from System.Collections.Generic import List
from Autodesk.Revit.DB import Transaction, TransactionGroup

uidoc = __revit__.ActiveUIDocument
doc = __revit__.ActiveUIDocument.Document
doc_info = doc.ProjectInformation
ppath = doc.PathName
pfilename = os.path.splitext(os.path.split(ppath)[1])[0]

dir_path = os.path.dirname(os.path.realpath(__file__))
#dir_path = os.path.dirname(ppath)

cl_all = FilteredElementCollector(doc).WhereElementIsNotElementType()
# basepoint2 = ElementCategoryFilter(BuiltInCategory.OST_ProjectBasePoint, True)
basepoint = cl_all.OfCategory(
    BuiltInCategory.OST_ProjectBasePoint).ToElementIds()

uidoc.ShowElements(basepoint[0])
Ejemplo n.º 9
0
__doc__ = 'Deletes all view parameter filters that has not been listed on any views. This includes sheets as well.'

from Autodesk.Revit.DB import Transaction, FilteredElementCollector, BuiltInCategory

uidoc = __revit__.ActiveUIDocument
doc = __revit__.ActiveUIDocument.Document
selection = [
    doc.GetElement(elId)
    for elId in __revit__.ActiveUIDocument.Selection.GetElementIds()
]

delConst = True

cl = FilteredElementCollector(doc)
clconst = cl.OfCategory(
    BuiltInCategory.OST_Constraints).WhereElementIsNotElementType()

constlst = set()


def listConsts(el, clconst):
    print('THIS OBJECT ID: {0}'.format(el.Id))
    for cnst in clconst:
        refs = [(x.ElementId, x) for x in cnst.References]
        elids = [x[0] for x in refs]
        if el.Id in elids:
            constlst.add(cnst)
            print("CONST TYPE: {0} # OF REFs: {1} CONST ID: {2}".format(
                cnst.GetType().Name.ljust(28),
                str(cnst.References.Size).ljust(24), cnst.Id))
            for t in refs:
Ejemplo n.º 10
0
it under the terms of the GNU General Public License version 3, as published by
the Free Software Foundation.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

See this link for a copy of the GNU General Public License protecting this package.
https://github.com/eirannejad/pyRevit/blob/master/LICENSE
'''

from Autodesk.Revit.DB import FilteredElementCollector, BuiltInCategory

uidoc = __revit__.ActiveUIDocument
doc = __revit__.ActiveUIDocument.Document
selection = [
    doc.GetElement(elId)
    for elId in __revit__.ActiveUIDocument.Selection.GetElementIds()
]

cl = FilteredElementCollector(doc)
list = cl.OfCategory(
    BuiltInCategory.OST_Rooms).WhereElementIsNotElementType().ToElements()

for el in list:
    print('ROOM NAME: {0} ROOM NUMBER: {1} ROOM ID: {2}'.format(
        el.LookupParameter('Name').AsString().ljust(30),
        el.LookupParameter('Number').AsString().ljust(20), el.Id))

print('\n\nTOTAL ROOMS FOUND: {0}'.format(len(list)))
Ejemplo n.º 11
0
pyRevit is a free set of scripts for Autodesk Revit: you can redistribute it and/or modify
it under the terms of the GNU General Public License version 3, as published by
the Free Software Foundation.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

See this link for a copy of the GNU General Public License protecting this package.
https://github.com/eirannejad/pyRevit/blob/master/LICENSE
'''

__doc__ = 'Lists all levels in this model.'

from Autodesk.Revit.DB import FilteredElementCollector, BuiltInCategory

uidoc = __revit__.ActiveUIDocument
doc = __revit__.ActiveUIDocument.Document
selection = [
    doc.GetElement(elId)
    for elId in __revit__.ActiveUIDocument.Selection.GetElementIds()
]

cl = FilteredElementCollector(doc)
list = cl.OfCategory(BuiltInCategory.OST_Levels).WhereElementIsNotElementType()

for i in list:
    print('Level ID:\t{1}\t\t\tName:\t{0}'.format(i.Name, i.Id.IntegerValue))
Ejemplo n.º 12
0
This file is part of pyRevit repository at https://github.com/eirannejad/pyRevit

pyRevit is a free set of scripts for Autodesk Revit: you can redistribute it and/or modify
it under the terms of the GNU General Public License version 3, as published by
the Free Software Foundation.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

See this link for a copy of the GNU General Public License protecting this package.
https://github.com/eirannejad/pyRevit/blob/master/LICENSE
'''

from Autodesk.Revit.DB import FilteredElementCollector, BuiltInCategory

uidoc = __revit__.ActiveUIDocument
doc = __revit__.ActiveUIDocument.Document
selection = [
    doc.GetElement(elId)
    for elId in __revit__.ActiveUIDocument.Selection.GetElementIds()
]

cl = FilteredElementCollector(doc)
scopeboxes = cl.OfCategory(BuiltInCategory.OST_VolumeOfInterest
                           ).WhereElementIsNotElementType().ToElements()

for el in scopeboxes:
    print('SCOPEBOX: {0}'.format(el.Name))
    cl = FilteredElementCollector(doc)
    gstyles = [i for i in cl.OfClass(GraphicsStyle).ToElements()]

    for gs in gstyles:
        if gs.GraphicsStyleCategory.Parent:
            parent = gs.GraphicsStyleCategory.Parent.Name
        else:
            parent = '---'
        if gs.GraphicsStyleCategory.GetHashCode() > 0:
            print('NAME: {0} CATEGORY:{2} PARENT: {3} ID: {1}'.format(
                gs.Name.ljust(50), gs.Id,
                gs.GraphicsStyleCategory.Name.ljust(50), parent.ljust(50)))

elif selected_switch == 'Grids':
    cl = FilteredElementCollector(doc)
    list = cl.OfCategory(
        BuiltInCategory.OST_Grids).WhereElementIsNotElementType().ToElements()

    for el in list:
        print('GRID: {0} ID: {1}'.format(
            el.Name,
            el.Id,
        ))

elif selected_switch == 'Line Patterns':
    cl = FilteredElementCollector(doc).OfClass(LinePatternElement)
    for i in cl:
        print(i.Name)

elif selected_switch == 'Line Styles':
    c = doc.Settings.Categories.get_Item(BuiltInCategory.OST_Lines)
    subcats = c.SubCategories
Ejemplo n.º 14
0
See this link for a copy of the GNU General Public License protecting this package.
https://github.com/eirannejad/pyRevit/blob/master/LICENSE
"""

__doc__ =   'Sometimes when a revision cloud is placed inside a view (instead of a sheet) and the view is' \
            ' placed on a sheet, the revision schedule on the sheet does not get updated with the revision' \
            ' number of the cloud inside the sheeted view. This script verifies that the sheet revision' \
            ' schedule is actually listing all the revisions shown inside the views of that sheet.'

from Autodesk.Revit.DB import FilteredElementCollector, BuiltInCategory, ViewSheet, ElementId

doc = __revit__.ActiveUIDocument.Document

# Collecting all revisions
cl = FilteredElementCollector(doc)
revclouds = cl.OfCategory(BuiltInCategory.OST_RevisionClouds).WhereElementIsNotElementType()
# Collecting all sheets
cl_views = FilteredElementCollector(doc)
shts = cl_views.OfCategory(BuiltInCategory.OST_Sheets).WhereElementIsNotElementType().ToElements()
sheets = sorted(shts, key=lambda x: x.SheetNumber)
# make a dictionary of all viewports on each sheet
sheetvpdict = { sh.Id.IntegerValue:[doc.GetElement(x).ViewId for x in sh.GetAllViewports()] for sh in sheets}
# make a dictionary of all revisions and the associated sheets
sheetrevs = {sh.Id.IntegerValue:[] for sh in sheets}

atleastonecrazysheetwasfound = False

print('SEARCHING...\n')

for revcloud in revclouds:
    # get revision info
Ejemplo n.º 15
0
"""Lists all sheets and views that the selected elements is visible in."""

from collections import defaultdict, namedtuple
from scriptutils import this_script
from revitutils import doc, uidoc, selection
from Autodesk.Revit.DB import FilteredElementCollector, BuiltInCategory

VportView = namedtuple('VportView', ['viewport', 'view'])

cl_views = FilteredElementCollector(doc)
allsheets = cl_views.OfCategory(BuiltInCategory.OST_Sheets) \
                    .WhereElementIsNotElementType() \
                    .ToElements()

sorted_sheets = sorted(allsheets, key=lambda x: x.SheetNumber)


def find_sheeted_views(sheet):
    return [VportView(doc.GetElement(vp),
                      doc.GetElement(doc.GetElement(vp).ViewId)) \
                for vp in sheet.GetAllViewports()]


sheet_dict = defaultdict(list)
for sheet in sorted_sheets:
    for vpview_tuple in find_sheeted_views(sheet):
        view_els = FilteredElementCollector(doc, vpview_tuple.view.Id) \
                   .WhereElementIsNotElementType() \
                   .ToElementIds()

        for el_id in selection.element_ids:
Ejemplo n.º 16
0
doc = __revit__.ActiveUIDocument.Document
doc_info = doc.ProjectInformation
ppath = doc.PathName
pfilename = os.path.splitext(os.path.split(ppath)[1])[0]

dir_path = os.path.dirname(os.path.realpath(__file__))
#dir_path = os.path.dirname(ppath)

print os.path.dirname(os.path.realpath(__file__))
import os

uidoc = __revit__.ActiveUIDocument
doc = __revit__.ActiveUIDocument.Document

cl_sheets = FilteredElementCollector(doc)
allsheets = cl_sheets.OfCategory(BuiltInCategory.OST_Sheets)
sheets = filter(
    lambda x: (str(x.GetType()) == 'Autodesk.Revit.DB.ViewSheet' and not x.
               IsTemplate),  # and not x.IsTemplate
    allsheets)
selIds = uidoc.Selection.GetElementIds()
sheets = []
for eId in selIds:
    sheets.append(doc.GetElement(eId))

t = Transaction(doc, "Toggle views parameters")
t.Start()
for v in sheets:
    print "v"
    part = 0
    # for p in v.GetParameters("INF_Album"):
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

See this link for a copy of the GNU General Public License protecting this package.
https://github.com/eirannejad/pyRevit/blob/master/LICENSE
'''

from Autodesk.Revit.DB import FilteredElementCollector, BuiltInCategory
doc = __revit__.ActiveUIDocument.Document

print('LIST OF REVISIONS:')
cl = FilteredElementCollector(doc)
revs = cl.OfCategory(BuiltInCategory.OST_Revisions).WhereElementIsNotElementType()
for rev in revs:
	print('{0}\tREV#: {1}DATE: {2}TYPE:{3}DESC: {4}'.format( rev.SequenceNumber, str(rev.RevisionNumber).ljust(5), str(rev.RevisionDate).ljust(10), str(rev.NumberType.ToString()).ljust(15), rev.Description))

print('\n\nREVISED SHEETS:\n\nNAME\tNUMBER\n--------------------------------------------------------------------------')
cl_sheets = FilteredElementCollector(doc)
sheetsnotsorted = cl_sheets.OfCategory(BuiltInCategory.OST_Sheets).WhereElementIsNotElementType().ToElements()
sheets = sorted(sheetsnotsorted, key=lambda x: x.SheetNumber)

for s in sheets:
	revs = s.GetAllRevisionIds()
	if len(revs) > 0:
		print('{0}\t{1}'.format(s.LookupParameter('Sheet Number').AsString(), s.LookupParameter('Sheet Name').AsString()))
		for rev in revs:
			rev = doc.GetElement(rev)
			print('\tREV#: {0}\t\tDATE: {1}\t\tDESC:{2}'.format( rev.RevisionNumber, rev.RevisionDate, rev.Description ))
Ejemplo n.º 18
0
"""Remove all materials that their names starts with 'Render'."""

from revitutils import doc, selection
from Autodesk.Revit.DB import FilteredElementCollector, BuiltInCategory, Transaction
from Autodesk.Revit.UI import TaskDialog

with Transaction(doc, 'Remove All Materials') as t:
    t.Start()
    cl = FilteredElementCollector(doc)
    materials = cl.OfCategory(BuiltInCategory.OST_Materials
                              ).WhereElementIsNotElementType().ToElements()

    count = 0

    for m in materials:
        if m.Name.startswith('Render'):
            try:
                doc.Delete(m.Id)
                count += 1
            except Exception as e:
                logger.error('Material', m.Id, e)
                continue
    t.Commit()

    TaskDialog.Show('pyRevit', '{} materials removed.'.format(count))
Ejemplo n.º 19
0
"""Lists views that have a template assigned to them."""

from scriptutils import this_script
from revitutils import doc, uidoc
from Autodesk.Revit.DB import FilteredElementCollector, BuiltInCategory, View

cl_views = FilteredElementCollector(doc)
views = cl_views.OfCategory(
    BuiltInCategory.OST_Views).WhereElementIsNotElementType().ToElements()

for v in views:
    vtid = v.ViewTemplateId
    vt = doc.GetElement(vtid)
    if vt:
        phasep = v.LookupParameter('Phase')
        print('TYPE: {1} ID: {2} TEMPLATE: {3} PHASE:{4} {0}'.format(
            v.ViewName,
            str(v.ViewType).ljust(20), this_script.output.linkify(v.Id),
            str(v.IsTemplate).ljust(10),
            phasep.AsValueString().ljust(25) if phasep else '---'.ljust(25)))
Ejemplo n.º 20
0
    from scriptutils import logger, this_script
    from revitutils import doc, selection, uidoc

    output = this_script.output

from Autodesk.Revit.DB import FilteredElementCollector, BuiltInCategory, ElementId, Transaction

cl = FilteredElementCollector(
    doc, uidoc.ActiveView.Id).WhereElementIsNotElementType()

if __shiftclick__:
    category = BuiltInCategory.OST_SharedBasePoint
else:
    category = BuiltInCategory.OST_ProjectBasePoint

elements = cl.OfCategory(category).ToElementIds()

if len(elements) == 0:
    t = Transaction(doc, "[%s] Reveal hidden" % __title__)
    t.Start()
    try:
        uidoc.ActiveView.EnableRevealHiddenMode()
        cl = FilteredElementCollector(
            doc, uidoc.ActiveView.Id).WhereElementIsNotElementType()
        elements = cl.OfCategory(category).ToElementIds()
    except:
        elements = []

    if len(elements) == 0:
        t.RollBack()
        cl = FilteredElementCollector(doc).WhereElementIsNotElementType()
Ejemplo n.º 21
0
the Free Software Foundation.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

See this link for a copy of the GNU General Public License protecting this package.
https://github.com/eirannejad/pyRevit/blob/master/LICENSE
'''

__doc__ = 'Lists all revision clouds in this model. It also prints the sheet number for any revision cloud on sheet views.'

from Autodesk.Revit.DB import FilteredElementCollector, BuiltInCategory, ViewSheet
doc = __revit__.ActiveUIDocument.Document

cl = FilteredElementCollector(doc)
revs = cl.OfCategory(
    BuiltInCategory.OST_RevisionClouds).WhereElementIsNotElementType()

for rev in revs:
    parent = doc.GetElement(rev.OwnerViewId)
    if isinstance(parent, ViewSheet):
        print('REV#: {0}\t\tID: {3}\t\tON SHEET: {1} {2}'.format(
            doc.GetElement(rev.RevisionId).RevisionNumber, parent.SheetNumber,
            parent.Name, rev.Id))
    else:
        print('REV#: {0}\t\tID: {2}\t\tON VIEW: {1}'.format(
            doc.GetElement(rev.RevisionId).RevisionNumber, parent.ViewName,
            rev.Id))
Ejemplo n.º 22
0
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

See this link for a copy of the GNU General Public License protecting this package.
https://github.com/eirannejad/pyRevit/blob/master/LICENSE
'''

from Autodesk.Revit.DB import FilteredElementCollector, BuiltInCategory, LinkElementId, UV, XYZ, Transaction, ViewSection, View3D, ViewDrafting, ViewSheet

uidoc = __revit__.ActiveUIDocument
doc = __revit__.ActiveUIDocument.Document

cl_views = FilteredElementCollector(doc)
views = cl_views.OfCategory(
    BuiltInCategory.OST_Views).WhereElementIsNotElementType().ToElements()
cl_rooms = FilteredElementCollector(doc)
spaces = cl_rooms.OfCategory(
    BuiltInCategory.OST_MEPSpaces).WhereElementIsNotElementType().ToElements()


def GetElementCenter(el, v):
    cen = el.Location.Point
    z = (el.UpperLimit.Elevation + el.LimitOffset) / 2
    cen = cen.Add(XYZ(0, 0, z))
    return cen


t = Transaction(doc, 'Tag All Spaces in All Views')
t.Start()