Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sample Revit async #5

Open
grizoood opened this issue Jul 7, 2022 · 1 comment
Open

Sample Revit async #5

grizoood opened this issue Jul 7, 2022 · 1 comment

Comments

@grizoood
Copy link

grizoood commented Jul 7, 2022

Hello,

Your framework looks great, but I'm stuck on how to implement an external event asynchronously. Could you provide an example please.

Another question is it possible to pass parameters to the external event and have an object in return?

A bit like this: https://github.com/KennanChan/Revit.Async

@Coolicky
Copy link

Coolicky commented Jul 7, 2022

Hi,

There is a Revit Event handler similar to Revt.Async here

https://github.com/engthiago/Onboxframework/blob/master/src/Revit/Async/IRevitEventHandler.cs

Just register it into container

container.AddRevitAsync(asyncSettings);
public class SampleClass
{
	private readonly IRevitEventHandler _eventHandler;

	public SampleClass(IRevitEventHandler eventHandler)
	{
		_eventHandler = eventHandler;
	}
}

And use it like below.

// With return value
public async Task<T> GetSomethingFromRevit
{
	var returnValue = await _eventHandler.RunAsync(uiApp =>
	{
		// Access Revit Application Classes as such
		var doc = uiApp.ActiveUIDocument.Document;

		return something;
	});
}

// As void
public async Task DoSomethingInRevit
{
	await _eventHandler.RunAsync(uiApp =>
	{
		// Access Revit Application Classes as such
		var doc = uiApp.ActiveUIDocument.Document;
		
		// Your Logic Here
	}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants