見出し画像

Inventor / iLogic 現在のビューの反対側に視点を変更するルール

 作業中に視点を変えたい時がある。View Vubeを使うことが多いがちょっと面倒なのでAPIを使うとどうか調べてみたことがある。
 Inventor API では視点のコントロールにCameraオブジェクトを使う。視点の目の位置にカメラを置いたときの対象や焦点距離などのプロパティを変えてやることで制御できる。

 このルールはその Camera オブジェクトを使って視点を反対側に変更するものだ。Camera オブジェクトを使ったサンプルにちょうど良い。

'現在のビューの反対側に視点を変更
'Ver 1.1 By Yoji Tanaka At 21/01/22 iLogic に移植

Sub Main
	
	'現在の視点と目標点をはさんで反対側の位置を計算し、その点を新しい視点にしてカメラを更新する

	Dim invApp As Inventor.Application = ThisApplication
	Dim oDoc As Inventor.Document = ThisDoc.Document
	Dim oViewActive As Inventor.View = invApp.ActiveView

	Dim oCamera As Inventor.Camera = oViewActive.Camera
	Dim oEye As Inventor.Point = oCamera.Eye
	Dim oTarget As Inventor.Point = oCamera.Target

	Dim oVec As Inventor.Vector = invApp.TransientGeometry.CreateVector(oTarget.X - oEye.X, oTarget.Y - oEye.Y, oTarget.Z - oEye.Z)
	oVec.ScaleBy(2.0#)

	Dim oNewEye As Inventor.Point = invApp.TransientGeometry.CreatePoint(oEye.X + oVec.X, oEye.Y + oVec.Y, oEye.Z + oVec.Z)
	Dim oUpVector As Inventor.UnitVector = oCamera.UpVector

	With oCamera
	    .Eye = oNewEye
	    .UpVector = oUpVector   '上下がずれないようにする
	    .Apply()
	End With

	oViewActive.Update()	
	
End Sub

-YO



役に立った!という記事にはぜひサポートお願いします。サポート頂けると大変に励みになります。