0
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

PythonでFreeCADのスライダーモデルを駆動する

Posted at

FreeCAD アセンブリワークベンチ

無料で使用できる3D-CAD:FreeCADのサンプルモデルがあります.
[Assembly]: https://wiki.freecad.org/Assembly_Workbench/ja/
ここには,スライダーモデルをマクロ機能(Python)で駆動させる手順が示されています.
drive_crank.gif
サンプルをそのまま動かすだけでは,つまらないので
Pythonスクリプトを少し改良してみます.

drive_crank_mod.py
import math
import FreeCAD as App
import FreeCADGui as Gui

actuator = App.ActiveDocument.getObjectsByLabel("Fixed")[0]

for i in range(2):
	for angle in range(0, 46, 5):
	    actuator.Offset1.Rotation.Angle = math.radians(angle)
	    App.ActiveDocument.recompute()
	    Gui.updateGui()
	
	for angle in range(45, -46, -5):
	    actuator.Offset1.Rotation.Angle = math.radians(angle)
	    App.ActiveDocument.recompute()
	    Gui.updateGui()
	
	for angle in range(-45, 1, 5):
	    actuator.Offset1.Rotation.Angle = math.radians(angle)
	    App.ActiveDocument.recompute()
	    Gui.updateGui()

このPythonスクリプトのポイントは,
1.パッケージ3つをインポート
2.モデルのラベル名で駆動ジョイントを定義:
  回転ジョイントのラベルが"Fixed"となっていること
3.回転駆動を2回させる
4.駆動角度は,(初期角度,終了角度,ステップ)として与え,
  終了角度値は,終了角度よりも少し超えた値としないと,
 終了角度よりも1ステップ分手前の角度で終わってしまう.

drive_crank_mod.gif

0
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?