Create room using pick point

Create room using pick point

adcdao
Advocate Advocate
1,578 Views
4 Replies
Message 1 of 5

Create room using pick point

adcdao
Advocate
Advocate

Hi everybody,

 

I found some information about creating rooms but not exactly what I want. I want to be able to pick a point and create a room exactly as the Room command work and get information about the new room created (ID or UniqueID). Is it possible to do that?

 

Thank you very much,

André

0 Likes
Accepted solutions (1)
1,579 Views
4 Replies
Replies (4)
Message 2 of 5

smarente1
Enthusiast
Enthusiast
Accepted solution

Use this method:

 

https://www.revitapidocs.com/2017/28262c8c-d18a-338c-eb17-f406438949d8.htm 

 

Example:

 

from Autodesk.Revit.DB import UV
from rpw import revit, db

doc = revit.doc
uidoc = revit.uidoc
#Pick Room Point
point = uidoc.Selection.PickPoint()
#Active View
active = doc.ActiveView
#Active View Level
level_name = active.LookupParameter("Associated Level").AsString()
collect_levels = db.Collector(of_class = "Level")
active_level = [level for level in collect_levels if level.Name == level_name][0]

with db.Transaction(doc=doc, name="Create Room"):
    #Create Room
    new_room = doc.Create.NewRoom(active_level, UV(point.X,point.Y))
    #New Rooms Id
    new_room_Id = new_room.Id

 

Message 3 of 5

adcdao
Advocate
Advocate

Thank you I will try that,

 

Is it possible to highlight the room boundary when moving cursor?

 

Thanks,

André

0 Likes
Message 4 of 5

smarente1
Enthusiast
Enthusiast

It doesnt look like the PickPoint Method has a snap type option to highlight the boundary segments.   

 

https://www.revitapidocs.com/2015/af8ad302-7196-8e2f-f1eb-e5929cda30d9.htm 

 

 

0 Likes
Message 5 of 5

adcdao
Advocate
Advocate

Thank you very much for your  help. Based on your code here's a simplified and more complete version:

 

//Pick point
Autodesk.Revit.DB.XYZ pickPoint;
ObjectSnapTypes snapTypes = ObjectSnapTypes.None;
pickPoint = uidoc.Selection.PickPoint(snapTypes, "Select a point inside the room to create");
UV roomLocation = new UV(pickPoint.X, pickPoint.Y);

//Level
Autodesk.Revit.DB.View activeView;
activeView = doc.ActiveView;
Level activeLevel = activeView.GenLevel;

//Create the room

ElementId roomID=null;

using (Transaction t = new Transaction(doc, "Create Room"))
{
try
{
t.Start();

Room newRoom;
newRoom = doc.Create.NewRoom(activeLevel, roomLocation);
roomID = newRoom.Id;
t.Commit();

}

catch ( Exception ex)
{
MessageBox.Show(ex.Message);
}
}

 

I also have a more complete version with failure options with the help of 2 posts by Jeremy Tammik:

https://thebuildingcoder.typepad.com/blog/2010/04/failure-api.html

https://thebuildingcoder.typepad.com/blog/2012/04/failure-rollback.html

 

Thank you again for your help.

0 Likes