Most manufacturer downloads have materials as instance based parameters. I want to go through a large batch of families and easily convert the family’s Material Parameters from Instance to Type and save a copy of the file.
I was using IronPython for this, but I currently can’t even return the open document. I only receive “None”.
EDIT: I have used RiR nodes to isolate the parameters I will want to change from Instance to Type. The Add Parameter node will not let me create a parameter using the names I filtered because they already exist.
Please Update the Tracking Mode setting to Enabled: Replace in the Add Parameter component. This ensures the parameter is replaced with new IDs without errors, regardless of scope changes.
Thanks, I didn’t know about that.
I turned it on, but I still get the error that the parameter already exists.
Can you share the screenshot of your workflow?
Sure. Error is: 1. RhinoInside.Revit.GH: The name ‘Power Pill Finish’ is already in use.
Trying to toggle these parameters into Type while maintaining the 3D object links to the parameters.
We use the Define Parameter and Add Parameter components when creating new parameters in the document. Since the parameters already exist in the Revit document, that’s why you’re seeing this error.
As far as I remember changing the scope of a parameter in a Revit family file requires recreating the parameter, as the Revit API does not allow direct modification of a parameter’s scope. Yo need to remove old parameters and create new parameters with required scope. or If you have shared Parameters File, you can use the following workflow to add new parameter.
I thought that’s what the “Replace” function would allow.
I’m not sure I can do what I’m attempting without something complicated like:
- Gather the parameter names and save the data so they can be rebuilt with the same naming
- Gather the ObjectIDs that are linked to each of the parameters and save the data
- Delete the Instance Parameters out of the family
- Rebuild the parameters with the saved names, but as Type Parameters
- Relink the objects based on the saved ObjectID back to the respective parameter
Meanwhile I can manually open the family, edit parameter, and toggle to Type instead of Instance. I will have to do that 400 times though, so it’s frustrating something so simple is not accessible via API.
Hi, just want to add that it should be possible to adjust a parameter scope through revit API, using the below
@M.Tarabishy Thanks for sharing.
I attempted to use this API (in C# which I abandoned), but I’m not a great coder. I’m having a lot of data mismatches in general.
FamilyInstance vs. Family vs. FamilyDocument vs. a string that looks like a Family and not having FamilyManager in whichever I’m attempting to use
FamilyParameter vs. Parameter vs. a string that looks like a Parameter
Also, IronPython is twice as hard as Python to find troubleshooting.
Hi @jmarsh
Here is the small example using python. Please try this one
import clr
clr.AddReference('RevitAPI')
clr.AddReference('RhinoInside.Revit')
from RhinoInside.Revit import Revit
from Autodesk.Revit import DB
doc = Revit.ActiveDBDocument
family_manager = doc.FamilyManager
params = family_manager.Parameters
shared_params = []
for p in params:
try:
guid = p.GUID
shared_params.append(p)
except:
pass
ct = shared_params
if Create == 1:
t = DB.Transaction(doc, "Change Scope")
t.Start()
try:
for param in ct:
if not param.IsInstance:
family_manager.MakeInstance(param)
t.Commit()
except Exception as txn_err:
print(str(txn_err))
t.RollBack()
I named the input Create and added a boolean toggle.
The doc and family_manager print out correctly. (Getting the doc is wayyy more simple than whatever I was following.)
Print results:
doc = Autodesk.Revit.DB.Document object
family_manager = Autodesk.Revit.DB.FamilyManager
params = Autodesk.Revit.DB.ParameterSet
Do I need to break down the ParameterSet to only select Material properties?
What other inputs should I set up? Is my output going to be “t” instead of “a”?
Thanks for your help!
As I can see from the image you shared, your Material parameters are shared. if you use the given code, it will automatically extract the shared parameters and set the new scope
Here is the Gh File
ChangeScope.gh (3.8 KB)
My guess is you are on GH2 for Rhino 8. I’m in Rhino 7, so that file doesn’t want to display correctly. Can you maybe just screenshot the Python node and mention if there’s any type hints needed?