This repository has been archived by the owner on Aug 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 34
/
CreateSvfAutomation.cs
111 lines (98 loc) · 4.49 KB
/
CreateSvfAutomation.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/////////////////////////////////////////////////////////////////////
// Copyright (c) Autodesk, Inc. All rights reserved
// Written by Forge Partner Development
//
// Permission to use, copy, modify, and distribute this software in
// object code form for any purpose and without fee is hereby granted,
// provided that the above copyright notice appears in all copies and
// that both that copyright notice and the limited warranty and
// restricted rights notice below appear in all supporting
// documentation.
//
// AUTODESK PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS.
// AUTODESK SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF
// MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE. AUTODESK, INC.
// DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE
// UNINTERRUPTED OR ERROR FREE.
/////////////////////////////////////////////////////////////////////
using System;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using Autodesk.Forge.DesignAutomation.Inventor.Utils;
using Inventor;
using Path = System.IO.Path;
using File = System.IO.File;
using Shared;
namespace CreateSVFPlugin
{
[ComVisible(true)]
public class CreateSvfAutomation : AutomationBase
{
public CreateSvfAutomation(InventorServer inventorApp) : base(inventorApp)
{
}
public override void ExecWithArguments(Document doc, NameValueMap map)
{
LogTrace("Processing " + doc.FullFileName);
try
{
SaveAsSVF(doc);
}
catch (Exception e)
{
LogError("Processing failed. " + e.ToString());
}
}
private void SaveAsSVF(Document Doc)
{
using (new HeartBeat())
{
LogTrace("** Saving SVF");
try
{
ApplicationAddIn svfAddin = _inventorApplication
.ApplicationAddIns
.Cast<ApplicationAddIn>()
.FirstOrDefault(item => item.ClassIdString == "{C200B99B-B7DD-4114-A5E9-6557AB5ED8EC}");
var oAddin = (TranslatorAddIn)svfAddin;
if (oAddin != null)
{
Trace.TraceInformation("SVF Translator addin is available");
TranslationContext oContext = _inventorApplication.TransientObjects.CreateTranslationContext();
// Setting context type
oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism;
NameValueMap oOptions = _inventorApplication.TransientObjects.CreateNameValueMap();
// Create data medium;
DataMedium oData = _inventorApplication.TransientObjects.CreateDataMedium();
Trace.TraceInformation("SVF save");
var sessionDir = Path.Combine(Directory.GetCurrentDirectory(), "SvfOutput");
oData.FileName = Path.Combine(sessionDir, "result.collaboration");
var outputDir = Path.Combine(sessionDir, "output");
var bubbleFileOriginal = Path.Combine(outputDir, "bubble.json");
var bubbleFileNew = Path.Combine(sessionDir, "bubble.json");
// Setup SVF options
if (oAddin.get_HasSaveCopyAsOptions(Doc, oContext, oOptions))
{
oOptions.set_Value("GeometryType", 1);
oOptions.set_Value("EnableExpressTranslation", false);
oOptions.set_Value("SVFFileOutputDir", sessionDir);
oOptions.set_Value("ExportFileProperties", true);
oOptions.set_Value("ObfuscateLabels", false);
}
LogTrace($"SVF files are output to: {oOptions.get_Value("SVFFileOutputDir")}");
oAddin.SaveCopyAs(Doc, oContext, oOptions, oData);
Trace.TraceInformation("SVF can be exported.");
LogTrace($"** Saved SVF as {oData.FileName}");
File.Move(bubbleFileOriginal, bubbleFileNew);
}
}
catch (Exception e)
{
LogError($"********Export to format SVF failed: {e.Message}");
}
}
}
}
}