使用 API v3 和 .Net 将 DWG 转换为 DXF
Convert DWG to DXF using API v3 and .Net
我的要求是将 DWG 转换为 DXF,需要快速帮助以了解使用 Design API v3 和 .net c# 的过程,并且我想使用本地计算机中的所有 DWG 文件并且输出也应该发生本地。任何地方都没有参考,我对设计自动化完全陌生 API。
`
var workItemStatus = await api.CreateWorkItemAsync(new WorkItem()
{
ActivityId = myActivity,
Arguments = new Dictionary<string, IArgument>()
{
{ "input", new XrefTreeArgument() { Url = UploadUrl } },
{ "params", new XrefTreeArgument() { Url = $"data:application/json, {JsonConvert.SerializeObject(new CrxApp.Parameters { ExtractBlockNames = true, ExtractLayerNames = true })}" } },
{ "result", new XrefTreeArgument() { Verb=Verb.Put, Url = DownloadUrl } }
}
});
`
Also want to understand the params to convert from DWG to DXF, I have
no AutoCad installed. Ex. "params", new XrefTreeArgument()
- 发送绘图输入url
DXFOUT
- 发送 dxf 输出 url。
.NET 核心中的示例 Activity 规范
private async Task<string> SetupActivityAsync(string myApp = null)
{
Console.WriteLine("Setting up activity...");
var myActivity = $"{Owner}.{ActivityName}+{Label}";
var actResponse = await this.api.ActivitiesApi.GetActivityAsync(myActivity, throwOnError: false);
/*
* The default or basic CommandLine syntax, for this application we don't need bundle.
* CommandLine = new List<string>()
{
$"$(engine.path)\accoreconsole.exe /i $(args[inputFile].path) /al $(appbundles[{PackageName}].path) /s $(settings[script].path)"
},
*/
var activity = new Activity()
{
CommandLine = new List<string>()
{
$"$(engine.path)\accoreconsole.exe /i $(args[inputFile].path) /s $(settings[script].path)"
},
Engine = TargetEngine,
Settings = new Dictionary<string, ISetting>()
{
{ "script", new StringSetting() { Value = "DXFOUT\nresult.dxf\n\n" } }
},
Parameters = new Dictionary<string, Parameter>()
{
{ "inputFile", new Parameter() { Verb= Verb.Get, LocalName = "$(HostDwg)", Required = true } },
{ "outputFile", new Parameter() { Verb= Verb.Put, LocalName = "result.dxf", Required= true} }
},
Id = ActivityName
};
if(myApp != null)
{
activity.Appbundles = new List<string>()
{
myApp
};
}
if (actResponse.HttpResponse.StatusCode == HttpStatusCode.NotFound)
{
Console.WriteLine($"Creating activity {myActivity}...");
await api.CreateActivityAsync(activity, Label);
return myActivity;
}
await actResponse.HttpResponse.EnsureSuccessStatusCodeAsync();
Console.WriteLine("\tFound existing activity...");
if (!Equals(activity, actResponse.Content))
{
Console.WriteLine($"\tUpdating activity {myActivity}...");
await api.UpdateActivityAsync(activity, Label);
}
return myActivity;
}
我的要求是将 DWG 转换为 DXF,需要快速帮助以了解使用 Design API v3 和 .net c# 的过程,并且我想使用本地计算机中的所有 DWG 文件并且输出也应该发生本地。任何地方都没有参考,我对设计自动化完全陌生 API。
`
var workItemStatus = await api.CreateWorkItemAsync(new WorkItem()
{
ActivityId = myActivity,
Arguments = new Dictionary<string, IArgument>()
{
{ "input", new XrefTreeArgument() { Url = UploadUrl } },
{ "params", new XrefTreeArgument() { Url = $"data:application/json, {JsonConvert.SerializeObject(new CrxApp.Parameters { ExtractBlockNames = true, ExtractLayerNames = true })}" } },
{ "result", new XrefTreeArgument() { Verb=Verb.Put, Url = DownloadUrl } }
}
});
`
Also want to understand the params to convert from DWG to DXF, I have no AutoCad installed. Ex. "params", new XrefTreeArgument()
- 发送绘图输入url
DXFOUT
- 发送 dxf 输出 url。
.NET 核心中的示例 Activity 规范
private async Task<string> SetupActivityAsync(string myApp = null)
{
Console.WriteLine("Setting up activity...");
var myActivity = $"{Owner}.{ActivityName}+{Label}";
var actResponse = await this.api.ActivitiesApi.GetActivityAsync(myActivity, throwOnError: false);
/*
* The default or basic CommandLine syntax, for this application we don't need bundle.
* CommandLine = new List<string>()
{
$"$(engine.path)\accoreconsole.exe /i $(args[inputFile].path) /al $(appbundles[{PackageName}].path) /s $(settings[script].path)"
},
*/
var activity = new Activity()
{
CommandLine = new List<string>()
{
$"$(engine.path)\accoreconsole.exe /i $(args[inputFile].path) /s $(settings[script].path)"
},
Engine = TargetEngine,
Settings = new Dictionary<string, ISetting>()
{
{ "script", new StringSetting() { Value = "DXFOUT\nresult.dxf\n\n" } }
},
Parameters = new Dictionary<string, Parameter>()
{
{ "inputFile", new Parameter() { Verb= Verb.Get, LocalName = "$(HostDwg)", Required = true } },
{ "outputFile", new Parameter() { Verb= Verb.Put, LocalName = "result.dxf", Required= true} }
},
Id = ActivityName
};
if(myApp != null)
{
activity.Appbundles = new List<string>()
{
myApp
};
}
if (actResponse.HttpResponse.StatusCode == HttpStatusCode.NotFound)
{
Console.WriteLine($"Creating activity {myActivity}...");
await api.CreateActivityAsync(activity, Label);
return myActivity;
}
await actResponse.HttpResponse.EnsureSuccessStatusCodeAsync();
Console.WriteLine("\tFound existing activity...");
if (!Equals(activity, actResponse.Content))
{
Console.WriteLine($"\tUpdating activity {myActivity}...");
await api.UpdateActivityAsync(activity, Label);
}
return myActivity;
}