hi I wonder if somebody can help me,
using this code
IList<Reference> selElements = uidoc.Selection.PickObjects(ObjectType.Element);
I want to get and set parameter.
cheers
Solved! Go to Solution.
Solved by Mustafa.Salaheldin. Go to Solution.
Solved by jeremytammik. Go to Solution.
hi Jeremy,
thank you. I always follow your blog and pick lots of techniques and procedure.
however this pick objects i got error something like cannot convert reference to element.
could you help me sort it out.
thank you,
Mark
my objective in doing that is to select multiple elements, get and sets their parameters.
Picking an element is one topic.
Apparently, you have solved that to your satisfaction.
Congratulations on that step forward!
Getting and setting element parameters is another topic, equally simple, trivial, in fact, and fully covered by the getting started material and a couple of thousand other online examples.
How about working through that material yet?
Have you installed and explored the Revit SDK samples yet?
Have you installed RevitLookup?
Those are simple, invaluable steps that will save you a lot of time in the long run...
Good luck and have fun!
Cheers,
Jeremy
Hello
You have to deal with one issue here which is implementing the IList interface so instead of using :
IList<Reference> selElements = uidoc.Selection.PickObjects(ObjectType.Element);
Please use:
List<Reference> selElements = uidoc.Selection.PickObjects(ObjectType.Element).ToList();
Then iterate through the selElements list and get the element using
Element el = doc.GetElement(reference);
and set the parameters you need.
Please if this reply satisfies your need mark it as an answer.
How come when using Python (based on pyRevit), when I write:
pickedGrids = Selection.PickObjects(ObjectType.Element).ToList()
I get:
TypeError: PickObjects() takes at least 2 arguments (1 given)
It seems strange because the documentation should allow 1 argument.
https://www.revitapidocs.com/2019/577ac5d0-8a6d-8e73-9d0d-259ed0ac6024.htm
Same with PickElementsByRectangle() which should work without arguments:
https://www.revitapidocs.com/2019/2be6b3b7-2cec-1d8a-76fb-afcd618fcae6.htm
Any idea why this happens..?
Thanks
Please search this discussion forum for "Python arguments" and you will find an answer already there:
This should explain in full.
@jeremytammik Thank you. I'm not sure I understand the implementation that can apply here with regards to the post you linked to.
In Python I guess 'this' is equal to 'self', but I'm not sure what can be done here because I'm already in the correct Namespace with Selection.
I'll try to investigate more into usage of 'self' with Python and the Revit API.
Okay, but if we take the line:
pickedGrids = Selection.PickElementsByRectangle("Pick Grids")
which is the string overload, then still the error appears:
Not sure what you mean.
I did specify. I used the overload for 1 argument string and placed a string there.
Isn't that specifying the overload...?
OK, you have to use something like this:
List<Reference> selElements = uidoc.Selection.PickObjects.Overloads[Element](ObjectType.Element).ToList()
Where after the "PickObjects" function you enforce the signature (overload) that you want to use.
At your case it maybe something like this:
pickedGrids = Selection.PickElementsByRectangle.Overloads[String]("Pick Grids")
If this reply satisfies your request please don't forget to mark it as an answer.
I think you're using C# syntax ..?
Using the .Overloads[] gives an error of:
This code is not Python syntax but my point is to introduce how to use the Overloads method.
My imports for Python are:
import clr
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
clr.AddReference("System")
from System.Collections.Generic import List
clr.AddReference('RevitNodes')
import Revit
clr.ImportExtensions(Revit.GeometryConversion)
clr.ImportExtensions(Revit.Elements)
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
I think you need to import the clr extensions.
I tried importing the following:
from pyrevit.framework import clr
clr.AddReference('RevitAPI')
clr.AddReference("System")
clr.AddReference('RevitNodes')
import Revit
clr.ImportExtensions(Revit.GeometryConversion)
clr.ImportExtensions(Revit.Elements)
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
but still the same error..
Investigating further, since I'm using a python script based on the pyRevit framework specifically -
From these two links:
https://github.com/eirannejad/pyRevit/issues/307
https://github.com/eirannejad/pyRevit/issues/483
it doesn't seem that Overloads is even necessary or used in the pyRevit framework when trying to achieve functionality.
Actually I'm not sure, I just give you information from my experience in a previous code in Dynamo Python node. I didn't try it with pyRevit.
In my Dynamo Python code, it was also confused between different overloads. That is why I ad to specify it.
Jeremy:
How about actually answering a question for once, instead of mindlessly referring people to the help files and all of your blogs.
Thanks for your consideration.
Dear Greg,
Sorry for annoying you.
It is quite a bit of work trying to document optimal answers, and it is surprising that people keep coming up with new questions. On the other hand, quite a number of questions are not new at all, but old and repeated and already documented. Whenever I actually do answer a question, as you suggest I should do more of, I perform some searches for existing answers first. Often, my search turns up an answer that was there all along. Sometimes, I repeat it. Sometimes, I try to improve the documentation. Sometimes, I suggest that the person raising the question perform a search themself. I try to keep a balance. I sometimes fail to get it right. Sorry for that.
Happy Easter!
Best regards,
Jeremy
Can't find what you're looking for? Ask the community or share your knowledge.