Revit API: Maintaining a code for multiple API versions - revit-api

I have some Revit add-ins that are written for Revit 2019 or the versions below. Now I'm trying to upgrade the tools for Revit 2020, but it seems like there are some significant changes in API methods. Fortunately, some of them are backward compatible so I can just update the code with new API methods and use it for Revit 2020 and 2019. However, some of them only works for Revit 2020. (ex) ImageInstance.Create(Document, View, ElementId, ImagePlacementOptions)
In this case, what would be the best way to keep the same code base compatible with different Revit versions? I can easily imagine using If Statement to determine a proper API method for each Revit version, but it doesn't seem ideal for the maintenance of the tool.
Any advice would be appreciated!

Ive been writing and managing Addins since Revit version 2015 and use if statements to make sure things are backwards compatible. They havent gotten too out of control yet...
Its worth writing a small function to return the Revit version as a string for your if statement:
def revitVersion(): # returns '2020'
return app.VersionName[-4:]
You can also put lists together to help check for functionality:
revitsWithoutBIM360 = ['2015', '2016', '2017', '2018']
if revitVersion() in revitsWithoutBIM360:
print 'This version or Revit can't access BIM360 projects'
else:
# your code here
Might not be the most elegant way to handle it, but works for me.

Related

Should Word Online support inserting text into a content control via ContentControl.insertText?

I am developing a Word add-in with Office.js that utilizes ContentControl.insertText. According to the documentation, this method is provided by WordApi requirement set 1.1, which is supported in Office Online. Furthermore, the documentation for ContentControls lists Office Online as being supported and does not mention any exceptions when it comes to using that particular method.
That said, when I run the add-in in native Word 2016, everything works fine, but when I run it in the Word Online environment, it fails with the following exception:
code:"NotAllowed"
errorLocation:"ContentControl.insertText"
message:"The action isn’t supported in Word Online. Check the OfficeExtension.Error.debugInfo for more information."
For reference, I am using it like so:
control.insertText(heading.Text, 'Replace');
I also tried running the example provided in the documentation, with the same results: it works in Word 2016, but fails with the above exception in Word Online.
Has anyone been able to successfully insert text into a ContentControl in the Office Online environment? If not, are there plans for this functionality to be supported?
Any input or clarification would be most appreciated! Thanks!
I'm an engineer from MS. There are some cases which contentControl.insertText is not allowed.
I think the cause of your case is that there is more than one paragraphs in the heading.text and you try to insert heading.text into a inline content control.
The inline content control means that the content control just some part of a paragraph.
In order to make sure the root cause of your scenario, could you share me the doc and the script code.

Office-js doesn't display the properties

I was trying to repro a tutorial about the creation of an Excel Add-in when something get wrong with the IntelliSense of Visual Studio. I was writing this code:
function updateStocks() {
Excel.run(function (ctx) {
var **range** = ctx.workbook.names.getItem("Stocks")
At this step, everything was fine, but after the getItem, I have tried to add .getRange() at which point the IntelliSense was not able to understand anything related to my variable range.
Screenshot
What is really "funny" is the fact that even if the properties are not displayed, when I write the code of the tutorial manually, the code is executed without mistake.
Why does this behavior occur and how can I correct it?
Are you able to see IntelliSense for other types within that .run? I.e., do you have everything up to the point where you get a Range from a named item? If you were to obtain the range differently (e.g., context.workbook.getSelectedRange()), do you get IntelliSense then?
This might be related to an issue (now fixed) where the CDN accidentally had the namedItem.getRange method removed (it was the only one that was affected, and we've put in measures to ensure we catch those in the future). See "Can't get range from a defined name". The CDN has been patched a couple weeks ago, but the JS IntelliSense file ("VSDOC") probably hadn't. If that's the case, it's a point-in-time issue that should resolve itself very very soon, as new deployments of the CDN will have the getRange method both in the VSDOC and everywhere else.
FWIW, you may still run into limitations of the JS IntelliSense engine (there are plenty, unfortunately: for example, trying to pass values across Promises, or passing in API objects as parameters to functions). The only true good workaround for this is using TypeScript, which allows you to declaratively assert to the compiler/IntelliSense-engine that "I know this type is an Excel.Range!") -- and offers a number of other goodies, async/await being a very major one. I personally believe that if you really want a "premier" Office.js-coding experience, TypeScript is the way to go. To that end, I describe how to use TypeScript in my book, "Building Office Add-ins using Office.js" (full disclosure, I am the author; but I've had many readers comment on how helpful of a resource it's been to them). The book is very much TypeScript-oriented, IntelliSense being one of the reasons (and async/await and let being the primary others) -- though I also offer an Appendix where I describe the JavaScript-only way of accomplishing the same Office.js tasks. It takes only a small amount of effort to get started with using TypeScript, and once you do, I don't think you'll look back.

User Defined Function by JavaScript API for Excel

I have a library of functions written in JavaScript, for example myfactorial(n) can caculate the factorial of n in my way.
I would hope to develop an add-in by JavaScript API for Excel, such that once a user loads the add-in, they could use the embedded functions, e.g., write in a formula: =myfactorial(A2) or =callfunction("myfactorial", A2). In short, it is about supporting User Defined Functions by JavaScript API for Excel, I guess they are asking the same thing here.
So, does any know how is the progress? Otherwise, is there some workaround that we could do?
Thanks for this question! User-defined functions are a central part of Excel customization today. We're working on a solution that will bring those capabilities across all our modern Excel platforms. We're still figuring out the design, so unfortunately I don't have a timeline or details to share right now. I'll give an update in a few months.
-Michael, PM for Office add-ins
Update 11/6/17: JavaScript custom functions in Excel are now available in Developer Preview for anyone to try: https://aka.ms/customfunctions

How to get Hyperion Smart View For Office Version add-in?

Can you get the version of Hyperion SmartView installed using visual basic code for excel ?
I need to get a string output with the version number or something that looks like this -> 11.1.2.2.000
regards
The Smart View for Office Developer's Guide explains the use of HypGetVersion() on Page 44. It will, among other things, return the version.

Comparison sheet for switch to Orion

I can't find a resource that clarifies the programming differences between Polaris and Orion versions. I've been googling for a few days now.
Probably you already read this article written by Jukka Niiranen
The Next Dynamics CRM User Experience: Orion
I think Gemini release will bring (at least) the possibility to use Xrm javascript with the new forms (actually is really a shame to don't be able to pre-fill a field or to do some show/hide logic) and provide the xml definition that will replace the ribbon.
I'm not sure if there is such a document yet. Before we start with Orion, we have to pass Gemini, first. And given the inconsistency between road maps and reality this far, it could as well be that Orion will be known as CRM-2014.

Resources