Load & reload (redefine) families in Autodesk Revit
I'm glad to represent you a script for load/reload families in Revit project.
Just run the script from Dynamo player, choose a folder with families and families in window and click the button - all selected families will be reloaded.
Script scheme is:
"WindowsForm Create" node code is:
"FamReloader" node code is:
"ShowDialog" node code is:
Download script for Dynamo - Link
Just run the script from Dynamo player, choose a folder with families and families in window and click the button - all selected families will be reloaded.
"WindowsForm Create" node code is:
import clr clr.AddReference('System.Windows.Forms') clr.AddReference('System.Drawing') from System.Drawing import Size, Color, SolidBrush, Rectangle, Point from System.Windows.Forms import * import sys sys.path.append(r"C:\Program Files (x86)\IronPython 2.7\Lib") import os from System.IO import Directory, SearchOption class TESForm(Form): def __init__(self): self.Text = "Families Loader/ReLoader" self.Width = 500 self.Height = 310 self.MaximizeBox = False self.MinimizeBox = False self.ControlBox = False self.FormBorderStyle = FormBorderStyle.FixedSingle self.ShowIcon = False self.StartPosition = FormStartPosition.CenterScreen self.TopMost = True self.values = [] self.pathvalue = [] self.label = Label() self.label.Text = "--- NO PATH FOUND ---" self.label.Location = Point(20, 13) self.label.Height = 30 self.label.Width = 290 self.label.ForeColor = Color.Red self.button = Button() self.button.Text = "Nothing to reload" self.button.Width = 330 self.button.Location = Point (20, 230) self.button.Click += self.setclose self.button.Enabled = False self.button0 = Button() self.button0.Text = "Browse..." self.button0.Width = 100 self.button0.Location = Point (360, 10) self.button0.Click += self.OnClickedFile self.button1 = Button() self.button1.Text = "Exit" self.button1.Width = 100 self.button1.Location = Point (360, 230) self.button1.Click += self.setexit self.list = ListBox() self.list.Size = Size(440, 150) self.list.Location = Point(20, 50) self.list.SelectionMode = SelectionMode.MultiExtended self.check = CheckBox() self.check.Location = Point(20, 205) self.check.Text = 'Select all' self.check.Width = 70 self.check.Enabled = False self.check.CheckedChanged += self.checkedChanged self.Controls.Add(self.label) self.Controls.Add(self.button) self.Controls.Add(self.button0) self.Controls.Add(self.button1) self.Controls.Add(self.list) self.Controls.Add(self.check) def setclose(self, sender, event): for idx in self.list.SelectedIndices: self.values.append(self.pathvalue[idx]) self.Close() def setexit(self, sender, event): self.values = 'Exit' self.Close() def checkedChanged(self, sender, args): if sender.Checked: for i in range(self.list.Items.Count): self.list.SetSelected(i, True) else: self.list.ClearSelected() self.list.SetSelected(0, True) def OnClickedFile(self, sender, events): dialog = FolderBrowserDialog() if (dialog.ShowDialog(self) == DialogResult.OK): self.label.Text = dialog.SelectedPath if Directory.Exists(dialog.SelectedPath): files = Directory.GetFiles(dialog.SelectedPath, '*.rfa', SearchOption.TopDirectoryOnly) for i in files: fname = os.path.basename(i) truname = os.path.splitext(fname)[0] self.list.Items.Add(truname) self.list.SetSelected(0, True) else: files = [] if len(files) != 0: self.button.Enabled = True self.check.Enabled = True self.label.ForeColor = Color.Blue self.button.Text = "Load/ReLoad Families form path" self.pathvalue = files else: self.list.Items.Clear() self.button.Enabled = False self.label.ForeColor = Color.Red self.button.Text = "Nothing to reload" self.check.Enabled = False form = TESForm() form.ShowDialog() result = form.values OUT = result
"FamReloader" node code is:
import clr clr.AddReference('RevitAPI') from Autodesk.Revit.DB import * clr.AddReference('RevitServices') import RevitServices from RevitServices.Persistence import DocumentManager from RevitServices.Transactions import TransactionManager doc = DocumentManager.Instance.CurrentDBDocument elements = IN[0] class FamilyOption(IFamilyLoadOptions) : def OnFamilyFound(self, familyInUse, overwriteParameterValues) : overwriteParameterValues = True return True def OnSharedFamilyFound(self, sharedFamily, familyInUse, source, overwriteParameterValues) : return True if IN[0] != 'Exit': TransactionManager.Instance.EnsureInTransaction(doc) try: for element in elements : doc.LoadFamily(element, FamilyOption()) OUT = 'Families was loaded/reloaded' except: pass TransactionManager.Instance.TransactionTaskDone() else: OUT = 'Exit'
"ShowDialog" node code is:
import clr clr.AddReferenceByName("RevitAPI") clr.AddReferenceByName("RevitAPIUI") from Autodesk.Revit import * from Autodesk.Revit.UI import * from Autodesk.Revit.UI.Macros import * from Autodesk.Revit.DB import * from Autodesk.Revit.UI.Selection import * dialog = TaskDialog('Families Loader/ReLoader') result = IN[0] msg = IN[1] dialog.MainIcon = TaskDialogIcon.TaskDialogIconNone dialog.TitleAutoPrefix = False dialog.AllowCancellation = True dialog.MainContent = result + ': ' + str(msg) if IN[0] != 'Exit': dialog.Show()
Download script for Dynamo - Link
Comments
Post a Comment