Quasar Package Guide: PART – C

Quasar Package Guide: PART – C

ElementActiveViewByCategory – collect all elements of a category from an active view.

ElementActiveView
ElementActiveViewByCategory
# dynamo version - 1.3.3
import clr,System
clr.AddReference("RevitAPI")
clr.AddReference("RevitServices")
from Autodesk.Revit.DB import *
from RevitServices.Persistence import DocumentManager
# document
doc = DocumentManager.Instance.CurrentDBDocument
# category input
category = UnwrapElement(IN[0])
# all BuiltInCategory object
builtInCategories = System.Enum.GetValues(BuiltInCategory)

# check matching id to collect BIC object
for bic in builtInCategories:
    # if match
    if ElementId(bic) == category.Id:
        catObj = bic
        break

# collect elements
elements = FilteredElementCollector(doc, doc.ActiveView.Id).OfCategory(catObj).ToElements()

# output
OUT = elements

RoomTagToRoom – relocate room’s tag to its room location.

RoomTag
RoomTagToRoom
# dynamo version - 1.3.2
import clr
clr.AddReference('RevitServices')
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
# current document
doc = DocumentManager.Instance.CurrentDBDocument
# input
elems = IN[0];
# unwrapping
if not isinstance(elems,list):
    elems = UnwrapElement([elem])
else:
    elems = UnwrapElement(elems)

# transaction
TransactionManager.Instance.EnsureInTransaction(doc)
# each tag
for i in elems:
    # room location point
    room_loc = i.Room.Location.Point
    # calculate distance
    new_loc = room_loc - i.Location.Point
    # move to new/room loaction
    i.Location.Move(new_loc)
# transaction close
TransactionManager.Instance.TransactionTaskDone()
# output elements
OUT = elems

RoomCollector – Collect rooms by their status.

rooms

# dynamo version - 1.3.2
# import common language runtime
import clr

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

# 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

# if provided input[0]
if IN[0]:
	rooms = UnwrapElement(IN[0])

# if no input, collect all rooms
else:
	# collect all rooms
	rooms = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Rooms).ToElements()

# room status list for output
placed,notplaced,notenclosed,redundant = [],[],[],[]

# loop rooms
for r in rooms:
	# get room boundary need one argument(opts)
	s = r.GetBoundarySegments(SpatialElementBoundaryOptions())
	# get location of room
	l = r.Location
	# if location is none
	if l == None:
		# append to not placed
		notplaced.append(r)
	# elif no boundary segments
	elif len(s)<1:
		# append to not enclosed
		notenclosed.append(r)
	# elif area zero
	elif r.Area == 0:
		# append to redundant
		redundant.append(r)
	# passed all conditions
	else:
		# append to placed
		placed.append(r)

OUT = placed,notplaced,notenclosed,redundant

Become a Patron!

Work In Progress …

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.