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)を適用する処理を行っています。以下、コードの解説をしていきます。コードの解説Using New ActiveDocumentFixer(ThisApplication, ThisDoc.Document)ActiveDocumentFixer を使用して、現在のInventorのドキュメントを適切に管理する。ThisApplication は現在のInventorインスタンス、ThisDoc.Document は現在のアクティブなドキュメントを指す。ThisAssembly.BeginManageアセンブリの管理処理を開始。Dim triggers = Tiers & kettleSizeTiers(段数?)と kettleSize(ケトルのサイズ)を連結して、triggers 変数を作成。If (boilOverTrays) ThenboilOverTrays が True の場合に以下の処理を実行。Dim newComp = Components.Add("BoilOverTray", "Boil Over Tray.ipt")新しいコンポーネント Boil Over Tray.ipt をアセンブリに追加し、newComp に格納。拘束(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)を追加。パターンの適用(Patterns)Patterns.AddRectangular("TrayPattern", "BoilOverTray", 3, dimSectionWidth, "", "X Axis", columnNaturalDirection := False)BoilOverTray を 3 回、dimSectionWidth の間隔でX軸方向に直線配列(Rectangular Pattern)。columnNaturalDirection := False により、列の方向を指定。ThisAssembly.EndManageアセンブリの管理を終了。End UsingUsing ステートメントを終了し、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 & kettleSizeTiers(段数)と 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 UsingUsing ステートメントを終了し、ActiveDocumentFixer による管理を解放。ChatGPTを活用すればiLogic初心者でも大丈夫iLogicの最大の課題は、コードの理解に時間がかかること。でも、ChatGPTを使えば、すぐにコードの意味を把握できる。また、「このコードをもっと最適化できる?」と聞くことで、より効率的な書き方やエラーハンドリングの方法を教えてくれる。iLogicの学習をスムーズに進めるために、ぜひChatGPTを活用してみよう!