タイガーラック クリエイティブブログ
2026
June
11

【Inventor】iLogicでアセンブリ内のパーツを面拘束する方法

今回はInventorのiLogicで、アセンブリに配置中のパーツの面拘束を設定する方法を説明します。
今回の例ではアセンブリ上に配置されたPart1:1というパーツを原点位置に拘束します。

環境

  • Autodesk Inventor Professional 2025

アセンブリ内パーツの面拘束

スクリプト全体

Sub main()
  'アセンブリの情報を取得
  Dim oApp As Inventor.Application = ThisApplication
  Dim oDoc As AssemblyDocument = oApp.ActiveDocument
  Dim oAsmDef As AssemblyComponentDefinition = oDoc.ComponentDefinition
  Dim oConsts As AssemblyConstraints = oAsmDef.Constraints
  Dim oAsmWPs As WorkPlanes = oAsmDef.WorkPlanes
	
  'パーツオカレンスを取得
  Dim oPartOcc As ComponentOccurrence = oAsmDef.Occurrences.ItemByName("Part1:1")
  Dim oPartDef As PartComponentDefinition = oPartOcc.Definition
  Dim oPartWPs As WorkPlanes = oPartDef.WorkPlanes
	
  'アセンブリの平面を取得
  Dim oAsmWP_XZ As WorkPlane = oAsmWPs.Item("XZ Plane")
  Dim oAsmWP_XY As WorkPlane = oAsmWPs.Item("XY Plane")
  Dim oAsmWP_YZ As WorkPlane = oAsmWPs.Item("YZ Plane")
	
  'パーツの平面を取得
  Dim oPartWP_XZ As WorkPlane = oPartWPs.Item("XZ Plane")
  Dim oPartWP_XY As WorkPlane = oPartWPs.Item("XY Plane")
  Dim oPartWP_YZ As WorkPlane = oPartWPs.Item("YZ Plane")

  'パーツ平面のプロキシを作成
  Dim oPartWPProxy_XZ As WorkPlaneProxy
  Dim oPartWPProxy_XY As WorkPlaneProxy
  Dim oPartWPProxy_YZ As WorkPlaneProxy
  oPartOcc.CreateGeometryProxy(oPartWP_XZ, oPartWPProxy_XZ)
  oPartOcc.CreateGeometryProxy(oPartWP_XY, oPartWPProxy_XY)
  oPartOcc.CreateGeometryProxy(oPartWP_YZ, oPartWPProxy_YZ)

  '三平面をFlush拘束
  Dim oConst_XZ As FlushConstraint = oConsts.AddFlushConstraint(oPartWPProxy_XZ, oAsmWP_XZ, 0)
  Dim oConst_XY As FlushConstraint = oConsts.AddFlushConstraint(oPartWPProxy_XY, oAsmWP_XY, 0)
  Dim oConst_YZ As FlushConstraint = oConsts.AddFlushConstraint(oPartWPProxy_YZ, oAsmWP_YZ, 0)
    
  oDoc.Update()
End Sub

面拘束を行う際の流れは

1,アセンブリの情報を取得する
2,アセンブリ内のパーツ情報を取得する
3,アセンブリの平面を取得する
4,パーツの平面を取得する
5,パーツ平面のプロキシを作成する
6,アセンブリの平面とパーツ平面のプロキシを拘束する

という形になります。

アセンブリとパーツの情報取得

  Dim oApp As Inventor.Application = ThisApplication
  Dim oDoc As AssemblyDocument = oApp.ActiveDocument
  Dim oAsmDef As AssemblyComponentDefinition = oDoc.ComponentDefinition
  Dim oConsts As AssemblyConstraints = oAsmDef.Constraints
  Dim oAsmWPs As WorkPlanes = oAsmDef.WorkPlanes

  Dim oPartOcc As ComponentOccurrence = oAsmDef.Occurrences.ItemByName("Part1:1")
  Dim oPartDef As PartComponentDefinition = oPartOcc.Definition
  Dim oPartWPs As WorkPlanes = oPartDef.WorkPlanes

アセンブリのConstraints(拘束のコレクション)と、アセンブリとパーツのWorkPlanes(平面のコレクション)を取得します。ConstraintsWorkPlanesは両方ともComponentDefinition内にあります。
アセンブリのComponentDefinitionDocument.ComponentDefinitionから取得できます。
ドキュメント内のパーツのComponentDefinitionを取得するには、まずDocument.ComponentDefinition.Occurrences.ItemByName(“<パーツ名>”)でパーツのComponentOccurrenceを取得し、そこからComponentOccurrence.DefinitionComponentDefinitionを取得します。

