Skip to content

Instantly share code, notes, and snippets.

@MadhukarMoogala
Created December 8, 2020 04:46
Show Gist options
  • Save MadhukarMoogala/5b2d49177713147da618e953182a8eb1 to your computer and use it in GitHub Desktop.
Save MadhukarMoogala/5b2d49177713147da618e953182a8eb1 to your computer and use it in GitHub Desktop.
Yet another DA tiny console application
using Autodesk.Forge.Core;
using Autodesk.Forge.DesignAutomation;
using Kurukuru;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using Serilog;
using System;
using System.Text;
using System.Threading.Tasks;
namespace ToPDF
{
class Program
{
static async Task Main(string[] args)
{
Console.OutputEncoding = Encoding.UTF8;
//Step 1: Create Configuration
/**
* SET FORGE_CLIENT_ID=<>
* SET FORGE_CLIENT_SECRET=<>
*/
var config = new ConfigurationBuilder()
.AddForgeAlternativeEnvironmentVariables()
.Build();
var logger = new LoggerConfiguration()
.WriteTo.Console()
.CreateLogger();
//Step 2: Populate Forge Design Automation service,
//get Design Automation API Client
var Api = new ServiceCollection()
.AddLogging(builder => {
builder.SetMinimumLevel(LogLevel.Information);
builder.AddSerilog(logger, dispose: true);
})
.AddDesignAutomation(config)
.Services
.BuildServiceProvider()
.GetRequiredService<DesignAutomationClient>();
//Step 3: Fetch the Activity Specification by calling GetActivityAsync
var activity = await Api.GetActivityAsync("AutoCAD.PlotToPDF+prod");
logger.Information($"\n\t{JsonConvert.SerializeObject(activity, Formatting.Indented)}");
var engines = await Api.GetEnginesAsync();
logger.Information($"\n\t{JsonConvert.SerializeObject(engines, Formatting.Indented)}");
}
}
}
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Autodesk.Forge" Version="1.7.0" />
<PackageReference Include="Autodesk.Forge.DesignAutomation" Version="3.0.3" />
<PackageReference Include="Kurukuru" Version="1.1.0" />
<PackageReference Include="Microsoft.Extensions.CommandLineUtils" Version="1.1.1" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="3.1.8" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="3.1.8" />
<PackageReference Include="Serilog.Extensions.Logging" Version="3.0.1" />
<PackageReference Include="Serilog.Sinks.Console" Version="3.1.1" />
</ItemGroup>
</Project>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment