Autodesk Inventorの自動化ツール「iLogic」。設計作業を劇的に効率化できる機能だけど、プログラミング初心者にとってはハードルが高く感じることも多い。そこで役立つのがChatGPTだ。


ChatGPTでiLogicコードを解読しよう

iLogicはVisual Basicベースのスクリプトを活用する仕組み。コードを読めば理解できるとはいえ、最初は意味が分からないことも多い。そんなときは、コードをChatGPTに読み込ませれば、直感的に理解できる解説をしてくれる。

例えば、Autodeskのサポートページで提供されているサンプルファイル「BrewMain-Drawing-ModelState.zip」内のiLogicコードを見てみよう。


「MakeBoiloverTray」ルール

Using New ActiveDocumentFixer(ThisApplication, ThisDoc.Document)

ThisAssembly.BeginManage
Dim triggers = Tiers & kettleSize
If (boilOverTrays) Then 

	Dim newComp = Components.Add("BoilOverTray", "Boil Over Tray.ipt")

	Constraints.AddMate("Mate:27", newComp, "Face2", "LowerHorizontalTube", "Right")
	Constraints.AddFlush("Flush:23", newComp, "Face0", "LowerHorizontalTube", "Front")
	Constraints.AddMate("Mate:26", newComp, "Face3", "RightTube","Left")

	Patterns.AddRectangular("TrayPattern", "BoilOverTray", 3 ul,
							dimSectionWidth, "", "X Axis",
							columnNaturalDirection := False)

End If
ThisAssembly.EndManage

このコードをChatGPTに入力すると、例えばこんな解説をしてくれる。



ChatGPTの解説:

このiLogicコードは、Inventorのアセンブリ内で「Boil Over Tray」というコンポーネントを追加し、それに対して拘束(Constraints)とパターン(Patterns)を適用する処理を行っています。以下、コードの解説をしていきます。


コードの解説

  1. Using New ActiveDocumentFixer(ThisApplication, ThisDoc.Document)
  • ActiveDocumentFixer を使用して、現在のInventorのドキュメントを適切に管理する。
  • ThisApplication は現在のInventorインスタンス、ThisDoc.Document は現在のアクティブなドキュメントを指す。
  1. ThisAssembly.BeginManage
  • アセンブリの管理処理を開始。
  1. Dim triggers = Tiers & kettleSize
  • Tiers(段数?)と kettleSize(ケトルのサイズ)を連結して、triggers 変数を作成。
  1. If (boilOverTrays) Then
  • boilOverTraysTrue の場合に以下の処理を実行。
  1. Dim newComp = Components.Add("BoilOverTray", "Boil Over Tray.ipt")
  • 新しいコンポーネント Boil Over Tray.ipt をアセンブリに追加し、newComp に格納。
  1. 拘束(Constraints)
  • Constraints.AddMate("Mate:27", newComp, "Face2", "LowerHorizontalTube", "Right")
  • newComp"Face2""LowerHorizontalTube""Right" 面にメイト拘束(Mate)を追加。
  • Constraints.AddFlush("Flush:23", newComp, "Face0", "LowerHorizontalTube", "Front")
  • newComp"Face0""LowerHorizontalTube""Front" 面にフラッシュ拘束(Flush)を追加。
  • Constraints.AddMate("Mate:26", newComp, "Face3", "RightTube", "Left")
  • newComp"Face3""RightTube""Left" 面にメイト拘束(Mate)を追加。
  1. パターンの適用(Patterns)
  • Patterns.AddRectangular("TrayPattern", "BoilOverTray", 3, dimSectionWidth, "", "X Axis", columnNaturalDirection := False)
  • BoilOverTray を 3 回、dimSectionWidth の間隔でX軸方向に直線配列(Rectangular Pattern)。
  • columnNaturalDirection := False により、列の方向を指定。
  1. ThisAssembly.EndManage
  • アセンブリの管理を終了。
  1. End Using
  • Using ステートメントを終了し、ActiveDocumentFixer による管理を解放。

さらに、もう一つのコード例を見てみよう。


「MakeFeet」ルール

Dim triggers = Tiers & kettleSize

Using New ActiveDocumentFixer(ThisApplication, ThisDoc.Document)

ThisAssembly.BeginManage

