Quasar Package Guide: PART – B

Quasar Package Guide: Part – B

Become a Patron!

GridNamingGenerator – Rename horizontal(X) or vertical(Y) grid with startfrom (increment start from) value and reverse options.

GridRenaming
GridNamingGenerator
# dynamo version - 1.3.2
import clr,math
clr.AddReference('ProtoGeometry')
clr.AddReference("RevitAPI")
clr.AddReference("RevitServices")

clr.AddReference("RevitNodes")

import Revit
clr.ImportExtensions(Revit.Elements)
clr.ImportExtensions(Revit.GeometryConversion)
from Autodesk.DesignScript.Geometry import *
from Autodesk.Revit.DB import FilteredElementCollector, Grid
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

# current document
doc = DocumentManager.Instance.CurrentDBDocument
# collect grids
grids = FilteredElementCollector(doc).OfClass(Grid).ToElements()

direction = IN[0]
startfrom = IN[1]
# default value = False
reverse = IN[2] if IN[2] else False

tosort = []

# each grid
for grid in grids:
    # get curve
    line = grid.ToDSType(False).Curve
    # absolute value of x point
    if direction == 'X' and math.fabs(line.Direction.X) > 50:
        tosort.append((grid, line.StartPoint.Y))
    # absolute value of y point
    if direction == 'Y' and math.fabs(line.Direction.Y) > 50:
        tosort.append((grid, line.StartPoint.X))

# sort list by point value
res = sorted(tosort, key = lambda x: x[1])

# naming
pre_naming = startfrom
naming = startfrom

# sorted grid elements
sorted_grids = [i[0] for i in res]

# if reverse = True
if reverse:
    sorted_grids.reverse()

# grid naming is number such as 1, 2 ...
def grid_num(n):
    n = int(n)
    for grid in sorted_grids:
        try:
            grid.Name = str(n)
        except:
            grid.Name = str(n) + "'"
        n += 1

# grid naming is alphabet such as A, B ...
def grid_str(n):
    n = ord(n)
    for grid in sorted_grids:
        try:
            grid.Name = chr(n)
        except:
            grid.Name = chr(n) + "'"
        n += 1

# transaction
TransactionManager.Instance.EnsureInTransaction(doc)

# if naming is number
if startfrom.isdigit():
    grid_num(pre_naming)
    grid_num(naming)
# if alphabet
else:
    grid_str(pre_naming)
    grid_str(naming)

# transaction done
TransactionManager.Instance.TransactionTaskDone()

# output grid elements
OUT = sorted_grids

TransferLegend – select and transfer legend views from a linked document to the current document.

TransferLegend
TransferLegend


CustomDropDown – This node creates a dropdown user interface by the input values.

CustomDropDown
Quasar Package – CustomDropDown

HideUnhideElement – hide or unhide elements in given views.

hide_elem_inviews
HideUnhideElementsInViews
# dynamo version - 1.3.0

import clr, System
clr.AddReference("RevitAPI")
clr.AddReference("RevitServices")

from System.Collections.Generic import List
from Autodesk.Revit.DB import *
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

# current doc
doc = DocumentManager.Instance.CurrentDBDocument;

def lst_unwrap(elems):
    if not isinstance(elems,list):
        elems = UnwrapElement([elems]);
    else:
        elems = UnwrapElement(elems);
    return elems

# make unwrap list
lstElemToHide = lst_unwrap(IN[0]);
# make unwrap list
lstView = lst_unwrap(IN[1]);
# true, false / hide, unhide
toggle = IN[2];
# element's id list
lst = [i.Id for i in lstElemToHide];
# make dotNet List
lstElemId = List[ElementId](lst); 

# transaction
TransactionManager.Instance.EnsureInTransaction(doc);

# hide elements in each view
for v in lstView:
    if toggle:
        v.HideElements(lstElemId);
    else:
        v.UnhideElements(lstElemId);

# transaction done
TransactionManager.Instance.TransactionTaskDone();

OUT = "DONE!"

LinkLevelGrid – hide / unhide grids and levels from link documents.

GIF_LinkLevelGrid
Quasar Package – LinkLevelGrid

# dynamo version - 1.3.2
# author - min.naung

import clr
clr.AddReference("RevitAPI")
clr.AddReference("RevitServices")
import System

from System.Collections.Generic import List
from Autodesk.Revit.DB import *
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

# document manager
doc = DocumentManager.Instance.CurrentDBDocument
# start transaction
TransactionManager.Instance.EnsureInTransaction(doc);

# active view
active_view = doc.ActiveView
# filter name "can name anything"
ifilter = "LinkLevelGrid_QuasarPackage"
found = False

# input[0] boolean
hide = False if IN[0] else True

# collect all filter elements
allFilters = FilteredElementCollector(doc).OfClass(FilterElement).ToElements()

# get filters from current view
viewFilters = active_view.GetFilters();
# collect filters' names
viewFiltersName = [doc.GetElement(i).Name.ToString() for i in viewFilters]

# loop each filter
for fter in allFilters:
# filter already have in doc but not in current view
if ifilter == fter.Name.ToString() and ifilter not in viewFiltersName:
# add filter

active_view.AddFilter(fter.Id)
# set filter visibility
active_view.SetFilterVisibility(fter.Id, hide);
found = True
# filter already have in doc and current view
if ifilter == fter.Name.ToString() and ifilter in viewFiltersName:
# set filter visibility
active_view.SetFilterVisibility(fter.Id, hide);
found = True

# if filter not found in doc
if not found:
# all grids in doc
grids = FilteredElementCollector(doc).OfClass(Grid).ToElements()
# all levels in doc
levels = FilteredElementCollector(doc).OfClass(Level).ToElements()
# collect category id from grid and level
CateIds = List[ElementId]([grids[0].Category.Id,levels[0].Category.Id])

# type ids from grids
gridTypeIds = set([i.GetTypeId() for i in grids])
# type ids from levels
levelTypeIds = set([i.GetTypeId() for i in levels])

# get grid type element
type_elems = [doc.GetElement(i) for i in gridTypeIds]
# get level type element
type_elems.extend([doc.GetElement(l) for l in levelTypeIds])

# loop type elements
for elem in type_elems:
# if "_quasar" not include in type name
if not "_quasar" in elem.LookupParameter("Type Name").AsString():
# add "_quasar" in type name
elem.Name = elem.LookupParameter("Type Name").AsString() + "_quasar";
# get type names
type_names = [i.LookupParameter("Type Name").AsString() for i in type_elems]
# type name parameter id
paramId = type_elems[0].LookupParameter("Type Name").Id
# create a "not ends with" filter rule
notendswith = ParameterFilterRuleFactory.CreateNotEndsWithRule(paramId,"_quasar",False)
# create parameter filter element
paramFilterElem = ParameterFilterElement.Create(doc, ifilter,CateIds,[notendswith])
# set filter overrides (same with add filter to current)
active_view.SetFilterOverrides(paramFilterElem.Id, OverrideGraphicSettings())
# set filter visibility
active_view.SetFilterVisibility(paramFilterElem.Id, hide)

# transaction done
TransactionManager.Instance.TransactionTaskDone()

# output
OUT = "DONE!"


ElementSelector – select elements by category and parameter value.

elementselector
QuasarPackage – ElementSelector

Jump to Part – A or Part – C

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.