Read data from URL with Revit API

SwainStrain
Enthusiast
Enthusiast

Read data from URL with Revit API

SwainStrain
Enthusiast
Enthusiast

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:

IMG-20220128-WA0001.jpg

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

0 Likes
Reply
Accepted solutions (2)
449 Views
3 Replies
Replies (3)

Kevin.Lawson.PE
Advocate
Advocate
Accepted 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

 

 

 

-Kevin Lawson, PE
www.rippleengineeringsoftware.com
Revit heating and cooling load calculations in one click!

ricaun
Advisor
Advisor
Accepted solution

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

Luiz Henrique Cassettari

ricaun.com - Revit API Developer

AppLoader EasyConduit WireInConduit ConduitMaterial CircuitName ElectricalUtils

SwainStrain
Enthusiast
Enthusiast

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. 

0 Likes