コードの全文
「class SolidWorksMacro」のコード
using
SolidWorks.Interop.sldworks;
using
SolidWorks.Interop.swconst;
using
System.Runtime.InteropServices;
using System;
namespace sldworksapi5.csproj
{
public partial class
SolidWorksMacro
{
public
SldWorks swApp;
public void
Main()
{
Form1 f1 =
new Form1
();
f1.ShowDialog();
ModelDoc2 swDoc =
null;
swDoc = ((
ModelDoc2)(swApp.ActiveDoc));
for (
int
i = 0; i <= 100; ++i)
{
//"回転"フィーチャーの選択
swDoc.Extension.SelectByID2("回転"
, "SOLIDBODY"
, 0, 0, 0, false
, 1, null
, 0);
//フィーチャーオブジェトの作成
Feature myFeature =
null;
//選択した"回転"フィチャーのボティ移動を作成
myFeature = ((Feature
)(swDoc.FeatureManager.InsertMoveCopyBody2(((
double
)(i)) / 100, 0, 0, 0, 0, 0, 0, 0, 0, 0,
false, 1)));
// "ボディ移動"フィチャーを選択
swDoc.Extension.SelectByID2(
"ボディ-移動",
"BODYFEATURE"
, 0, 0, 0, false
, 0, null
, 0);
System.Threading.
Thread.Sleep(2000);
captuer gr =
new captuer
();
gr.capt(i);
//現在アクティブなドキュメント(選択状態)を削除
swDoc.EditDelete();
}
}
}
}
「class Form1」のコード
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace sldworksapi5.csproj
{
public partial class
Form1 :
Form
{
public
Form1()
{
InitializeComponent();
}
private void
Form1_Shown(object
sender, EventArgs
e)
{
this.Text =
"";
button1.Text =
"スタート";
button1.Font =
new Font
("MSゴシック"
,22, FontStyle
.Bold);
}
private void
button1_Click(object
sender, EventArgs
e)
{
this
.Close();
}
}
}
「class captuer」のコード
using System;
using
System.Collections.Generic;
using System.Text;
using System.Drawing;
using System.Windows.Forms;
namespace sldworksapi5.csproj
{
class
captuer
{
public void capt(
int n)
{
//Bitmapの作成
int heit=700;
Bitmap bmp =
new Bitmap
(Screen
.PrimaryScreen.Bounds.Width, heit);
//Graphicsの作成
Graphics g =
Graphics.FromImage(bmp);
//画面全体をコピーする
g.CopyFromScreen(new
Point(800, 400),
new Point
(400, 200), bmp.Size);
// Jpegで保存
bmp.Save(
@"C:\xampp\htdocs\sanetu\picture\sldworksapi5\"
+ n.ToString() + ".jpg"
, System.Drawing.Imaging.
ImageFormat.Jpeg);
//解放
g.Dispose();
}
}
}