-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathProgram.cs
65 lines (54 loc) · 2.21 KB
/
Program.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
using System;
using System.IO;
using System.Threading.Tasks;
using Xarial.XCad.Documents;
using Xarial.XCad.Documents.Enums;
using Xarial.XCad.Documents.Structures;
using Xarial.XCad.Enums;
using Xarial.XCad.SolidWorks;
using Xarial.XCad.SolidWorks.Documents;
using Xarial.XCad.SolidWorks.Enums;
namespace model_generator
{
class Program
{
static void Main(string[] args)
{
using(var app = SwApplicationFactory.Create(SwVersion_e.Sw2020, ApplicationState_e.Background))
{
var doc = (ISwDocument)app.Documents.Open(
Path.Combine(Path.GetDirectoryName(typeof(Program).Assembly.Location), @"template\model1.SLDPRT"),
DocumentState_e.ReadOnly);
Console.WriteLine("Enter width in meters");
var widthStr = Console.ReadLine();
if(!string.IsNullOrEmpty(widthStr))
{
doc.Dimensions["Width@Base"].SetValue(double.Parse(widthStr));
}
Console.WriteLine("Enter height in meters");
var heightStr = Console.ReadLine();
if(!string.IsNullOrEmpty(heightStr))
{
doc.Dimensions["Height@Boss"].SetValue(double.Parse(heightStr));
}
Console.WriteLine("Enter length in meters");
var lengthStr = Console.ReadLine();
if(!string.IsNullOrEmpty(lengthStr))
{
doc.Dimensions["Length@Base"].SetValue(double.Parse(lengthStr));
}
Console.WriteLine("Enter output file path");
var outFilePath = Console.ReadLine();
int errs = -1;
int warns = -1;
if(!doc.Model.Extension.SaveAs(outFilePath,
(int)SolidWorks.Interop.swconst.swSaveAsVersion_e.swSaveAsCurrentVersion,
(int)SolidWorks.Interop.swconst.swSaveAsOptions_e.swSaveAsOptions_Silent, null, ref errs, ref warns))
{
throw new Exception("Failed to save document");
}
app.Close();
}
}
}
}