机械荟萃山庄

 找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
热搜: 活动 交友 discuz
查看: 1636|回复: 0

AnyCAD .Net SDK试用手记

[复制链接]

2万

主题

2万

帖子

17万

积分

超级版主

Rank: 8Rank: 8

积分
173959
发表于 2019-6-25 12:55:43 | 显示全部楼层 |阅读模式
按照官方网站上的说法,AnyCAD .Net SDK是给C#的开发者提供的CAD API,而实际上其他.Net的开发者(VB.Net)都可以用。这个东东是免费的
1 下载在github上可以下载该SDK。解压后大小不到20M,相比其他CAD的SDK来说,确实小!

2 在项目中引用Assembly:

3. 我认为一些有用的类
4. 代码(摘自官方的示例程序)
?
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using AnyCAD.Platform;

namespace AnyCAD.Basic
{
public partial class FormMain : Form
{
// The global application object
Platform.Application theApplication = new Platform.Application();
// BREP tool to create geometries.
BrepTools shapeMaker = new BrepTools();
// Default 3d View
Platform.View3d theView;


public FormMain()
{
InitializeComponent();
this.MouseWheel += new System.Windows.Forms.MouseEventHandler(this.OnMouseWheel);
}

private void FormMain_Load(object sender, EventArgs e)
{
// Initialize the Application.
theApplication.Initialize();
Size size = panel3d.Size;

// Create the 3d View
theView = theApplication.CreateView(panel3d.Handle.ToInt32(), size.Width, size.Height);

theView.RequestDraw();

this.timerDraw.Enabled = true;
}
private void FormMain_SizeChanged(object sender, EventArgs e)
{
Size size = panel3d.Size;
if(theView != null)
theView.OnSize(size.Width, size.Height);
}
private void panel3d_Paint(object sender, PaintEventArgs e)
{
if (theView == null)
return;

theView.Redraw();
}

private void timerDraw_Tick(object sender, EventArgs e)
{
theView.RequestDraw();
theView.Redraw();
}

private SceneNode ShowTopoShape(TopoShape topoShape, int id)
{
// Add the TopoShape to Scene.
TopoShapeConvert convertor = new TopoShapeConvert();
SceneNode faceNode = convertor.ToFaceNode(topoShape, 0.5f);
faceNode.SetId(id);
theView.GetSceneManager().AddNode(faceNode);
return faceNode;
}

private void ClearScene()
{
theView.GetSceneManager().ClearNodes();
}

private void sphereToolStripMenuItem_Click(object sender, EventArgs e)
{
TopoShape sphere = shapeMaker.MakeSphere(new Vector3(0, 0, 0), 40);
ShowTopoShape(sphere, 100);
}

private void boxToolStripMenuItem_Click(object sender, EventArgs e)
{
TopoShape box = shapeMaker.MakeBox(new Vector3(40, -20, 0), new Vector3(0, 0, 1), new Vector3(30, 40, 60));

SceneNode sceneNode = ShowTopoShape(box, 101);

// Face Style
FaceStyle style = new FaceStyle();
style.SetColor(new ColorValue(0.5f, 0.3f, 0, 1));
sceneNode.SetFaceStyle(style);
}

private void cylinderToolStripMenuItem_Click(object sender, EventArgs e)
{
TopoShape cylinder = shapeMaker.MakeCylinder(new Vector3(80, 0, 0), new Vector3(0, 0, 1), 20, 100, 315);
SceneNode sceneNode = ShowTopoShape(cylinder, 102);
FaceStyle style = new FaceStyle();
style.SetColor(new ColorValue(0.1f, 0.3f, 0.8f, 1));
sceneNode.SetFaceStyle(style);
}

private void coneToolStripMenuItem_Click(object sender, EventArgs e)
{
TopoShape cylinder = shapeMaker.MakeCone(new Vector3(120, 0, 0), new Vector3(0, 0, 1), 20, 100, 40, 315);
ShowTopoShape(cylinder, 103);
}

private void extrudeToolStripMenuItem_Click(object sender, EventArgs e)
{
int size = 20;
// Create the outline edge
TopoShape arc = shapeMaker.MakeArc3Pts(new Vector3(-size, 0, 0), new Vector3(size, 0, 0), new Vector3(0, size, 0));
TopoShape line1 = shapeMaker.MakeLine(new Vector3(-size, -size, 0), new Vector3(-size, 0, 0));
TopoShape line2 = shapeMaker.MakeLine(new Vector3(size, -size, 0), new Vector3(size, 0, 0));
TopoShape line3 = shapeMaker.MakeLine(new Vector3(-size, -size, 0), new Vector3(size, -size, 0));

TopoShapeGroup shapeGroup = new TopoShapeGroup();
shapeGroup.Add(line1);
shapeGroup.Add(arc);
shapeGroup.Add(line2);
shapeGroup.Add(line3);

TopoShape wire = shapeMaker.MakeWire(shapeGroup);
TopoShape face = shapeMaker.MakeFace(wire);

// Extrude
TopoShape extrude = shapeMaker.Extrude(face, 100, new Vector3(0, 0, 1));
ShowTopoShape(extrude, 104);

// Check find....
SceneNode findNode = theView.GetSceneManager().FindNode(104);
theView.GetSceneManager().SelectNode(findNode);
}

private void revoleToolStripMenuItem_Click(object sender, EventArgs e)
{
int size = 10;
// Create the outline edge
TopoShape arc = shapeMaker.MakeArc3Pts(new Vector3(-size, 0, 0), new Vector3(size, 0, 0), new Vector3(0, size, 0));
TopoShape line1 = shapeMaker.MakeLine(new Vector3(-size, -size, 0), new Vector3(-size, 0, 0));
TopoShape line2 = shapeMaker.MakeLine(new Vector3(size, -size, 0), new Vector3(size, 0, 0));
TopoShape line3 = shapeMaker.MakeLine(new Vector3(-size, -size, 0), new Vector3(size, -size, 0));

TopoShapeGroup shapeGroup = new TopoShapeGroup();
shapeGroup.Add(line1);
shapeGroup.Add(arc);
shapeGroup.Add(line2);
shapeGroup.Add(line3);

TopoShape wire = shapeMaker.MakeWire(shapeGroup);

TopoShape revole = shapeMaker.Revol(wire, new Vector3(size * 3, 0, 0), new Vector3(0, 1, 0), 145);

ShowTopoShape(revole, 105);
}

private void clearToolStripMenuItem_Click(object sender, EventArgs e)
{
ClearScene();
}

private void sTLToolStripMenuItem_Click(object sender, EventArgs e)
{
OpenFileDialog dlg = new OpenFileDialog();
dlg.Filter = "STL (*.stl)|*.stl|All Files(*.*)|*.*";

if (DialogResult.OK == dlg.ShowDialog())
{
TopoShape shape = shapeMaker.LoadFile(dlg.FileName);
if( shape != null)
ShowTopoShape(shape, 1000);

}
}

private void Pane3d_MouseDown(object sender, MouseEventArgs e)
{
ViewUtility.OnMouseDownEvent(theView, e);
}

private void Pane3d_MouseMove(object sender, MouseEventArgs e)
{
ViewUtility.OnMouseMoveEvent(theView, e);
}

private void Pane3d_MouseUp(object sender, MouseEventArgs e)
{
ViewUtility.OnMouseUpEvent(theView, e);
}
private void OnMouseWheel(object sender, MouseEventArgs e)
{
ViewUtility.OnMouseWheelEvent(theView, e);
}


}
}




  
5. 运行效果

6. 结论
  • 建模功能满足基本的需求
    • 支持基本体
    • 支持创建拉伸,扫掠,回转体等
  • 支持自定义的显示效果设置
  • 视图操作符合CAD的操作习惯
  • 与AutoCAD相比最大的一个优势就是不是二次开发的方式,直接可以创建独立的应用程序

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

x
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|小黑屋|手机版|Archiver|机械荟萃山庄 ( 辽ICP备16011317号-1 )

GMT+8, 2024-11-16 08:43 , Processed in 0.103736 second(s), 20 queries , Gzip On.

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表