Dim Pad_1Pos = ThisAssembly.Geometry.Point(0,0,0)
Dim Pad_1 = Components.Add("Foot", "Pad.ipt", Pad_1Pos)

Constraints.AddMate("FootOnGround", "Foot", "Bottom", "", "XY Plane")
Constraints.AddFlush("SideFlush", "Foot", "YZ Plane", "", "YZ Plane")
Constraints.AddMate("FootOtherSide", "", "XZ Plane", "Foot", "XY Plane")

Patterns.AddRectangular("FeetPattern", "Foot", 
		2 ul, dimSectionWidth * 3 ul, "", "X Axis",	columnNaturalDirection := False,
		rowCount := 2 ul,
		rowOffset := dimDepth - dimTubingSize,
		rowComponent := "", 
		rowEntityName := "Y Axis")

ThisAssembly.EndManage

End Using

これをChatGPTに渡すと・・・



このiLogicコードの解説

このコードは、Inventorのアセンブリ内で「Foot(Pad.ipt)」というコンポーネントを追加し、それに対して拘束(Constraints)とパターン(Patterns)を適用する処理を行っています。特に、フットパーツをXY面に配置し、それをX方向とY方向にパターン配置するスクリプトになっています。


コードの分解と解説

1. Dim triggers = Tiers & kettleSize

  • Tiers(段数)と kettleSize(ケトルのサイズ)を連結して、triggers 変数に格納。
  • これは条件分岐やトリガー設定に使われる可能性がある。

2. Using New ActiveDocumentFixer(ThisApplication, ThisDoc.Document)

  • ActiveDocumentFixer を使って現在のInventorのドキュメントを適切に管理。
  • ThisApplication は現在のInventorインスタンス、ThisDoc.Document は現在のアクティブなドキュメントを指す。

3. ThisAssembly.BeginManage

  • アセンブリの変更管理を開始。

4. フットパッドの配置

フットの挿入

vb
コピーする編集する
Dim Pad_1Pos = ThisAssembly.Geometry.Point(0,0,0)
Dim Pad_1 = Components.Add("Foot", "Pad.ipt", Pad_1Pos)
  • Pad_1Pos(0,0,0) の位置を設定し、新しいフットパーツ (Pad.ipt) を追加。

5. 拘束の追加

vb
コピーする編集する
Constraints.AddMate("FootOnGround", "Foot", "Bottom", "", "XY Plane")
  • "Foot""Bottom" 面を "XY Plane" にメイト拘束(Mate)。
  • これによりフットパーツがXY面(床)に固定される。
vb
コピーする編集する
Constraints.AddFlush("SideFlush", "Foot", "YZ Plane", "", "YZ Plane")
  • "Foot""YZ Plane" をアセンブリの "YZ Plane" にフラッシュ拘束(Flush)。
  • これにより左右の位置がそろう。
vb
コピーする編集する
Constraints.AddMate("FootOtherSide", "", "XZ Plane", "Foot", "XY Plane")
  • "XZ Plane""Foot""XY Plane" をメイト拘束(Mate)。
  • これにより、フットの正しい方向が保たれる。

6. 矩形パターンの適用

vb
コピーする編集する
Patterns.AddRectangular("FeetPattern", "Foot", 
		2 ul, dimSectionWidth * 3 ul, "", "X Axis",	columnNaturalDirection := False,
		rowCount := 2 ul,
		rowOffset := dimDepth - dimTubingSize,
		rowComponent := "", 
		rowEntityName := "Y Axis")
  • "Foot"X軸方向に2回 配置(間隔 dimSectionWidth * 3)。
  • "Y Axis" にも 2回 配置(間隔 dimDepth - dimTubingSize)。
  • columnNaturalDirection := False に設定し、自然な方向と逆向きの配置を指定。

7. ThisAssembly.EndManage

  • アセンブリの変更管理を終了。

8. End Using

  • Using ステートメントを終了し、ActiveDocumentFixer による管理を解放。



ChatGPTを活用すればiLogic初心者でも大丈夫

iLogicの最大の課題は、コードの理解に時間がかかること。でも、ChatGPTを使えば、すぐにコードの意味を把握できる。

また、「このコードをもっと最適化できる?」と聞くことで、より効率的な書き方やエラーハンドリングの方法を教えてくれる。iLogicの学習をスムーズに進めるために、ぜひChatGPTを活用してみよう!