Inventor 2014 API 新機能 更新情報

前回前々回の「Inventor 2014 機能紹介 」に続き、Inventor 2014のAPIについてご紹介させていただきます。
今回は、アセンブリ内における「新しいジョイント機能」用のAPIにおいて、Autodesk Inventor 2014 API Help( admapi_18_0.chm) ファイルに掲載されております「サンプルコード」の更新情報を掲載させていただきます。

“Create rotational assembly connection. API Sample”
Fig-1

Public Sub AssemblyJoint()
‘ アセンブリドキュメントを新規作成
Dim asmDoc As AssemblyDocument
Set asmDoc = ThisApplication.Documents.Add(kAssemblyDocumentObject, _
ThisApplication.FileManager.GetTemplateFile(kAssemblyDocumentObject))
Dim asmDef As AssemblyComponentDefinition
Set asmDef = asmDoc.ComponentDefinition

‘ アセンブリ内にオカレンスを配置
Dim occ1 As ComponentOccurrence
Dim occ2 As ComponentOccurrence
Dim trans As Matrix
Set trans = ThisApplication.TransientGeometry.CreateMatrix
Set occ1 = asmDef.Occurrences.Add(“C:\Temp\SamplePart.ipt”, trans)

‘ 最初に配置されたオカレンス位置を基に2つ目のオカレンスのマトリクスを調整し配置
trans.Cell(1, 4) = 6 * 2.54
Set occ2 = asmDef.Occurrences.Add(“C:\Temp\SamplePart.ipt”, trans)

‘ 最初のオカレンスのFace1を得て、FaceProxyを作成
Dim face1 As Face
Set face1 = GetNamedEntity(occ1, “Face1”)

‘ 2つ目のオカレンスのFace2を得て、FaceProxy を作成
Dim face2 As Face
Set face2 = GetNamedEntity(occ2, “Face2”)

‘ 2つ目のオカレンスから Edge1 を得てEdgeProxyの作成.
Dim Edge1 As Edge
Set Edge1 = GetNamedEntity(occ2, “Edge1”)

‘ 最初のオカレンスからEdge 3 を得てEdgeProxyの作成.
Dim Edge3 As Edge
Set Edge3 = GetNamedEntity(occ1, “Edge3”)

‘ Edge1の中心データでGeometryIntentの作成
Dim edge1Intent As GeometryIntent
Set edge1Intent = asmDef.CreateGeometryIntent(Edge1, PointIntentEnum.kMidPointIntent)

‘ Edge3の中心データでGeometryIntentの作成
Dim edge3Intent As GeometryIntent
Set edge3Intent = asmDef.CreateGeometryIntent(Edge3, PointIntentEnum.kMidPointIntent)

‘ 「ジョイント」定義用に2つのGeometryIntentの作成
Dim intentOne As GeometryIntent
Set intentOne = asmDef.CreateGeometryIntent(face2, edge1Intent)
Dim intentTwo As GeometryIntent
Set intentTwo = asmDef.CreateGeometryIntent(face1, edge3Intent)

' 2つのパーツ間に「リジッド」ジョイントを作成<br />

Dim jointDef As AssemblyJointDefinition
Set jointDef = asmDef.Joints.CreateAssemblyJointDefinition(kRotationalJointType, intentOne, intentTwo)
jointDef.FlipAlignmentDirection = False
jointDef.FlipOriginDirection = True
Dim joint As AssemblyJoint
Set joint = asmDef.Joints.Add(jointDef)

' ジョイントを表示<br />

joint.Visible = True

‘ ジョイントをアニメーション駆動
joint.DriveSettings.StartValue = “0 deg”
joint.DriveSettings.EndValue = “180 deg”
joint.DriveSettings.GoToStart
joint.DriveSettings.PlayForward
joint.DriveSettings.PlayReverse
End Sub

‘ 指定された名前のiMateと関連付けられているエンティティを検索します。
‘ iMatesを汎用ネーミングメカニズムとして使用する
Private Function GetNamedEntity(Occurrence As ComponentOccurrence, Name As String) As Object
‘ 参照されたファイル内で指定した名前のiMateを探す
Dim iMate As iMateDefinition
Dim partDef As PartComponentDefinition
Set partDef = Occurrence.Definition
For Each iMate In partDef.iMateDefinitions
‘ iMateが正しい名前を持っているかどうかを確認
If UCase(iMate.Name) = UCase(Name) Then
‘ iMateに関連付けられているジオメトリを取得
Dim entity As Object
Set entity = iMate.entity

‘ プロキシの作成
Dim resultEntity As Object
Set resultEntity = Nothing
Call Occurrence.CreateGeometryProxy(entity, resultEntity)

Exit For
End If
Next

‘ 見つかったエンティティを返す。見つからない場合はNothing
Set GetNamedEntity = resultEntity
End Function

サンプルはここ よりダウンロードする事ができます。
(解凍後、”C:\Temp\SamplePart.ipt”として配置して動作確認ができます)

次回も、引き続きInventor2014製品の API ついてご案内する予定です。
By Shigekazu Saito.


Comments

Leave a Reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading