Skip to content

Scripting RobotBuilder

Nishendra Singh edited this page Sep 16, 2026 · 2 revisions

Part of the Scripting API. RobotBuilder is the script equivalent of the Define Robot wizard: parts, base, joints, finish.

from freecad.robotics.App.rbt_api import RobotBuilder, FIXED, REVOLUTE

Members

Member Function
RobotBuilder(doc=None).new_robot() Make a new assembly and Robot object
.attach(hint=None) Bind to an existing robot for edits
.import_parts(path) Merge a parts .FCStd file. Result: the imported objects
.add_parts(objs) / .add_part(obj) Insert parts into the assembly, in build order
.add_base(ref, jtype=FIXED) Ground the base link. ref = (link, "FaceN"). Types: FIXED, REVOLUTE (turntable), PRISMATIC (rail)
.add_joint(jtype, ref1, ref2) Connect two links. Parent side first
.flip_joint(joint) / .delete_joint(joint) / .remove_link(link) Corrections
.robot The robot as RobotApi, available during the build
.finish() Validate and recompute. Result: RobotApi

Build a robot

b = RobotBuilder().new_robot()

parts = b.import_parts(r"C:\robots\parts.FCStd")
links = b.add_parts(parts)

b.add_base((links[0], "Face3"), FIXED)
b.add_joint(REVOLUTE, (links[0], "Face7"), (links[1], "Face2"))
b.add_joint(REVOLUTE, (links[1], "Face9"), (links[2], "Face1"))

rob = b.finish()
print(rob.n_joints)

The rules are the same as in the wizard: ground the base first, then connect the links in sequence, parent side first. The type of the base joint sets the robot kind. See Step 3: Define joints.

Edit an existing robot

b = RobotBuilder().attach()        # the only robot, or attach("KR16")

jnt = b.robot.fpo.RobotJoints[2]
b.flip_joint(jnt)                  # re-mate from the other face side

rob = b.finish()

Back: TrajectoryApi · Next: Scripting API

Clone this wiki locally