Hello everyone,
I would like to create a plugin that reads data directly from a url. Currently I'm using Postman with the url to extract the data in an excel or json file:
I wonder if it's possible to skip this passage and do it directly from Revit API.
I've never done anything like that and I'm asking your help to find some guide online with the passages to follow.
Thank you very much,
Letizia
Solved! Go to Solution.
Solved by ricaun. Go to Solution.
Solved by Kevin.Lawson.PE. Go to Solution.
Yes, this is definitely possible, although should not think of it in terms of the Revit API. This will be a sidecare project that works alongside the Revit API. I like Selenium for these tasks. Get Selenium.WebDriver, NotNetSeleniumExtras.WaitHelpers, and Selenium.WebDriver.ChromeDriver (or whatever browser you prefer) from Nuget. Then in your class call something like this:
IWebDriver driver = new ChromeDriver();
//Open webpage.
driver.Navigate().GoToUrl("example");
var wait = new WebDriverWait(driver, TimeSpan.FromSeconds(600)); //wait 10 minutes if necessary
var element = wait.Until(SeleniumExtras.WaitHelpers.ExpectedConditions.ElementIsVisible((By.CssSelector("tbody td:nth-child(2)")))); //wait until whatever data you want is visible.
var bhpTRs = driver.FindElements(By.CssSelector("tr[data-fieldname='total brake horsepower']"));//get data
To read data from url you could use System.Net.WebClient.
Something like this.
public string GetString(string address)
{
using (var client = new System.Net.WebClient())
{
return client.DownloadString(address);
}
}
See yaa
Thank you @Kevin.Lawson.PE and @ricaun, still had no time to test it, I'll write my breakthrough here as soon as I have the chance.
Can't find what you're looking for? Ask the community or share your knowledge.