Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

get and set parameters for pickObjects

20 REPLIES 20
SOLVED
Reply
Message 1 of 21
markjvlampad
3985 Views, 20 Replies

get and set parameters for pickObjects

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

20 REPLIES 20
Message 2 of 21
jeremytammik
in reply to: markjvlampad
Message 3 of 21
markjvlampad
in reply to: jeremytammik

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

Message 4 of 21
markjvlampad
in reply to: markjvlampad

my objective in doing that is to select multiple elements, get and sets their parameters.

 

 

Message 5 of 21
jeremytammik
in reply to: markjvlampad

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

 

 



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

Message 6 of 21

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.


¯\_(ツ)_/¯
Let it work like a charm.

Mustafa Salaheldin


EESignature




Digital Integration Manager, DuPod

Facebook | Twitter | LinkedIn

Message 7 of 21

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

 

Message 8 of 21
jeremytammik
in reply to: AH_Yafim

Please search this discussion forum for "Python arguments" and you will find an answer already there:

 

https://forums.autodesk.com/t5/revit-api-forum/quot-setstructuralasset-quot-needs-2-arguments/m-p/76...

 

This should explain in full.

 



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

Message 9 of 21

Actually this method has different overloads. You have to define for Python which one to use.


¯\_(ツ)_/¯
Let it work like a charm.

Mustafa Salaheldin


EESignature




Digital Integration Manager, DuPod

Facebook | Twitter | LinkedIn

Message 10 of 21

@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.

 

@Mustafa.Salaheldin 

Okay, but if we take the line:

pickedGrids = Selection.PickElementsByRectangle("Pick Grids")

 

which is the string overload, then still the error appears:

TypeError: expected Selection, got str
 
Message 11 of 21

Yes even though, you have to specify which overload.


¯\_(ツ)_/¯
Let it work like a charm.

Mustafa Salaheldin


EESignature




Digital Integration Manager, DuPod

Facebook | Twitter | LinkedIn

Message 12 of 21

@Mustafa.Salaheldin 

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...?

Message 13 of 21

@AH_Yafim 

 

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.

 


¯\_(ツ)_/¯
Let it work like a charm.

Mustafa Salaheldin


EESignature




Digital Integration Manager, DuPod

Facebook | Twitter | LinkedIn

Message 14 of 21

@Mustafa.Salaheldin 

I think you're using C# syntax ..?

Using the .Overloads[] gives an error of:

 

AttributeError: 'method_descriptor' object has no attribute 'Overloads'
 
From checking this error online, I think I might be missing some imports.
Could that be the case?
My imports are:
 
from Autodesk.Revit.DB import *
from Autodesk.Revit.UI.Selection import *
from Autodesk.Revit.UI import TaskDialog
from Autodesk.Revit.DB import Transaction
 
 
Message 15 of 21

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.

 


¯\_(ツ)_/¯
Let it work like a charm.

Mustafa Salaheldin


EESignature




Digital Integration Manager, DuPod

Facebook | Twitter | LinkedIn

Message 16 of 21

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.

Message 17 of 21

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.

 


¯\_(ツ)_/¯
Let it work like a charm.

Mustafa Salaheldin


EESignature




Digital Integration Manager, DuPod

Facebook | Twitter | LinkedIn

Message 18 of 21
greg7KTAR
in reply to: jeremytammik

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.

Message 19 of 21
jeremy_tammik
in reply to: greg7KTAR

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

  

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
Message 20 of 21
greg7KTAR
in reply to: jeremy_tammik

Jeremy:

I appreciate your response, first and foremost. I can understand in your position you are on an island and put in a position to try to answer all things on behalf of Autodesk as well as defend the API inherently through your replies, because that is the position you are put in.

At the same time, the task in front of Autodesk in managing an innovation ecosystem is a large one.

With that having been said, my response echoes frustration not just from a single post, but from the process as a whole. Something worth keeping in mind is that there are a number of experts in specific fields within construction, of which I consider myself to be one, who at the same time have varying levels of experience in programming as a whole and certainly of the many platforms out there. In order to move the industry forward, we must all except that everyone’s entry point is different. I for one was a co-founder of TSI, and have been involved from an executive standpoint for 15-20 years in software development, though my actual personal programming experience amounts to about 5 years. My experience, relatively new, in PHP, HTML, Java, is about two years. My experience in SQL closer to 10, and my experience in C# and the Revit API is going on a few months now.

I have reviewed the SDK, but that doesn’t mean I have completed every exercise in it. There are also other sources that I have found more helpful, and while learning, I am also developing my application (Revit API part, other is online and being developed as well), for Analytics.

I think it is fair to say, that the data structure, and access to information in the API is lacking everything everyone wants or might expect. This makes development in this environment risky and costly, though potential rewarding if through difficulty one can provide a result others have not yet done.

I’d just like to ask that the tone of, and nature of responses is respectful or all of the work people might be putting in at the point at which they are posting a question or response, without referring to the scoreboard and comparing all the other possible experience that others might have. There is no doubt you are the leading expert in this niche. We all need your help, and that makes it hard for you. I can see others are trying to help as well. I only hope the tone moving forward for all of us can be inquisitive, interested and curious, as well as supportive of the innovations and challenges we all face trying to get there.

Regards,
Greg

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Forma Design Contest


Rail Community