I spent Monday evening at the interesting meetup workshop on functional programming in JavaScript led by basel.js meetup group regular Lukasz Gintowt.
All available seats were taken with 20 participants.
Follow the link above to get to all the interesting material we looked at.
It reminded me somewhat of the early days of AutoCAD programming, where the more elegant AutoLISP solutions tended towards functional programming... Remember car, cdr, mapcar, apply and lambda?
Basically, that is part of what we talked about.
Look up Haskell Brooks Curry, mathematician and logician, with three programming languages named after him, Haskell, Brooks and Curry, as well as the concept of currying, a technique used for transforming functions in mathematics and computer science.
We went through a number of cool hand-on JavaScript exercises listed in Lukasz' slides.
Here are some of the additional notes I took:
- A highly recommended JavaScript book: You Don't Know JS.
- Underscore is an interesting and well-known JavaScript library providing functional programming helpers. Lo-dash is similar and better in some respects.
- Idempotency is recommended for all REST call implementations, i.e., repeated calls to the same REST URL should return the same consistent result. For instance, if a first call to a URL ending in /delete/id returns the response 'deleted' or 'OK', i.e. 200, then all the further calls to the same URL should return the same value. Many implementations return something different, e.g. 'not found' on the second and all following calls. That is wrong; they should also return deleted or OK, or the idempotency will be violated.
Cool View and Data API Demos
David In't Veld posted a comment on the View and Data API notes and samples asking for some simple demos:
Question: Is there any 'Demo' webpage to show-off what this View API can do?
It's a pity there are almost zero sample projects in an actually working Internet environment. I thought by now this would have been set up. Because clearly there has been a lot of work been put into this... The website developer.autodesk.com simply points to GitHub but those samples require some study to make them work... even images on the Autodesk website are not working API but simple images.
Our company is investing in new ways of showing our Revit models, and I suggested the View API, however since I could not show any impressive working model. I cannot convince anyone to invest in this...
Probably not the best place to mention this, but its frustrating every time I see View API in the title. Would like to see more demo pages...
Answer: The best place to ask for more appropriate samples is in the dedicated Autodesk View and Data API discussion forum: Autodesk Community –> Web Services API –> View and Data API discussion forum.
I would suggest submitting this comment there as well and see what the team has to say.
Here is a bunch of publicly accessible demo pages that will hopefully help fulfil your need, partially equipped with source code on GitHub to look at as well:
- gallery.autodesk.io
- mountcomp-stg.autodesk.io – github.com/Developer-Autodesk/client-mountsimulation-view.and.data.api
- timeliner.autodesk.io – github.com/Developer-Autodesk/client-timeliner-view.and.data.api
- octoviewer.autodesk.io
- checkoutmymodel.autodesk.io – github.com/Developer-Autodesk/workflow-aspnet-webform-view.and.data.api
- sapdemo.autodesk.io – github.com/Developer-Autodesk/integration-sap-view.and.data.api
- viewer.autodesk.io/bingmapintegration/
- Steampunk – autode.sk/m3w
- Tractor – s3.amazonaws.com/FastViewer/index.html?file=frontloader/0.svf
- Office – s3.amazonaws.com/FastViewer/index.html?file=Waltham/0.svf
- Blog – adndevblog.typepad.com/cloud_and_mobile/stephens-test-page.html
By the way, I looked at David's web site and really like the photos.
Another example of combining photography and Revit API programming, just like my colleague Jaime.
Hey Jeremy,
Thanks for providing these helpful links, and for having a look at my webpage!
I'm definitely going to play a bit with this View API, as soon as I finish my Revit addin...(I'm not such a multitasker as you are I suppose..)
Thanks again for all the good work.
Posted by: David In't Veld | November 06, 2014 at 04:38
Dear David,
My pleasure entirely, and best of luck to you exploring the view and data API!
Come to one of the upcoming DevDays conferences to see much more of it live!
Cheers, Jeremy.
Posted by: Jeremy Tammik | November 06, 2014 at 05:02
Hi Jeremy,
I am new to this blog and new to Revit API (SDK 2015), still not really knowing what I am doing and struggling through the examples here and in other places.
There are lots of useful examples and many of them are based on using "ElementSet". so I create an element set, like "ElementSet elems = selection.Elements;" Then I get a message saying "don't use selection.elements, it's deprecated, use GetElementIds() instead." Of course I want to be a good guy, so I use "GetElementIds()", only to find out that this does not work for "ElementSet".
Okay, so I abandon "ElementSet" and use "ICollectionelems" which is (grammatically) fine -> no compiler errors. But now I have a Icollection and all the loads of code which I had found in the web so far do not work for me any more, as they were based on "ElementSet".
So here are my questions: is there a way to cast/convert "ICollection" to "ElementSet"? Am I the first one to come across this problem? What would be the professional approach to deal with this ?
Many thanks for you advice...
Posted by: fimo | November 06, 2014 at 09:13
Dear Fimo,
Thank you for a very valid question.
ElementSet is obsolete in Revit 2015, just as the message tells you. The main change is this one, I guess:
http://thebuildingcoder.typepad.com/blog/2014/04/whats-new-in-the-revit-2015-api.html#2.10
However, as long as it has not been removed, you can still use it and ignore the warning.
All new code should avoid making use of it, since it will probably no longer work (and be removed) in the next release.
In most cases, you can replace it by a collection of ElementId objects. However, its are element ids and not Element instances, so there will be some differences in usage.
That is the issue you are encountering. Basically, the old code needs to be rewritten to take the collection of ids instead of the set of elements.
The Revit API used to define quite a number of custom collections.
They are all being replaced by generic .NET collections, by and by.
Also, a number of methods are now using ElementId arguments instead of straight Element ones.
This is part of a multi-year transition.
I hope this explains.
Cheers, Jeremy.
Posted by: Jeremy Tammik | November 06, 2014 at 09:46
Typepad-HTML-E-Mail
Hi Jeremy,
thanks for your detailed response.
Yes, it does explain...
But, alas, my personal conclusion is supposed to be the following: as there are mostly old style code snippets available and I do not know how
to convert them into new style, I have to stick to the obsolete variants in order to get some results. That means I am now learning the old style. I hope Autodesk will wait a little longer before removing the old code...:-)
Anyway thanks a lot for your explanation.
Posted by: fimo | November 07, 2014 at 04:12
Dear Fimo,
Please do not jump to the wrong conclusion.
My personal conclusion from that is to learn the new style and convert to old snippets to the new style.
The conversion is mostly trivial. Here is an example:
Look at the modification of the file DataToBim/DataToBuilding.cs:
https://github.com/jeremytammik/DataToBimCountoursAndBuildings/commit/88637e90dfa984ae424d655304e9e0a43f6b19c7
I have migrated dozens of projects on The Building Coder and often documented the migration steps in great detail.
Simply look at The Building Coder category on Migration:
http://thebuildingcoder.typepad.com/blog/migration
I hope this helps.
Cheers, Jeremy.
Posted by: Jeremy Tammik | November 07, 2014 at 04:35
Dear Fimo,
To motivate you further, and others as well, I hope, I published an edited version of our discussion:
http://thebuildingcoder.typepad.com/blog/2014/11/migrating-deprecated-api-and-2d-boolean-operations.html#3
I also did some further work myself removing compilation warnings about deprecated API usage from The Building Coder samples, to provide a perfect example to explain.
I hope this helps.
Cheers, Jeremy.
Posted by: Jeremy Tammik | November 07, 2014 at 06:50