Going to go with a âteach a man to fishâ method here instead of a âhave a fishâ so that you can grow your skill set a bit (youâre ready for it).
For now skip the last line by commenting it out, and look at what you can do with the object you have.
Two ways to do this, one is more complete than the other, and one is faster to implement on the fly.
Method 1: This is faster to implement and often less error prone, but may leave you scratching your head with some bits.
OUT = dir(yourObject)
From that output you can see every method and property you can use on that object. The stuff with two underscores proceeding and following it are worth noting specifically; these are special in that they are meant to help you work rather than providing a meaningful final output. For example, doc will give you the formal documentation for the API call (if it exists - internal and undocumented APIs wonât have this). Now you know what you can do with the object you have, so you can read the methods and properties to find something which looks appealing. Not as useful as just knowing what to do as some objects have hundreds or even thousands of calls, and some methods and properties require specialist knowledge to know how to use them; but this is still insanely useful as a tool.
Method 2: This returns more complete results, but can fail in some instances (in particular with some APIs that return complex data via reflection).
import inspect
OUT = inspect.getmembers(yourObject)
From that output you get not just the data about what you can do, but the documentation of each property and method. Basically youâre outputting the full set of data as you might see on RevitAPI docs. There are other good uses for inspect (getting the class and the class tree), so itâs useful to know if youâre not able to write the help docs by memory for the library and modules youâre using. This geeks for geeks article can help learn what you can do with it: Inspect Module in Python - GeeksforGeeks
Look those methods over and see if there is something that you can work with to get the Name of what youâre working with.
Iâm a beginner fisher and I have to learn tips and tricks to be a big fisher like you
In fact, I knew the use of the commands OUT = dir(object) and OUT = object.__doc__ which allows exploring propreties of ojects and methods for Revit nodes, but I dont knew that their uses can extend also to API.
1- Iâm working with IronPython2 engine, and I noticed that the get_Name method not existing there opposite of CPython3 where there are more methods??..in this case should I use CPython3 to be able to use this method?
2- how Should I know if the item in the dropdown list is an object proprety (attribute) or a method ?
for example, in IronPython2 if I type : OUT = bar_type.CanBeCopied.__doc__ no doc is displayed, but if I type OUT = bar_type.Create.__doc__ I get the doc?
how do you know that the name is obtained by get_Name method compared to its proprety in the line 88?
4- No way to get the RebarBarType name using AsString method in Revit API ?
Thanks.
Hello, in fact it was a question (I had forgotten the?), not an affirmation (not yet competent enough to claim things)
did you see the OUT[2] line of the displayed python script?
cordially
christian.stan
Wasnât the goal of the topic the string transformation of RebarBarType?
So solved here (as itâs orange color [string] the super cool thing of Dynamo>2.16, I canât live without it, too too good idea of ââI donât know who)
no, NameT out[0,1,2]
script:
May be that the Name property will work as is; the get_ methods (and set_ methods) are added wrappers to help with conversion. I do recommend writing in the CPython engine or IronPython3 whenever possible, as itâll help with forward compatibility.
Trial and error, or look it up in the official documentation, or via RevitAPIDocs.com. I usually assume a property as a first step, and if that fails move on to a method with no overloads (empty parenthesis).
No, because you havenât accessed the name, only the object.
Here is a solution under IronPython2 (with transform to node dynamo) (itâs not mine, you can imagine, look at this topic explanations by Mr. Poupin and Solution by Mr. Brendan Cassidy)