Copying Views Selected in Project Browser (API)

Copying Views Selected in Project Browser (API)

Anonymous
Not applicable
1,662 Views
3 Replies
Message 1 of 4

Copying Views Selected in Project Browser (API)

Anonymous
Not applicable
import clr
import math
clr.AddReference('RevitAPI') 
clr.AddReference('RevitAPIUI') 
from Autodesk.Revit.DB import * 
 
app = __revit__.Application
doc = __revit__.ActiveUIDocument.Document
uidoc = __revit__.ActiveUIDocument

vtId = 0
collector = FilteredElementCollector(doc).OfClass(clr.GetClrType(ViewFamilyType))
collectorVP = FilteredElementCollector(doc).OfClass(clr.GetClrType(ViewPlan)).WhereElementIsNotElementType()
collectorViews = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Views)
 
#template name
templateName = 'DEMO PLAN'
myTemplate = 0
for view in collectorViews:
	if view.IsTemplate and view.Name == templateName:
		myTemplate = view
		break

#by how much you want to expand the crop around the room
expandVal = 1

#selected room elements
selEls = uidoc.Selection.Elements


#get elementId of FloorPlan viewFamilyType
for el in collector:
	if el.ViewFamily == ViewFamily.FloorPlan:
		vtId = el.Id
		break
		
		
t = Transaction(doc, 'Create Room Plan View(s)')
t.Start()
for rm in selEls:
	
	if int(BuiltInCategory.OST_Rooms) == rm.Category.Id.IntegerValue:		
		rmbox = rm.get_BoundingBox(None)
		print rmbox
		minPt = XYZ(rmbox.Min.X-expandVal, rmbox.Min.Y-expandVal, 0)
		maxPt = XYZ(rmbox.Max.X+expandVal, rmbox.Max.Y+expandVal, 0)
		rmbox.Min = minPt
		rmbox.Max = maxPt
		lev = rm.Level
		
		#create a Plan View for the room
		vp = ViewPlan.Create(doc, vtId, lev.Id)
		print vp.Name		
		
		#assign template to the view
		if myTemplate != 0:
			vp.ViewTemplateId =myTemplate.Id
			
		testName = rm.get_Parameter('Name').AsString() + ' ' + str(rm.get_Parameter('Number').AsString())
		
		for el in collectorVP:
			if el.Name == testName:
				testName = testName + ' (1)'
				break
				
		vp.Name = testName
		
		#assign room's BoundingBox to view CropBox
		vp.CropBox = rmbox
		vp.CropBoxActive = True
		#you can fancy this up by assigning a particular view template etc		
t.Commit()

 

I’ve been programming & teaching myself the Revit 2014 API with the Python Shell. Using Dima Chiriacov’s tutorial regarding creating room plan views based on user selection, I have been trying to tweak it to accomplish a similar task.

 

Rather than having the user select the room in a project view before applying the script to create new room views, I want the user to select Floor Plan views in the Project Browser.

 

Some areas in the code I’ve tested to accomplish this includes much of the For Loop after the transaction starts.

Would anyone be able to point me in the correct direction to have selected views in the project browser create views rather than room selections?

 

Thanks,

 

S.W.

 

Tutorial Script: http://dp-stuff.org/downloads/dpstuff/free/revitpython/createRoomPlanViews.txt

0 Likes
1,663 Views
3 Replies
Replies (3)
Message 2 of 4

Anonymous
Not applicable
Hmm, I don't think the project browser has the option to ask for it's selected views (can anyone confirm this). I would suggest creating your own dialog with a collection of views and let the user select the desired views.
0 Likes
Message 3 of 4

Anonymous
Not applicable

Hello Remy,

 

I am very interested in your comment, because right now I am working on a Macro to prompt the user to select from project browser the desired views that he would like to have in a new sheet. Plus this function aligns them to an exact positino and duplicates with detailing the views. 

 

However, I am not allowed to select the views by myself, I can filter them, but I can not make this part of the function generic enough.

 

I would like to know how would you suggest me to create the dialog box in which to show the collection of views and from which to collect and make the desired transactions.

 

I am new to Revit API and I am working with macro manager not external commands.

 

Thank you very much.

0 Likes
Message 4 of 4

Anonymous
Not applicable

 

Let's say you make a Listview called theViewListview

 

var coll = new FilteredElementCollector(doc);
var filter = new ElementClassFilter(typeof (View));
coll.WherePasses(filter);
foreach (Element el in coll)
{
if (el is View)
{
theViewListview.Add(el as View);
}

// and to add sheets
if (el is ViewSheet)
{
theViewListview.Add(el as ViewSheet);
}
}

 

and there you have a listview filled with views.

0 Likes