@Einar_Raknes
I downloaded the DS above, but having no Python/API skills it’s like reading my Japanese kana, I can read the symbols but have no clue to meaning and much less how to modify it. Hopefully, other programmers will give it a try. Thanks again for your time and effort!
Hi Jonathan,
Maybe the new “Document.BackgroundOpen” node of @john_pierson/Rhythm/sixtysecondrevit can help you.
http://sixtysecondrevit.com/2016-11-07-open-revit-files-in-background-with/
Good luck
I had a look at it now, but without any luck. It seems that the doc.EditFamily(f)
doesn’t like to be called within Dynamo. I tested similar code in Revit Python Shell and it worked without problems. Strangly some very similar workflows for setting shared parameters in families seem to work:
- http://stackoverflow.com/questions/35513566/revit-api-dynamo-creating-a-family-parameter-from-project-document
- http://dynamobim.org/forums/topic/modify-room-calculation-point-toggle-builtin-parameter/
- Batch add shared parameters to families in project from .txt file with ui.multipleinputform ++
Maybe @Mostafa_El_Ayoubi understand why? It’s probably something about how Dynamo handles transactions.
Here is the python script if you wold like to try:
import clr
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
clr.AddReference('RevitAPIUI')
from Autodesk.Revit.UI import *
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument
class FamilyOption(IFamilyLoadOptions):
def OnFamilyFound(self,familyInUse,overwriteParameterValues):
overwriteParameterValues = True
return True
def OnSharedFamilyFound(self, sharedFamily, familyInUse, FamilySource, overwriteParameterValues):
overwriteParameterValues = True
return True
#Preparing input from dynamo to revit
f = UnwrapElement(IN[0])
o = IN[1]
OUT = []
famdoc = doc.EditFamily(f)
thisFamily = famdoc.OwnerFamily
parOmniclass = thisFamily.get_Parameter(BuiltInParameter.OMNICLASS_CODE)
TransactionManager.Instance.EnsureInTransaction(famdoc)
parOmniclass.Set(o)
TransactionManager.Instance.TransactionTaskDone()
TransactionManager.Instance.ForceCloseTransaction()
famdoc.LoadFamily(doc, FamilyOption())
famdoc.Close(False)
OUT = 0
Here is the code I used in Revit Python Shell:
import clr
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
clr.AddReference('RevitAPIUI')
from Autodesk.Revit.UI import *
app = __revit__.Application
uidoc = __revit__.ActiveUIDocument
doc = __revit__.ActiveUIDocument.Document
class FamilyOption(IFamilyLoadOptions):
def OnFamilyFound(self,familyInUse,overwriteParameterValues):
return True
def OnSharedFamilyFound(self, sharedFamily, familyInUse, FamilySource, overwriteParameterValues):
return True
#Preparing input from dynamo to revit
fec = FilteredElementCollector(doc).OfClass(Family)
for f1 in fec:
if f1.Name == "NO_Column_CastInPlace_Round":
f = f1
break
o = "23.25.30.11.14.11"
famdoc = doc.EditFamily(f)
thisFamily = famdoc.OwnerFamily
parOmniclass = thisFamily.get_Parameter(BuiltInParameter.OMNICLASS_CODE)
t = Transaction(famdoc)
t.Start("Edit o")
parOmniclass.Set(o)
t.Commit()
print famdoc.LoadFamily(doc, FamilyOption())
print famdoc.Close(False)
Isn’t it true that Dynamo puts Revit in a read-only state when it’s run? That would explain why the EditFamily method doesn’t work, because that method can’t be used when Revit is in a read-only state.
It might have something to do with Dynamo and Revits Dynamic Model Update (DMU)
From API docs:
This creates an independent copy of the family for editing. To apply the changes back to the family stored in the document, use the LoadFamily overload accepting IFamilyLoadOptions .
This method may not be called if the document is currently modifiable (has an open transaction) or is in a read-only state. The method may not be called during dynamic updates. To test the document’s current status, check the values of IsModifiable and IsReadOnly properties.
The results from IsModifiable
and IsReadOnly
looks fine to me.
Uhm… Yeah that’s what I meant
Hi everyone, thanks for racking your brains on this!
I read thru the thread and was wondering if the attemps you’ve made above also cover the suggestion made by @MJB-online regarding @john_pierson’s node?
If not, and by the description there doesn’t seem to be DS or Python needed, I’ll look into it and reply back with further development because I’d like participate and to do my part in the question/problem solving
My node should be able to get you started, point to the family with file path, background open, get/set data.
But as @Einar_Raknes pointed out, working between documents is a bit difficult in Dynamo.If you are using any python nodes to achieve this you will need to give the node a document input similar to what I have done with the clockwork node above.
This should do the trick:
#Copyright(c) 2017, Konrad K Sobon
# @arch_laboratory, http://archi-lab.net
# Import Element wrapper extension methods
import clr
clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)
# Import DocumentManager and TransactionManager
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument
# Import RevitAPI
clr.AddReference("RevitAPI")
import Autodesk
from Autodesk.Revit.DB import *
import System
import sys
pyt_path = r'C:\Program Files (x86)\IronPython 2.7\Lib'
sys.path.append(pyt_path)
paramName = IN[1]
value = IN[2]
class FamilyOption(IFamilyLoadOptions):
def OnFamilyFound(self, familyInUse, overwriteParameterValues):
overwriteParameterValues = True
return True
def OnSharedFamilyFound(self, sharedFamily, familyInUse, source, overwriteParameterValues):
return True
def GetBuiltInParam(paramName):
builtInParams = System.Enum.GetValues(BuiltInParameter)
test = []
for i in builtInParams:
if i.ToString() == paramName:
test.append(i)
break
else:
continue
if len(test) == 0:
return None
else:
return test[0]
try:
errorReport = None
output = []
uniqueFams = set()
bip = GetBuiltInParam(paramName)
for i in IN[0]:
family = UnwrapElement(i).Symbol.Family
if family not in uniqueFams:
uniqueFams.add(family)
famDoc = doc.EditFamily(family)
if famDoc != None:
ownerFamily = famDoc.OwnerFamily
param = ownerFamily.get_Parameter(bip)
TransactionManager.Instance.EnsureInTransaction(famDoc)
param.Set(value)
TransactionManager.Instance.TransactionTaskDone()
output.append(famDoc.LoadFamily(doc, FamilyOption()))
except:
# if error accurs anywhere in the process catch it
import traceback
errorReport = traceback.format_exc()
#Assign your output to the OUT variable
if errorReport == None:
OUT = output
else:
OUT = errorReport
What if it is not a builtin parameter? Seems that in family doc, parameter changed by FamilyManager.Set() function do not get updated when loaded back to a project environment.
@wzy816 That would be another topic of the day.
Just got in and saw all the replies!
Since the “Solution” has already been checked and liked, I assume this solves the case!
Thanks @Konrad_K_Sobon for the final solution and everybody else who provided ideas to feed off from to help find the solution !
And from my understing of the node, it also provides a solution to other BIP, nice!
The code by @Konrad_K_Sobon is almost the same as mine, and I get the same problems as with my code when trying to run it.
Traceback (most recent call last):
File “”, line 61, in
Exception: The document is currently modifiable! Close the transaction before calling EditFamily.
Maybe it’s my version of Dynamo causing the problem. Have anyone else tested the code?
Revit 2017 and
Dynamo 2.0.0???
you can call this before calling EditFamily()
TransactionManager.Instance.ForceCloseTransaction()
That will ensure that no Transaction is open.
Yes, built from source: https://github.com/DynamoDS/Dynamo
- Download Dynamo master and DynamoRevit 2017 to the same forlder with github desktop.
- Bulid Dynamo Master
- Run restorepackages.bat
- Bulid DynamoRevit 2017
- Add .addin file to %appdata%\Autodesk\Revit\Addins\2017\ with path: “[Your GitHub Folder]\Dynamo\bin\AnyCPU\Debug\Revit_2017\DynamoRevitVersionSelector.dll”
Super bleeding edge! I like it!
Thank you! Thought I actually had tried that betfore, but it seems to work now.
Hi @Konrad_K_Sobon,
how would it be applicable to detailItems _ I guess yes_ in order to change line weight of the filled regions inside detailItems?
How can we add Room Calculation Point for all the Familes in Model using Dynamo.