From 748bd15683ab522479b7dbb5d172ea6129b2f850 Mon Sep 17 00:00:00 2001 From: mgjean Date: Sat, 20 Oct 2018 13:13:20 +0800 Subject: [PATCH 01/15] reload-all-links , hide-unhide-links-levels-grids --- .../HowTo_HideUnhideLinksLevelsGrids.py | 96 +++++++++++++++++++ 0-python-code/HowTo_ReloadAllLinkDocuments.py | 31 ++++++ 2 files changed, 127 insertions(+) create mode 100644 0-python-code/HowTo_HideUnhideLinksLevelsGrids.py create mode 100644 0-python-code/HowTo_ReloadAllLinkDocuments.py diff --git a/0-python-code/HowTo_HideUnhideLinksLevelsGrids.py b/0-python-code/HowTo_HideUnhideLinksLevelsGrids.py new file mode 100644 index 0000000..ef20aa7 --- /dev/null +++ b/0-python-code/HowTo_HideUnhideLinksLevelsGrids.py @@ -0,0 +1,96 @@ +""" +HIDE / UNHIDE - LEVELS AND GRIDS FROM LINKS DOCUMENTS + +TESTED REVIT API: 2017, 2018 + +Author: min.naung@https://twentytwo.space/contact | https://github.com/mgjean + +This file is shared on www.revitapidocs.com +For more information visit http://github.com/gtalarico/revitapidocs +License: http://github.com/gtalarico/revitapidocs/blob/master/LICENSE.md +""" + +import System +from System.Collections.Generic import List +from Autodesk.Revit.DB import Transaction +from Autodesk.Revit.DB import * + +doc = __revit__.ActiveUIDocument.Document +active_view = doc.ActiveView + +# filter name "can name anything" +ifilter = "GiveFilterAName" + +endWiths = "Anything" + +# filter check +found = False + +unhide = False # Edit here to hide/unhide +msg = "Unhide" if unhide else "Hide" +trans = Transaction(doc,"%s links levels grids" %(msg)) +trans.Start() + +# 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, unhide) + 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, unhide) + 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, unhide) + +print "DONE!" +trans.Commit() \ No newline at end of file diff --git a/0-python-code/HowTo_ReloadAllLinkDocuments.py b/0-python-code/HowTo_ReloadAllLinkDocuments.py new file mode 100644 index 0000000..79c9867 --- /dev/null +++ b/0-python-code/HowTo_ReloadAllLinkDocuments.py @@ -0,0 +1,31 @@ +""" +Reload All Link Documents + +TESTED REVIT API: 2017 + +Author: min.naung@https://twentytwo.space/contact | https://github.com/mgjean + +This file is shared on www.revitapidocs.com +For more information visit http://github.com/gtalarico/revitapidocs +License: http://github.com/gtalarico/revitapidocs/blob/master/LICENSE.md +""" + +from Autodesk.Revit.DB import FilteredElementCollector,RevitLinkInstance + +uidoc = __revit__.ActiveUIDocument + +linkInstances = FilteredElementCollector(doc).OfClass(RevitLinkInstance).ToElements() + +load = [] + +for link in linkInstances: + linkType = doc.GetElement(link.GetTypeId()); + filepath = linkType.GetExternalFileReference().GetAbsolutePath(); + try: + linkType.LoadFrom(filepath,None); + load.append(link.Name.split(" : ")[0]+" "); + except: + load.append(link.Name.split(" : ")[0]+" ") + pass +for i in load: + print i From cf730bc001a5e89aa5331a6eb45c755c052dab3c Mon Sep 17 00:00:00 2001 From: Deyan Nenov Date: Wed, 24 Oct 2018 12:01:27 +0100 Subject: [PATCH 02/15] Create Snippets_ToggleLevelBubbleVisibility --- .../Snippets_ToggleLevelBubbleVisibility | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 1-csharp-code/Snippets_ToggleLevelBubbleVisibility diff --git a/1-csharp-code/Snippets_ToggleLevelBubbleVisibility b/1-csharp-code/Snippets_ToggleLevelBubbleVisibility new file mode 100644 index 0000000..df5c2ce --- /dev/null +++ b/1-csharp-code/Snippets_ToggleLevelBubbleVisibility @@ -0,0 +1,30 @@ +/* +Toggle the visibility of the Level Bubble in Section/Elevation +The snippet can be reused for Grids +TESTED REVIT API: 2018 +The snippet can be used as is in a Revit Application Macro for test purposes +Author: Deyan Nenov | github.com/ArchilizerLtd +This file is shared on www.revitapidocs.com +For more information visit http://github.com/gtalarico/revitapidocs +License: http://github.com/gtalarico/revitapidocs/blob/master/LICENSE.md +*/ + +public void PassCategoryAndClassAsVariables() +{ + Document doc = this.ActiveUIDocument.Document; + Selection sel = this.ActiveUIDocument.Selection; + + do + { + //Pick the Level you want to toggle in Elevation/Section + Level lvl = doc.GetElement(sel.PickObject(ObjectType.Element, "Pick View to Align To")) as Level; + + using(Transaction t = new Transaction(doc, "toggle")) + { + t.Start(); + lvl.HideBubbleInView(DatumEnds.End0,doc.ActiveView); //DatumEnds.End1 to toggle the other End + t.Commit(); + } + } + while(true); +} From 8acbc175257c3556e9c04d0d81abc6f543cfa21a Mon Sep 17 00:00:00 2001 From: Deyan Nenov Date: Sat, 27 Oct 2018 11:56:14 +0100 Subject: [PATCH 03/15] Snippet_FilterSelect This works just as Filter Selection but in Reverse. It allows you to first select the Category of the Selection by picking up an Object of that Category and follow up with a standard rectangular selection. After finishing the selection, only objects from that Category will be selected. --- 1-csharp-code/Snippets_FilterSelect | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 1-csharp-code/Snippets_FilterSelect diff --git a/1-csharp-code/Snippets_FilterSelect b/1-csharp-code/Snippets_FilterSelect new file mode 100644 index 0000000..a0d2375 --- /dev/null +++ b/1-csharp-code/Snippets_FilterSelect @@ -0,0 +1,27 @@ +/* +Make a selection of objects in view filtering by category +This works just as Filter Selection but in Reverse. It allows you to first select the Category of the Selection by +picking up an Object of that Category and follow up with a standard rectangular selection. After finishing the selection, only +objects from that Category will be selected. +TESTED REVIT API: 2018 +The snippet can be used as is in a Revit Application Macro for test purposes +Author: Deyan Nenov | github.com/ArchilizerLtd +This file is shared on www.revitapidocs.com +For more information visit http://github.com/gtalarico/revitapidocs +License: http://github.com/gtalarico/revitapidocs/blob/master/LICENSE.md +*/ + +public void FilterSelect() +{ + UIDocument uidoc = ActiveUIDocument; + Document doc = uidoc.Document; + + Reference refer = uidoc.Selection.PickObject(ObjectType.Element, "Set the filter"); //Pick an object by which Category you will filter + + IList elements = uidoc.Selection.PickElementsByRectangle(); + + uidoc.Selection.SetElementIds(elements + .Where(x => x.Category.Id.IntegerValue.Equals(doc.GetElement(refer).Category.Id.IntegerValue)) + .Select(x => x.Id) + .ToList()); +} From f91ffea6c7d4a480379bc840fef06d5ffe93fa8d Mon Sep 17 00:00:00 2001 From: Deyan Nenov Date: Sat, 27 Oct 2018 12:02:10 +0100 Subject: [PATCH 04/15] Update Snippet_ToggleLevelBubbles Renamed Method --- 1-csharp-code/Snippets_ToggleLevelBubbleVisibility | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/1-csharp-code/Snippets_ToggleLevelBubbleVisibility b/1-csharp-code/Snippets_ToggleLevelBubbleVisibility index df5c2ce..f3c4466 100644 --- a/1-csharp-code/Snippets_ToggleLevelBubbleVisibility +++ b/1-csharp-code/Snippets_ToggleLevelBubbleVisibility @@ -9,7 +9,7 @@ For more information visit http://github.com/gtalarico/revitapidocs License: http://github.com/gtalarico/revitapidocs/blob/master/LICENSE.md */ -public void PassCategoryAndClassAsVariables() +public void ToggleLevelBubbles() { Document doc = this.ActiveUIDocument.Document; Selection sel = this.ActiveUIDocument.Selection; From a15de7b7039816a13148f3812f60060e780098a8 Mon Sep 17 00:00:00 2001 From: mgjean Date: Fri, 9 Nov 2018 22:41:45 +0800 Subject: [PATCH 05/15] worksets, roomtag --- 0-python-code/HowTo_GetAllWorksets.py | 23 +++++++++++++ .../Tools_RoomTagMoveToRoomLocation.py | 33 +++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 0-python-code/HowTo_GetAllWorksets.py create mode 100644 0-python-code/Tools_RoomTagMoveToRoomLocation.py diff --git a/0-python-code/HowTo_GetAllWorksets.py b/0-python-code/HowTo_GetAllWorksets.py new file mode 100644 index 0000000..9fc9792 --- /dev/null +++ b/0-python-code/HowTo_GetAllWorksets.py @@ -0,0 +1,23 @@ +""" +GET ALL WORKSETS FROM THE CURRENT DOCUMENT + +TESTED REVIT API: 2016,2017,2018 + +Author: min.naung@https://twentytwo.space/contact | https://github.com/mgjean + +This file is shared on www.revitapidocs.com +For more information visit http://github.com/gtalarico/revitapidocs +License: http://github.com/gtalarico/revitapidocs/blob/master/LICENSE.md +""" +from Autodesk.Revit.DB import FilteredWorksetCollector, WorksetKind + +# document instance +doc = __revit__.ActiveUIDocument.Document + +# collect user created worksets +worksets = FilteredWorksetCollector(doc).OfKind(WorksetKind.UserWorkset).ToWorksets() + +# loop worksets +for workset in worksets: + # print name, workset + print workset.Name,workset diff --git a/0-python-code/Tools_RoomTagMoveToRoomLocation.py b/0-python-code/Tools_RoomTagMoveToRoomLocation.py new file mode 100644 index 0000000..4c2cce5 --- /dev/null +++ b/0-python-code/Tools_RoomTagMoveToRoomLocation.py @@ -0,0 +1,33 @@ +""" +ROOM TAGS MOVE TO ROOM LOCATION + +TESTED REVIT API: 2016,2017,2018 + +Author: min.naung@https://twentytwo.space/contact | https://github.com/mgjean + +This file is shared on www.revitapidocs.com +For more information visit http://github.com/gtalarico/revitapidocs +License: http://github.com/gtalarico/revitapidocs/blob/master/LICENSE.md +""" +from Autodesk.Revit.DB import FilteredWorksetCollector, WorksetKind +from Autodesk.Revit.DB import Transaction + +# document instance +doc = __revit__.ActiveUIDocument.Document + +# collect room tags from active view +tags = FilteredElementCollector(doc, doc.ActiveView.Id).OfClass(SpatialElementTag).ToElements() + +trans = Transaction(doc, "Room Tags Relocation") +trans.Start() +# loop tags +for i in tags: + # get room location + room_loc = i.Room.Location.Point + # location to move (room location - current tag location) + new_loc = room_loc - i.Location.Point + # move to new location + i.Location.Move(new_loc) + +print "DONE!" +trans.Commit() \ No newline at end of file From 529ad291f7043146c294ef215a6357d02d3b56d5 Mon Sep 17 00:00:00 2001 From: Deyan Nenov Date: Sat, 10 Nov 2018 12:26:14 +0000 Subject: [PATCH 06/15] Create Snippets_DimensionGrids --- 1-csharp-code/Snippets_DimensionGrids | 66 +++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 1-csharp-code/Snippets_DimensionGrids diff --git a/1-csharp-code/Snippets_DimensionGrids b/1-csharp-code/Snippets_DimensionGrids new file mode 100644 index 0000000..7799449 --- /dev/null +++ b/1-csharp-code/Snippets_DimensionGrids @@ -0,0 +1,66 @@ +/* +Create a dimension line between all chosen grid. The gird lines need to be parallel to each other, +which is the case most of the time but not always. +TESTED REVIT API: 2018 +The snippet can be used as is in a Revit Application Macro for test purposes +Author: Deyan Nenov | github.com/ArchilizerLtd | www.archilizer.com +This file is shared on www.revitapidocs.com +For more information visit http://github.com/gtalarico/revitapidocs +License: http://github.com/gtalarico/revitapidocs/blob/master/LICENSE.md +*/ + +public void DimGrids() +{ + UIDocument uidoc = this.ActiveUIDocument; + Document doc = uidoc.Document; + + // Pick all the grid lines you want to dimension to + GridSelectionFilter filter = new ThisApplication.GridSelectionFilter(doc); + IList grids = uidoc.Selection.PickElementsByRectangle(filter, "Pick Grid Lines"); + + ReferenceArray refArray = new ReferenceArray(); + XYZ dir = null; + + foreach(Element el in grids) + { + Grid gr = el as Grid; + + if(gr == null) continue; + if(dir == null) + { + Curve crv = gr.Curve; + dir = new XYZ(0,0,1).CrossProduct((crv.GetEndPoint(0) - crv.GetEndPoint(1))); // Get the direction of the gridline + } + + Reference gridRef = null; + + // Options to extract the reference geometry needed for the NewDimension method + Options opt = new Options(); + opt.ComputeReferences = true; + opt.IncludeNonVisibleObjects = true; + opt.View = doc.ActiveView; + foreach (GeometryObject obj in gr.get_Geometry(opt)) + { + if (obj is Line) + { + Line l = obj as Line; + gridRef = l.Reference; + refArray.Append(gridRef); // Append to the list of all reference lines + } + } + } + + XYZ pickPoint = uidoc.Selection.PickPoint(); // Pick a placement point for the dimension line + Line line = Line.CreateBound(pickPoint, pickPoint + dir * 100); // Creates the line to be used for the dimension line + + using(Transaction t = new Transaction(doc, "Make Dim")) + { + t.Start(); + if( !doc.IsFamilyDocument ) + { + doc.Create.NewDimension( + doc.ActiveView, line, refArray); + } + t.Commit(); + } +} From a7dca5295dcf9c8d3ada0fb75ed347901dd5ed65 Mon Sep 17 00:00:00 2001 From: Gui Talarico Date: Sun, 11 Nov 2018 18:56:47 -0500 Subject: [PATCH 07/15] Delete Tools_RoomTagMoveToRoomLocation.py @mgjean I started this PR to fix the import statement, but then I noticed the code snipped was almost identical to this one: https://github.com/gtalarico/revitapidocs.code/blob/master/0-python-code/Tools_MoveRoomTagToRoomCenter.py Do you agree? --- .../Tools_RoomTagMoveToRoomLocation.py | 33 ------------------- 1 file changed, 33 deletions(-) delete mode 100644 0-python-code/Tools_RoomTagMoveToRoomLocation.py diff --git a/0-python-code/Tools_RoomTagMoveToRoomLocation.py b/0-python-code/Tools_RoomTagMoveToRoomLocation.py deleted file mode 100644 index 4c2cce5..0000000 --- a/0-python-code/Tools_RoomTagMoveToRoomLocation.py +++ /dev/null @@ -1,33 +0,0 @@ -""" -ROOM TAGS MOVE TO ROOM LOCATION - -TESTED REVIT API: 2016,2017,2018 - -Author: min.naung@https://twentytwo.space/contact | https://github.com/mgjean - -This file is shared on www.revitapidocs.com -For more information visit http://github.com/gtalarico/revitapidocs -License: http://github.com/gtalarico/revitapidocs/blob/master/LICENSE.md -""" -from Autodesk.Revit.DB import FilteredWorksetCollector, WorksetKind -from Autodesk.Revit.DB import Transaction - -# document instance -doc = __revit__.ActiveUIDocument.Document - -# collect room tags from active view -tags = FilteredElementCollector(doc, doc.ActiveView.Id).OfClass(SpatialElementTag).ToElements() - -trans = Transaction(doc, "Room Tags Relocation") -trans.Start() -# loop tags -for i in tags: - # get room location - room_loc = i.Room.Location.Point - # location to move (room location - current tag location) - new_loc = room_loc - i.Location.Point - # move to new location - i.Location.Move(new_loc) - -print "DONE!" -trans.Commit() \ No newline at end of file From 942c77d18a9630a23a17532d47ab1ec6bbcfdc36 Mon Sep 17 00:00:00 2001 From: Gui Talarico Date: Sun, 11 Nov 2018 19:17:52 -0500 Subject: [PATCH 08/15] Update Tools_MoveRoomTagToRoomCenter.py See PR #20 --- 0-python-code/Tools_MoveRoomTagToRoomCenter.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/0-python-code/Tools_MoveRoomTagToRoomCenter.py b/0-python-code/Tools_MoveRoomTagToRoomCenter.py index 3968f0f..ad6ec0a 100644 --- a/0-python-code/Tools_MoveRoomTagToRoomCenter.py +++ b/0-python-code/Tools_MoveRoomTagToRoomCenter.py @@ -1,9 +1,10 @@ """ -Moves all selected tags to the center of their corresponding rooms +Moves all tags to the "Room Location Point" of their corresponding rooms TESTED REVIT API: 2015, 2016, 2017, 2017.1 Author: Gui Talarico | github.com/gtalarico + min.naung | https://twentytwo.space/contact | https://github.com/mgjean This file is shared on www.revitapidocs.com For more information visit http://github.com/gtalarico/revitapidocs @@ -16,17 +17,15 @@ clr.AddReference('RevitAPIUI') from Autodesk.Revit.DB import Transaction -from Autodesk.Revit.DB import FilteredElementCollector, BuiltInCategory -from Autodesk.Revit.DB.Architecture import Room +from Autodesk.Revit.DB import FilteredElementCollector, SpatialElementTag uidoc = __revit__.ActiveUIDocument doc = __revit__.ActiveUIDocument.Document ########################################################################### # TAG COLLECTOR [IN VIEW BY: doc.ActiveView.Id] -room_tags = FilteredElementCollector(doc, doc.ActiveView.Id).OfCategory( - BuiltInCategory.OST_RoomTags).WhereElementIsNotElementType().\ - ToElements() +room_tags = FilteredElementCollector(doc, doc.ActiveView.Id)\ + .OfClass(SpatialElementTag).ToElements() ########################################################################### transaction = Transaction(doc, 'Move Room Tags on Room Points') From 39e4575e12939c22864d94f63a4d9e90a842ed49 Mon Sep 17 00:00:00 2001 From: hdm-dt-fb Date: Thu, 10 Jan 2019 11:41:25 +0100 Subject: [PATCH 09/15] add script --- ...SetViewTemplateParameterToNotControlled.py | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 0-python-code/Tools_SetViewTemplateParameterToNotControlled.py diff --git a/0-python-code/Tools_SetViewTemplateParameterToNotControlled.py b/0-python-code/Tools_SetViewTemplateParameterToNotControlled.py new file mode 100644 index 0000000..b83a9e2 --- /dev/null +++ b/0-python-code/Tools_SetViewTemplateParameterToNotControlled.py @@ -0,0 +1,52 @@ +""" +Set view template parameter to not controlled by view template + +Sets a single view template parameter 'keep_non_sheet_view' +to be not controlled by view template, keeping other view +template parameters settings. + +TESTED REVIT API: 2017 + +Author: Frederic Beaupere | github.com/hdm-dt-fb + +This file is shared on www.revitapidocs.com +For more information visit http://github.com/gtalarico/revitapidocs +License: http://github.com/gtalarico/revitapidocs/blob/master/LICENSE.md +""" + +import clr +clr.AddReference("RevitAPI") +from Autodesk.Revit.DB import FilteredElementCollector as Fec +from System.Collections.Generic import List +from rpw import db, doc + + +all_views = Fec(doc).OfClass(View).ToElements() +view_templates = [view for view in all_views if view.IsTemplate] +first_view_template = view_templates[0] +view_template_params = first_view_template.GetTemplateParameterIds() +switch_off_param_name = "keep_non_sheet_view" + +# get the id of the parameter we want to switch off +for param_id in view_template_params: + param = doc.GetElement(param_id) + if "Name" in dir(param): + print(param.Name) + if param.Name == switch_off_param_name: + switch_off_param_id = param_id + break + +# set the switch off parameter to be non controlled +# while keeping the setting of the other parameters +with db.Transaction("adjust view_templates"): + + for view_template in view_templates: + set_param_list = List[ElementId]() + set_param_list.Add(switch_off_param_id) + + non_controlled_param_ids = view_template.GetNonControlledTemplateParameterIds() + + for param_id in non_controlled_param_ids: + set_param_list.Add(param_id) + + view_template.SetNonControlledTemplateParameterIds(set_param_list) From 79a99be321e5edae9b0443fb7cb9f2d65b413428 Mon Sep 17 00:00:00 2001 From: hdm-dt-fb Date: Fri, 11 Jan 2019 11:40:12 +0100 Subject: [PATCH 10/15] remove rpw dependency --- ...SetViewTemplateParameterToNotControlled.py | 27 +++++++++++-------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/0-python-code/Tools_SetViewTemplateParameterToNotControlled.py b/0-python-code/Tools_SetViewTemplateParameterToNotControlled.py index b83a9e2..c371edc 100644 --- a/0-python-code/Tools_SetViewTemplateParameterToNotControlled.py +++ b/0-python-code/Tools_SetViewTemplateParameterToNotControlled.py @@ -17,10 +17,11 @@ import clr clr.AddReference("RevitAPI") from Autodesk.Revit.DB import FilteredElementCollector as Fec +from Autodesk.Revit.DB import Transaction from System.Collections.Generic import List -from rpw import db, doc +doc = __revit__.ActiveUIDocument.Document all_views = Fec(doc).OfClass(View).ToElements() view_templates = [view for view in all_views if view.IsTemplate] first_view_template = view_templates[0] @@ -38,15 +39,19 @@ # set the switch off parameter to be non controlled # while keeping the setting of the other parameters -with db.Transaction("adjust view_templates"): - for view_template in view_templates: - set_param_list = List[ElementId]() - set_param_list.Add(switch_off_param_id) +t = Transaction(doc, "adjust view_templates") +t.Start() + +for view_template in view_templates: + set_param_list = List[ElementId]() + set_param_list.Add(switch_off_param_id) + + non_controlled_param_ids = view_template.GetNonControlledTemplateParameterIds() + + for param_id in non_controlled_param_ids: + set_param_list.Add(param_id) - non_controlled_param_ids = view_template.GetNonControlledTemplateParameterIds() - - for param_id in non_controlled_param_ids: - set_param_list.Add(param_id) - - view_template.SetNonControlledTemplateParameterIds(set_param_list) + view_template.SetNonControlledTemplateParameterIds(set_param_list) + +t.Commit() From 870b48449bd799f2b7cb2479146747a93e97db85 Mon Sep 17 00:00:00 2001 From: franpossetto Date: Sat, 20 Apr 2019 15:58:07 -0300 Subject: [PATCH 11/15] Add Get Parameter Value by Name, Set Parameter Value by Name and Get All Elements of Category Examples --- .../HowTo_GetAllElementsOfCategory.py | 26 ++++++++++++++++ .../HowTo_GetParameterValueByName.py | 25 +++++++++++++++ 0-python-code/HowTo_SetParameterByName.py | 31 +++++++++++++++++++ 3 files changed, 82 insertions(+) create mode 100644 0-python-code/HowTo_GetAllElementsOfCategory.py create mode 100644 0-python-code/HowTo_GetParameterValueByName.py create mode 100644 0-python-code/HowTo_SetParameterByName.py diff --git a/0-python-code/HowTo_GetAllElementsOfCategory.py b/0-python-code/HowTo_GetAllElementsOfCategory.py new file mode 100644 index 0000000..bccbad4 --- /dev/null +++ b/0-python-code/HowTo_GetAllElementsOfCategory.py @@ -0,0 +1,26 @@ +""" +All elements of Category +Get all elements of the specified category from Model. + +TESTED REVIT API: 2016,2017 + +Author: Francisco Possetto | github.com/franpossetto +""" + +#Imports. +from Autodesk.Revit.DB import FilteredElementCollector, BuiltInCategory + +doc = __revit__.ActiveUIDocument.Document + +def all_elements_of_category(category): + return FilteredElementCollector(doc).OfCategory(category).WhereElementIsNotElementType().ToElements() + +#All Elements Of Walls Category. +walls = all_elements_of_category(BuiltInCategory.OST_Walls) + +#All Elements Of Doors Category. +doors = all_elements_of_category(BuiltInCategory.OST_Doors) + +#All Elements Of Windows Category. +windows = all_elements_of_category(BuiltInCategory.OST_Windows) + diff --git a/0-python-code/HowTo_GetParameterValueByName.py b/0-python-code/HowTo_GetParameterValueByName.py new file mode 100644 index 0000000..5eac831 --- /dev/null +++ b/0-python-code/HowTo_GetParameterValueByName.py @@ -0,0 +1,25 @@ +""" +Get Parameter Value by Name +Get value of one of element's parameters. + +TESTED REVIT API: 2016,2017 + +Author: Francisco Possetto | github.com/franpossetto +""" + +#Imports. +from Autodesk.Revit.DB import Element + +doc = __revit__.ActiveUIDocument.Document +uidoc = __revit__.ActiveUIDocument + +def get_parameter_value_by_name(element, parameterName): + return element.LookupParameter(parameterName).AsValueString() + +#Select elements from revit. +selection = [doc.GetElement(x) for x in uidoc.Selection.GetElementIds()] + +#Example with Walls. +for wall in selection: + print get_parameter_value_by_name(wall, "Base Constraint") + \ No newline at end of file diff --git a/0-python-code/HowTo_SetParameterByName.py b/0-python-code/HowTo_SetParameterByName.py new file mode 100644 index 0000000..b570443 --- /dev/null +++ b/0-python-code/HowTo_SetParameterByName.py @@ -0,0 +1,31 @@ +""" +Set Parameter by Name +Set one of element's parameters. + +TESTED REVIT API: 2016,2017 + +Author: Francisco Possetto | github.com/franpossetto +""" + +#Imports +from Autodesk.Revit.DB import Element, Transaction + +doc = __revit__.ActiveUIDocument.Document +uidoc = __revit__.ActiveUIDocument +t = Transaction(doc, 'Set Parameter by Name') + +#Select element from revit. +selection = [doc.GetElement(x) for x in uidoc.Selection.GetElementIds()] + +def set_parameter_by_name(element, parameterName, value): + element.LookupParameter(parameterName).Set(value) + +#Start Transaction +t.Start() + +for s in selection: + #Set a new Comment + set_parameter_by_name(s,"Comments", "Good Element") + +#End Transaction +t.Commit() \ No newline at end of file From 52c91190ef6bf2c3f6055d7db8aaa33a04b7fe0d Mon Sep 17 00:00:00 2001 From: franpossetto Date: Wed, 24 Apr 2019 16:16:50 -0300 Subject: [PATCH 12/15] Add License line (#23) Thanks you! --- 0-python-code/HowTo_GetAllElementsOfCategory.py | 4 ++++ 0-python-code/HowTo_GetParameterValueByName.py | 4 ++++ 0-python-code/HowTo_SetParameterByName.py | 4 ++++ 3 files changed, 12 insertions(+) diff --git a/0-python-code/HowTo_GetAllElementsOfCategory.py b/0-python-code/HowTo_GetAllElementsOfCategory.py index bccbad4..54910a4 100644 --- a/0-python-code/HowTo_GetAllElementsOfCategory.py +++ b/0-python-code/HowTo_GetAllElementsOfCategory.py @@ -5,6 +5,10 @@ TESTED REVIT API: 2016,2017 Author: Francisco Possetto | github.com/franpossetto + +Shared on www.revitapidocs.com +For more information visit http://github.com/gtalarico/revitapidocs +License: http://github.com/gtalarico/revitapidocs/blob/master/LICENSE.md """ #Imports. diff --git a/0-python-code/HowTo_GetParameterValueByName.py b/0-python-code/HowTo_GetParameterValueByName.py index 5eac831..6aeb99d 100644 --- a/0-python-code/HowTo_GetParameterValueByName.py +++ b/0-python-code/HowTo_GetParameterValueByName.py @@ -5,6 +5,10 @@ TESTED REVIT API: 2016,2017 Author: Francisco Possetto | github.com/franpossetto + +Shared on www.revitapidocs.com +For more information visit http://github.com/gtalarico/revitapidocs +License: http://github.com/gtalarico/revitapidocs/blob/master/LICENSE.md """ #Imports. diff --git a/0-python-code/HowTo_SetParameterByName.py b/0-python-code/HowTo_SetParameterByName.py index b570443..a2c675a 100644 --- a/0-python-code/HowTo_SetParameterByName.py +++ b/0-python-code/HowTo_SetParameterByName.py @@ -5,6 +5,10 @@ TESTED REVIT API: 2016,2017 Author: Francisco Possetto | github.com/franpossetto + +Shared on www.revitapidocs.com +For more information visit http://github.com/gtalarico/revitapidocs +License: http://github.com/gtalarico/revitapidocs/blob/master/LICENSE.md """ #Imports From e0a69a9eec6802b9206a4c19824f6955215f1d95 Mon Sep 17 00:00:00 2001 From: Deyan Nenov Date: Mon, 1 Jul 2019 16:47:08 +0100 Subject: [PATCH 13/15] Added GridSelectionFilter class that was missing (#24) --- 1-csharp-code/Snippets_DimensionGrids | 31 +++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/1-csharp-code/Snippets_DimensionGrids b/1-csharp-code/Snippets_DimensionGrids index 7799449..09b2c04 100644 --- a/1-csharp-code/Snippets_DimensionGrids +++ b/1-csharp-code/Snippets_DimensionGrids @@ -8,7 +8,9 @@ This file is shared on www.revitapidocs.com For more information visit http://github.com/gtalarico/revitapidocs License: http://github.com/gtalarico/revitapidocs/blob/master/LICENSE.md */ - +/// +/// Creates a single dimension string between the chosen Grid lines +/// public void DimGrids() { UIDocument uidoc = this.ActiveUIDocument; @@ -16,7 +18,7 @@ public void DimGrids() // Pick all the grid lines you want to dimension to GridSelectionFilter filter = new ThisApplication.GridSelectionFilter(doc); - IList grids = uidoc.Selection.PickElementsByRectangle(filter, "Pick Grid Lines"); + var grids = uidoc.Selection.PickElementsByRectangle(filter, "Pick Grid Lines"); ReferenceArray refArray = new ReferenceArray(); XYZ dir = null; @@ -64,3 +66,28 @@ public void DimGrids() t.Commit(); } } +/// +/// Grid Selection Filter (example for selection filters) +/// +public class GridSelectionFilter : ISelectionFilter +{ + Document doc = null; + public GridSelectionFilter(Document document) + { + doc = document; + } + + public bool AllowElement(Element element) + { + if(element.Category.Name == "Grids") + { + return true; + } + return false; + } + + public bool AllowReference(Reference refer, XYZ point) + { + return true; + } +} From aa5380b85b560d1920889650969953f6cbe2a07d Mon Sep 17 00:00:00 2001 From: franpossetto <13245192+franpossetto@users.noreply.github.com> Date: Mon, 17 Aug 2020 13:54:00 -0300 Subject: [PATCH 14/15] Code snippets for cs (#26) * Add Snippets_GetWorksetByName.cs and Snippets_HideCategory.cs * Delete blank lines * Add new line at the end of the file --- 1-csharp-code/Snippets_GetWorksetByName.cs | 21 +++++++++++++++ 1-csharp-code/Snippets_HideCategory.cs | 31 ++++++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 1-csharp-code/Snippets_GetWorksetByName.cs create mode 100644 1-csharp-code/Snippets_HideCategory.cs diff --git a/1-csharp-code/Snippets_GetWorksetByName.cs b/1-csharp-code/Snippets_GetWorksetByName.cs new file mode 100644 index 0000000..478d881 --- /dev/null +++ b/1-csharp-code/Snippets_GetWorksetByName.cs @@ -0,0 +1,21 @@ +/* +Get workset by name. +TESTED REVIT API: 2020 +Author: Francisco Possetto | github.com/franpossetto +This file is shared on www.revitapidocs.com +For more information visit http://github.com/gtalarico/revitapidocs +License: http://github.com/gtalarico/revitapidocs/blob/master/LICENSE.md +*/ + +using System.Linq; +using System.Collections.Generic; +using Autodesk.Revit.DB; + +public Workset GetWorksetByName(Document doc, string WorksetName) +{ + IList worksets = new FilteredWorksetCollector(doc).OfKind(WorksetKind.UserWorkset).ToWorksets(); + Workset workset = worksets.Where(x => x.Name == WorksetName).FirstOrDefault(); + + //if the workset does not exist, return the first one. + return (workset != null) ? workset : worksets.FirstOrDefault(); +} diff --git a/1-csharp-code/Snippets_HideCategory.cs b/1-csharp-code/Snippets_HideCategory.cs new file mode 100644 index 0000000..0d29f05 --- /dev/null +++ b/1-csharp-code/Snippets_HideCategory.cs @@ -0,0 +1,31 @@ +/* +Hide Category. +TESTED REVIT API: 2020 +Hide / Unhide Category in the active view. +Author: Francisco Possetto | github.com/franpossetto +This file is shared on www.revitapidocs.com +For more information visit http://github.com/gtalarico/revitapidocs +License: http://github.com/gtalarico/revitapidocs/blob/master/LICENSE.md +*/ + +using Autodesk.Revit.DB; + +public void HideCategory(Document doc, string categoryName, bool hide) +{ + View activeView = doc.ActiveView; + Categories categories = doc.Settings.Categories; + Category category = null; + + // Get the category by name + foreach (Category cat in categories) + if (cat.Name == categoryName) category = cat; + + if (category == null) return; + + using (Transaction t = new Transaction(doc, "Hide/Unhide Category")) + { + t.Start(); + activeView.SetCategoryHidden(category.Id, hide); + t.Commit(); + } +} From a8103ff10fcc0d55c7e484b0dc8d1fce954433d7 Mon Sep 17 00:00:00 2001 From: RobertCurry0216 <51145821+RobertCurry0216@users.noreply.github.com> Date: Fri, 16 Oct 2020 03:04:29 +1100 Subject: [PATCH 15/15] GetFamilySymbolByName C# Snippet added (#27) Co-authored-by: Robert Curry --- .../Snippit_FindFamilySymbolByName.cs | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 1-csharp-code/Snippit_FindFamilySymbolByName.cs diff --git a/1-csharp-code/Snippit_FindFamilySymbolByName.cs b/1-csharp-code/Snippit_FindFamilySymbolByName.cs new file mode 100644 index 0000000..f3db9fc --- /dev/null +++ b/1-csharp-code/Snippit_FindFamilySymbolByName.cs @@ -0,0 +1,38 @@ +/* +Pass Document and name string as Variables +This snippet is a utility function to make working with family symbols easier +also is an example on using FilteredElementCollector filters + +TESTED REVIT API: 2019 +The snippet can be used as is in a Revit Application Macro for test purposes + +Author: Robert Curry | https://github.com/RobertCurry0216 + +This file is shared on www.revitapidocs.com +For more information visit http://github.com/gtalarico/revitapidocs +License: http://github.com/gtalarico/revitapidocs/blob/master/LICENSE.md +*/ + +public static FamilySymbol GetFamilySymbolByName(Document doc, string name) +{ + var paramId = new ElementId(BuiltInParameter.ALL_MODEL_FAMILY_NAME); + var paramValueProvider = new ParameterValueProvider(paramId); + var equalsRule = new FilterStringEquals(); + var filterRule = new FilterStringRule(paramValueProvider, equalsRule, name, false); + var filter = new ElementParameterFilter(filterRule); + + var fec = new FilteredElementCollector(doc); + fec.OfClass(typeof(FamilySymbol)).WhereElementIsElementType().WherePasses(filter); + + if (fec.GetElementCount() == 1) + { + var symbol = fec.FirstElement() as FamilySymbol; + if (!symbol.IsActive) + { + symbol.Activate(); + doc.Regenerate(); + } + return symbol; + } + return null; +} \ No newline at end of file