アセンブリとパーツの平面を取得

  Dim oAsmWP_XZ As WorkPlane = oAsmWPs.Item("XZ Plane")
  Dim oAsmWP_XY As WorkPlane = oAsmWPs.Item("XY Plane")
  Dim oAsmWP_YZ As WorkPlane = oAsmWPs.Item("YZ Plane")

  Dim oPartWP_XZ As WorkPlane = oPartWPs.Item("XZ Plane")
  Dim oPartWP_XY As WorkPlane = oPartWPs.Item("XY Plane")
  Dim oPartWP_YZ As WorkPlane = oPartWPs.Item("YZ Plane")

WorkPlanes.Item(“<平面の名前>”)WorkPlaneを取得します。Inventorのデフォルトでは平面の名称がXZ Plane,XY Plane,YZ Planeとなっています。三平面ともアセンブリとパーツの両方から取得します。

パーツ平面のプロキシを作成する

  Dim oPartWPProxy_XZ As WorkPlaneProxy
  Dim oPartWPProxy_XY As WorkPlaneProxy
  Dim oPartWPProxy_YZ As WorkPlaneProxy
  oPartOcc.CreateGeometryProxy(oPartWP_XZ, oPartWPProxy_XZ)
  oPartOcc.CreateGeometryProxy(oPartWP_XY, oPartWPProxy_XY)
  oPartOcc.CreateGeometryProxy(oPartWP_YZ, oPartWPProxy_YZ)

アセンブリ内のパーツ平面は取得してもそのまま拘束に使用することが出来ないので、ComponentOccurrence.CreateGeometryProxy(<WorkPlane>,<WorkPlaneProxy>)コマンドでプロキシを作成する必要があります。

アセンブリの平面とパーツ平面のプロキシを拘束する

  Dim oConst_XZ As FlushConstraint = oConsts.AddFlushConstraint(oPartWPProxy_XZ, oAsmWP_XZ, 0)
  Dim oConst_XY As FlushConstraint = oConsts.AddFlushConstraint(oPartWPProxy_XY, oAsmWP_XY, 0)
  Dim oConst_YZ As FlushConstraint = oConsts.AddFlushConstraint(oPartWPProxy_YZ, oAsmWP_YZ, 0)

oConsts.AddFlushConstraints(<平面1>,<平面2>, <距離>)を行うことでFlush拘束を行うことが出来ます。
3方向分の取得したアセンブリの平面と、作成したパーツ平面のプロキシを指定し、距離を0とすることでアセンブリの原点の位置に拘束することが出来ます。
Flush拘束をMate拘束に変更したい場合は

  Dim oConst_XZ As MateConstraint = oConsts.AddMateConstraint(oPartWPProxy_XZ, oAsmWP_XZ, 0)

というような形に変更すればMate拘束が可能です。
なお、既に拘束が存在する場合でも既存の拘束を上書きすることなく追加されてしまう為、拘束を置き換える場合は事前にoConst_ZX.Name = <拘束名>の様な形で拘束に名前を付けておき、oConsts.Item(“<拘束名>”).Delete()のような形で拘束を取得して削除する必要があります。

Sub DeleteConstraint(oConsts As AssemblyConstraints, sName As String)
  Dim oConst As AssemblyConstraint
  For Each oConst In oConsts
    If (oConst.Name = sName)
      oConst.Delete()
      Exit For
    End If
  Next
End Sub

存在しない拘束名をItemで取得しようとするとエラーが発生してしまう為、For Eachで拘束名を探して削除するとより使いやすくなります。

アセンブリの更新

oDoc.Update()

iLogicスクリプトを動作させても画面上のパーツの位置情報は更新されないため、すべての処理の終了後に更新を行います。
以上でPart1:1が原点位置に固定、描画がされます。

以前の記事で別のルールを呼び出す方法を説明しましたが、今回のスクリプトも「そのままのVBコード」にチェックを入れていないルールでInventor.Applicationを取得し、その他を「そのままのVBコード」にチェックを入れたルールに記入すれば、配置用ルールを作成して使い回す事が出来るので活用してみてください。

このカテゴリの最新記事

関連記事

SHOP LIST

タイガーラック株式会社

〒577-0056
大阪府東大阪市長堂1-3-14 TOKUYASU Bld.