Menu Home

Quasar Package Guide: PART – C

Parent Topic : Quasar Package Guide

Quasar Package Guide – PART – C

ElementActiveViewByCategory

collect all elements from an active view of a given category.

ElementActiveView
ElementActiveViewByCategory
# dynamo version - 1.3.4

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 the location of the room.

RoomTag
RoomTagToRoom
# dynamo version - 1.3.4

import clr
#clr.AddReference('RevitAPI')
clr.AddReference('RevitServices')

#from Autodesk.Revit.DB import *
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

doc = DocumentManager.Instance.CurrentDBDocument

elems = IN[0];

if not isinstance(elems,list):
	elems = UnwrapElement([elem])
else:
	elems = UnwrapElement(elems)

#room_tags = FilteredElementCollector(doc).OfClass(SpatialElementTag).ToElements()

TransactionManager.Instance.EnsureInTransaction(doc)

for i in elems:
	room_loc = i.Room.Location.Point
	new_loc = room_loc - i.Location.Point
	i.Location.Move(new_loc)

TransactionManager.Instance.TransactionTaskDone()

OUT = elems

RoomCollector

Check/Collect the room by its status; Place , Unplaced, NotEnclosed & Redundant.

rooms
# dynamo version - 1.3.4

import clr
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

DuplicateSheetWithViews

Duplicate the given sheet(s) and its associate views by sheet name(s), sheet number(s) & a titleblock.

import clr

clr.AddReference('RevitAPI')
clr.AddReference("RevitServices")
clr.AddReference("RevitNodes")

from Autodesk.Revit.DB import *
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

# document 
doc = DocumentManager.Instance.CurrentDBDocument

# unwrap function
def lst(l):
	if isinstance(l, list):
		return l
	else:
		return [l]

# sheets
sheets = UnwrapElement(lst(IN[0]))
# new sheet names
names = lst(IN[1])
# new sheet numbers
numbers = lst(IN[2])
# titleblocks
titleblock = UnwrapElement(IN[3])
# new sheets list
new_sheets = []
# output list
out = []

# transaction start
TransactionManager.Instance.EnsureInTransaction(doc)
# name, number iteration
for (name, number) in zip(names,numbers):
	# create new sheet
	newSheet = ViewSheet.Create(doc, titleblock.Id)	
	# set sheet number
	newSheet.SheetNumber = number
	# set sheet name
	newSheet.Name = name
	# append to new sheets list
	new_sheets.append(newSheet)

# sheet , new sheet iteration
for sheet,nSheet in zip(sheets,new_sheets):
	# view list
	views = []
	# get view ports
	vPorts = sheet.GetAllViewports()
	# iterate view ports
	for ele in vPorts:
		# get view port
		ele = doc.GetElement(ele)				
		# duplicate option
		vOpt = ViewDuplicateOption.WithDetailing
		# get viewport location		
		viewLoc = ele.GetBoxCenter()
		# get type Id
		vptype = ele.GetTypeId()
		# get view 
		view = doc.GetElement(ele.ViewId)
		# check view type
		if not view.ViewType == ViewType.Legend or view.ViewType==ViewType.Schedule:
			# view duplicate
			v = view.Duplicate(vOpt)
			# get view
			dup_view = doc.GetElement(v)
			try:
				# set view name
				dup_view.Name = ele.LookupParameter("View Name").AsString().ToString()
			except:
				pass
		else:
			# get view id
			v = view.Id
		# create new view port 
		newPort = Viewport.Create(doc,nSheet.Id, v, viewLoc)
		# append to views list
		views.append(newPort)
		# change viewport type
		newPort.ChangeTypeId(vptype)
	# append to output				
	out.append(views)
# transaction end	
TransactionManager.Instance.TransactionTaskDone()	
# output result
OUT = out

ViewPortAlignment

Views arrange and align on sheets based on the given template sheet view ports position and location.

# dynamo version - 1.3.0

import clr
clr.AddReference("RevitAPI")
clr.AddReference("RevitNodes")
clr.AddReference("RevitServices")
from Autodesk.Revit.DB import *
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

doc = DocumentManager.Instance.CurrentDBDocument

template = UnwrapElement(IN[0]);
sheets = IN[1];
result = [];
if not isinstance(sheets,list):
	sheets = UnwrapElement([sheets]);
else:
	sheets = UnwrapElement(sheets);

TransactionManager.Instance.EnsureInTransaction(doc);
sub =[]

for s in sheets:
		
	#collect all viewports from template sheet
	temp_ports = FilteredElementCollector(doc).OwnedByView(template.Id);
	#collect all viewports from current sheet
	view_ports = FilteredElementCollector(doc).OwnedByView(s.Id);
	
	#template sheet schedule views
	temp_schedules = [i for i in temp_ports if  i.Category != None and i.Category.Name == "Schedule Graphics" and i.IsTitleblockRevisionSchedule == False];
	#template sheet viewports
	temp_views = [i for i in temp_ports if i.Category != None and i.Category.Name == "Viewports"];
	
	#sheet schedule views
	s_schedules = [i for i in view_ports if  i.Category != None and i.Category.Name == "Schedule Graphics" and i.IsTitleblockRevisionSchedule == False];
	#sheet viewports
	s_views = [i for i in view_ports if i.Category != None and i.Category.Name == "Viewports"];
	
	#get/set location
	for ts,ss in zip(temp_schedules,s_schedules):
		ss.Point = ts.Point;
	
	for tv,vv in zip(temp_views,s_views):
		temploc = tv.GetBoxCenter();	
		vv.SetBoxCenter(temploc);
		
	sub.append([s_schedules,s_views]);

TransactionManager.Instance.TransactionTaskDone();

OUT = sub;

To Be Continued

Categories: quasar Revit Revit-Dynamo

Tagged as:

min.naung

Site Founder and Developer.

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.

%d bloggers like this: