Revit API: 'Hidden' methods? - revitpythonshell

While using Revit API and browsing the "RevitAPI.chm" file (and browsing examples on the internet), I have noticed that some methods exist while not being listed neither in the "RevitAPI.chm" file nor suggested when using RevitPythonShell.
I explain. Let's say for instance that I have a "Space" Object, obtained with
s = FilteredElementCollector(doc).OfClass(SpatialElement).ToElements()
If I do, let's say (assuming s[0] is a valid Space object):
s[0].Geometry
I got an 'indexer object':
<indexer# object at 0x0000000000000049>
But if I do:
s[0].get_Geometry(Options())
Then I got my GeometryElement object. The same behavior goes with get_BoundingBox, for instance.
Now, that's fine, but the only way I could know about these get_something methods is by seeing examples (either on the "RevitAPI.chm", or on forums etc.). So that's kind of strange, isn't it? In the sense that these methods aren't actually listed.
So I guess my questions would be:
Is it the normal behavior? (or should I normally just get a GeometryElement object by using s[0].Geometry, for instance?)
If yes, ... why ? :D
What are these 'indexers' ?
Thanks!
Arnaud.
PS: Using Revit 2017, tests made with RevitPythonShell and pyRevit

The methods prefixed by a lowercase get_ are automatically generated getter methods. The official Revit API provides and documents the BoundingBox property on the Element class. Rather inelegantly, this so-called property takes an argument. Therefore, the C# .NET implementation generates a property getter function for it.

Related

How to convert byte[] to ObjectParameter in ASP.net

I have a byte[] and wanna convert it to object parameter in asp.net.
byte[] version =98471574580;
and I have One method that wants "ObjectParametere version".I must convert byte[] version to
ObjectParametere.
The way to do this has a few steps that if you follow in future shoudl save you needing to ask this sort of question again.
1) Look at the documentation for the class you want to use. It is found here: http://msdn.microsoft.com/en-us/library/system.data.objects.objectparameter(v=vs.110).aspx googleing for "ObjectParameter" returns it as top hit for me. Google might have noticed me doing a lot of MSDN searches though and bumping them to the top so if in doubt try adding MSDN or c# to the search.
2) Look for how to create an instance of the object. This would usually be through constructors. Sometimes you may use static methods but constructors are usual and in fact there are two here we can consider.
3) Decide which constructor to use. One takes a name and a type. One takes a name and a value. Since we have a value this seems like the one to choose.
4) Call the constructor you have decided to use and assign it to a variable (or use it directly in your code). In this case the syntax would be var objParam = new ObjectParameter("version", version);.
Some of these steps might be short circuited. For example if you are programming in Visual Studio then typing new ObjectParameter( should then offer intellisense help on what constructors are available, saving the need to look the documentation up online.

Understanding some code

I have an application which was built a few years ago. I came across a section of code that baffled me as the functionality this provides throughout the ASP .Net application is great but i just dont understand it. Perhaps its the [] throwing me off but i think it could be some C# code converted to VB .Net.... Not sure but wondered if anyone understands this and if so could they share what its doing
The code in an NotInheritable class
Public Overloads Function [Get](Of B)() As B
Dim myType = GetType(B)
Return DirectCast([Get](myType), B)
End Function
I understand it overloads a function but
Why are the [] there for and what do they mean? When would you use them? If i remove them i have a compiler error.
Get in VB .Net is used in properties so is this some shortcut access to a property somewhere? Or
where could i view which method its overloading?
I've used code similar to List(Of Customer), IQueryable(of Customer) but how has (Of B) allowed in this manner?
I have read up on MSDN and researched around. The only thing that comes to mind is either some C# syntax conversion or some old VB6 syntax which the original developer must have used whilst creating the application.
Appreciate any clarification on this.
Because Get is part of Visual Basic Language Keywords. You need the bracket to indicate you want to use them as a method/property name.
Here is an excerpt from Microsoft on Keywords as Element Names in Code (Visual Basic):
Any program element — such as a variable, class, or member — can have
the same name as a restricted keyword. For example, you can create a
variable named Loop. However, to refer to your version of it — which
has the same name as the restricted Loop keyword — you must either
precede it with a full qualification string or enclose it in square
brackets ([ ]), as the following example shows.
1) Brackets allow you to use reserved words as identifiers (like the ampersand in c#).
2) It appears to be a bad naming decision. If they wanted to hide an existing member they could have used the Shadows keyword.
3) You'll need to examine the inheritance hierarchy. Start with the most recent parent.
4) It is calling a different overload of Get in the implementation but the Of B is trying to contrain it to B for some reason.

Set HttpContext.Current.Request.Browser.Type in ASP.NET

Is there a way to set HttpContext.Current.Request.Browser.Type in ASP.NET. That is a read-only, string property. So you cannot really just assign a string to it. Tried initializing Browser property which is of type HttpBrowserCapabilities, but it has only one constructor and does not take any parameters and browser Type is still null. The reason why I want to be able to set Type for browser is that my unit test is failing as Type property is null.
Edit per null check comments:
I could definitely modify code to check for null, but that will be just for my unit test as when the requests come from browsers, that value is never null. Hence not quite excited about doing that. But it can be my last resort.
You can define your own browser definition files which ASP.net will then use. Check out http://forums.asp.net/p/955969/1176101.aspx.
So if you know what browser it's failing on you could setup a browser file for it. However, I agree that checking for null values makes more sense as it accounts for a lot more possiblities that way.
You might want to think about refactoring your code to use HttpContextBase instead of relying directly on the concrete type.
By doing so you could simply create a stub object that provides the behavior you want. Eventually implementing your own HttpBrowserCapabilitiesBase object.
You would then have full control to use your mock types during unit testing. Indeed that is what they were created for.

DataService.commitRequiredOn() recursive check?

We're using LCDS and the "commitRequiredOn" method in the DataService class to check if there are pending changes for an entity. However, it seems like "commitRequiredOn" does not check the complete graph of an object, but just the object itself. For now, we have implemented a recursive check on the complete object graph, but this seems like functionality that should come out of the box.
Am I missing something here, or is there just no built-in way to recursively check an entity to see if it's dirty or not?
I can confirm that commitRequiredOn is checking only the objects itself. But there is also the property DataService.commitRequired (and this is checking for all the objects managed by the dataservice) - maybe you can use it.

Why does Flex's ArrayCollection's Contain method look at memory reference?

When using .contains() on an ArrayCollection in Flex, it will always look at the memory reference. It does not appear to look at an .equals() method or .toString() method or anything overridable. Instead, I need to loop through the ArrayCollection every time and check each individual item until I find what I'm looking for.
Does anyone know why Flex/ActionScript was made this way? Why not provide a way from people to use the contains() method the way they want?
Couldn't you just extend ArrayCollection and override the contains() method? Alternatively you can paste the source for ArrayCollection into an "mx/collections" package in your project and modify the source; this "monkey-patching technique" will override the behavior throughout your entire project. However I would be extremely cautious about changing ArrayCollection in that manner: since it's used all over the place in the Flex APIs there is a good chance you'll start breaking other components in the framework.
The contains() method searches by reference, correct (I believe even for primitives), so if you're trying to find a string or an int in an ArrayCollection, you'll have to do the searching yourself, by some variation of looping or searching. I don't think any of us could tell you why there isn't, say, an optional parameter on that method indicating whether to search by ref or by val, though; so it goes, as they say.
But I'd definitely warn you off monkey-patching the framework code -- that's just asking for trouble. :)
Well, it seems like the ArrayCollection doesn't actually look directly at memory, but only as a last resort. It will attempt to find a Unique ID (UID) for the object. If the UID doesn't exist, it will create one for it using the UIDUtil.as.
You can get around this whole default UID stuff by having your object implement the IUID interface and providing your own UID for the object. The ArrayCollection will look at the UID you provide it.
I would suggest a simple:
in_array($haystack, $arrayCollection->toArray());

Resources