[S8635] 形状エディタで直方体を作成するスクリプト

 

形状エディタで直方体を作成するスクリプトを例示します。

# 直方体の幅

W = 20

# 直方体の奥行

D = 10

# 直方体の高さ

H = 10

app = designer.GetApplication()

# 形状エディタを起動

app.LaunchGeometryEditor()

# 形状エディタのオブジェクトを取得

geomApp = app.CreateGeometryEditor()    

# パートを作成

objPart = geomApp.GetDocument().GetAssembly().CreatePart()

# パートを開く

objPart.OpenPart()

# XY平面上にスケッチを作成

objSketch = objPart.CreateSketch(objPart.GetPlaneXY())

# スケッチを開く

objSketch.OpenSketch()

# スケッチ内に4つの線分を作成

objLine1 = objSketch.CreateLine(0, 0, W, 0)

objLine2 = objSketch.CreateLine(0, D, W, D)

objLine3 = objSketch.CreateLine(0, 0, 0, D)

objLine4 = objSketch.CreateLine(W, 0, W, D)

# X軸上の辺を固定拘束する

ref1 = geomApp.GetDocument().CreateReferenceFromItem(objLine1)

objSketch.CreateMonoConstraint("fixture", ref1)

# Y軸上の辺を固定拘束する

ref1 = geomApp.GetDocument().CreateReferenceFromItem(objLine3)

objSketch.CreateMonoConstraint("fixture", ref1)

# 奥行の距離拘束を作成

ref1 = geomApp.GetDocument().CreateReferenceFromItem(objLine1)

ref2 = geomApp.GetDocument().CreateReferenceFromItem(objLine2)

objConstraint = objSketch.CreateBiConstraint("distance", ref1, ref2)

# 幅の距離拘束を作成

ref1 = geomApp.GetDocument().CreateReferenceFromItem(objLine3)

ref2 = geomApp.GetDocument().CreateReferenceFromItem(objLine4)

objConstraint = objSketch.CreateBiConstraint("distance", ref1, ref2)

# 選択をクリア

geomApp.GetDocument().GetSelection().Clear()

# 作成した辺を選択

geomApp.GetDocument().GetSelection().Add(objLine1)

geomApp.GetDocument().GetSelection().Add(objLine2)

geomApp.GetDocument().GetSelection().Add(objLine3)

geomApp.GetDocument().GetSelection().Add(objLine4)

# 領域を作成

objSketch.CreateRegions()

# スケッチを閉じる

objSketch.CloseSketch()

# スケッチを押し出す

objPart.CreateExtrudeSolid(objSketch, H)

# パートを閉じる

objPart.ClosePart()

# JMAG-Designerに形状をインポート

app.ImportDataFromGeometryEditor()

ファイルご利用の注意点

JMAGスクリプトライブラリをご利用されるに際し、以下の利用規約をよくお読みいただき、ご同意の上ご利用下さるようお願い申し上げます。