Quasar Package Guide: PART – B

Parent Topic : Quasar Package Guide

Quasar Package Guide : PART – B

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

GridRenaming
GridNamingGenerator

GridNamingGenerator – IronPython

#dynamo version - 1.3.4
import clr,math

clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *


clr.AddReference("RevitAPI")
clr.AddReference("RevitServices")
from Autodesk.Revit.DB import FilteredElementCollector, Grid
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)
clr.ImportExtensions(Revit.GeometryConversion)

doc = DocumentManager.Instance.CurrentDBDocument
grids = FilteredElementCollector(doc).OfClass(Grid).ToElements()


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

tosort = []

for grid in grids:
	line = grid.ToDSType(False).Curve
	if direction == 'X' and math.fabs(line.Direction.X) > 50:
		tosort.append((grid, line.StartPoint.Y))
	
	if direction == 'Y' and math.fabs(line.Direction.Y) > 50:
		tosort.append((grid, line.StartPoint.X))
		
res = sorted(tosort, key = lambda x: x[1])


pre_naming = startfrom
naming = startfrom

sorted_grids = [i[0] for i in res]

if reverse:
	sorted_grids.reverse()

def grid_num(n):
	n = int(n)
	for grid in sorted_grids:
		try:
			grid.Name = str(n)
		except:
			grid.Name = str(n) + "'"
		n += 1
		
		
def grid_str(n):
	n = ord(n)
	for grid in sorted_grids:
		try:
			grid.Name = chr(n)
		except:
			grid.Name = chr(n) + "'"
		n += 1
		

TransactionManager.Instance.EnsureInTransaction(doc)

if startfrom.isdigit():
	grid_num(pre_naming)
	grid_num(naming)
else:
	grid_str(pre_naming)
	grid_str(naming)

TransactionManager.Instance.TransactionTaskDone()


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

HideUnhideElementInViews – IronPython

# dynamo version - 1.3.4

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

import Autodesk, Revit, RevitServices

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

doc = DocumentManager.Instance.CurrentDBDocument;
message = ''; melem = ''; mview = '';
def lst_unwrap(elems):
	if not isinstance(elems,list):
		elems = UnwrapElement([elems]);
	else:
		elems = UnwrapElement(elems);
	return elems

lstElemToHide = lst_unwrap(IN[0]);
lstView = lst_unwrap(IN[1]);
toggle = IN[2];
lst = [i.Id for i in lstElemToHide];
lstElemId = List[ElementId](lst); 

TransactionManager.Instance.EnsureInTransaction(doc);

for v in lstView:
	if toggle:
		h = "hide"
		v.HideElements(lstElemId);
	else:
		h = "unhide";
		v.UnhideElements(lstElemId);
	
	if (len(lstElemToHide)>1): melem = "elements"
	else: melem = "element"
	
	if (len(lstView)>1): mview = "views"
	else: mview = "view"
	
TransactionManager.Instance.TransactionTaskDone();
message = "%s %s %s in %s %s." %(len(lstElemToHide),melem,h,len(lstView),mview);
OUT = message;

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

GIF_LinkLevelGrid
Quasar Package – LinkLevelGrid

LinkLevelGrid – IronPython

# dynamo version - 1.3.4

# import common language runtime 
import clr

# clr.AddReference loads and imports .net assembly(dll) as module
# load RevitAPI.dll and RevitServices.dll
clr.AddReference("RevitAPI")
clr.AddReference("RevitServices")

# import system for dotnet List
import System
from System.Collections.Generic import List

# import all classes from Revit DB
from Autodesk.Revit.DB import *
# import document manager
from RevitServices.Persistence import DocumentManager
# import transaction manager
from RevitServices.Transactions import TransactionManager
# instantiate current document
doc = DocumentManager.Instance.CurrentDBDocument

# start transaction
TransactionManager.Instance.EnsureInTransaction(doc)

# active view
active_view = doc.ActiveView

# filter name "can name anything"
ifilter = "GiveFilterAName"

endWiths = "Anything"

# filter check
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 endwiths not include in type name
		if not endWiths in elem.LookupParameter("Type Name").AsString():
			# add endwiths in type name
			elem.Name = elem.LookupParameter("Type Name").AsString() + endWiths
	# 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,endWiths,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

GetRoomSideSurfaces – Collect revit room sides as dynamo surfaces.

# dynamo version - 1.3.4

import clr
clr.AddReference("RevitAPI");
clr.AddReference("RevitNodes")

import Autodesk, Revit;
clr.ImportExtensions(Revit.Elements);
clr.ImportExtensions(Revit.GeometryConversion);
from Autodesk.Revit.DB import *

rooms = UnwrapElement(IN[0]);
result =[];


for room in rooms:
	# geo of room
	geo = room.get_Geometry(Options())
	# get enum
	enum = geo.GetEnumerator()
	# skip one
	next = enum.MoveNext()
	# current geo
	solid = enum.Current
	# get faces
	faces = solid.Faces
	count = 0;
	sub = []
	# each face
	for face in faces:
		count +=1;
		# omit first two (top,btn)
		if count>2:
			# face to dyn obj
			sub.append(face.ToProtoType()[0])
			# curves
			#sub.append(face.GetEdgesAsCurveLoops()[0])
	result.append(sub)
OUT = result

Quasar Package – GetRoomSideSurface

AllElementOfWorkset – Collect all the elements belong to input workset.

# dynamo version - 1.3.4

import clr
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
import Autodesk

clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

doc = DocumentManager.Instance.CurrentDBDocument

workset = IN[0]
filter = ElementWorksetFilter(workset.Id,False)
# collect user created worksets
elements = FilteredElementCollector(doc).WherePasses(filter).ToElements()
# elements output
OUT = elements
Quasar Package – AllElementsOfWorkset

Jump to Part – A or Part – C

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.