SolidWorks 使い方 入門
ソリッドワークス3Dプリンターのデータ作成、修正、造形 株式会社 サンエツ
class Form1の全文
public partial class
Form1 : Form
{
public Form1()
{
InitializeComponent();
}
//Shownイベント
private void Form1_Shown(
object sender,
EventArgs e)
{
this
.Text="中点線の作成";
label1.Text=
"X方向の中点線の長さ";
label2.Text=
"Y方向の中点線の長さ";
label3.Text=
"Z方向の中点線の長さ";
button1.Text=
"決定";
textBox1.Text=
"0";
textBox2.Text=
"0";
textBox3.Text=
"0";
}
//textBoxに入力された値をリストにAdd
List
<double> _ar=
new List<
double>();
//button1_Clickイベント
private void
button1_Click(object
sender, EventArgs
e)
{
_ar.Clear();
//リストをクリアしておく
//textBoxの値をリストにAddします。
ar.Add(
double.Parse(textBox1.Text));
ar.Add(double
.Parse(textBox2.Text));
ar.Add(
double.Parse(textBox3.Text));
this
.Close();
}
//リストごとclass SolidWorksMacroに渡す
public
List<double
> ar
{
get
{return this._ar;}
}
}
public partial class
SolidWorksMacro
{
//SldWorksソリッドワークスの大箱
public
SldWorks swApp;
public void
Main()
{
//class Form1からリストごと値を受け取る
List<double
> _dr=new
List<double
>();
_dr.Clear();
//class Form1の作成
Form1 f1=
new Form1
();
f1.ShowDialog();
//class Form1からリストごと値を受け取る
_dr=f1.ar;
//ドキュメントを入れる箱
ModelDoc2
swDoc ;
//現在のドキュメントを変数に格納
swDoc = ((ModelDoc2
)(swApp.ActiveDoc));
//正面を選択
swDoc.Extension.SelectByID2("正面"
, "PLANE"
, 0, 0, 0, false
, 0, null
, 0);
//スケッチを挿入します
swDoc.SketchManager.InsertSketch(true
);
//スケッチの大箱
SketchSegment skSegment=
null;
//線の作成
skSegment=((SketchSegment
)(swDoc.SketchManager.CreateLine(_dr[0]/1000, _dr[1]/1000, _dr[2]/1000, -_dr[0]/1000, -_dr[1]/1000, -_dr[2]/1000)));
//選択を解除
swDoc.ClearSelection2(true
);
//スケッチを挿入します
swDoc.SketchManager.InsertSketch(true
);
}
}