0% found this document useful (0 votes)
2K views11 pages

Python Scripting Tutorial - FreeCAD Documentation

This document is a tutorial on Python scripting in FreeCAD, an open-source parametric 3D modeler. It covers basic concepts like creating documents, adding objects like boxes and modifying their properties. It also demonstrates working with vectors, meshes, importing other objects and manipulating them using Python modules. The tutorial shows how to display messages and includes examples of importing different Python libraries for tasks in FreeCAD.

Uploaded by

Bolarinwa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2K views11 pages

Python Scripting Tutorial - FreeCAD Documentation

This document is a tutorial on Python scripting in FreeCAD, an open-source parametric 3D modeler. It covers basic concepts like creating documents, adding objects like boxes and modifying their properties. It also demonstrates working with vectors, meshes, importing other objects and manipulating them using Python modules. The tutorial shows how to display messages and includes examples of importing different Python libraries for tasks in FreeCAD.

Uploaded by

Bolarinwa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
  • Introduction to Python Scripting: Provides an overview of using Python as a scripting language in FreeCAD, including basic setup instructions and benefits.
  • Using Python in FreeCAD: Explains how to execute Python scripts in FreeCAD, detailing script creation and modification processes.
  • Exploring FreeCAD: Covers the basics of navigating and using the FreeCAD Python console, with examples of macro creation.
  • FreeCAD Object Management: Focuses on object creation and attribute management within FreeCAD, illustrating property manipulation.
  • Vectors and Placements: Describes the concept of vectors in FreeCAD and their applications in positioning and aligning 3D objects.
  • App and GUI: Introduces the separation of components in FreeCAD's structure, emphasizing the GUI and visual elements interface.
  • Modules and Tools: Discusses various FreeCAD modules and tools such as Mesh and Sketcher, highlighting their uses in modeling and geometry.
  • Mesh and Part: Explores detailed creation and manipulation of mesh objects and parts, elaborating on scripting capabilities.
  • Drafting and Design: Details the drafting tools available in FreeCAD, focusing on adding shapes and adjusting geometries.
  • Interface and Macros: Explains the user interface and automation with macros, enhancing productivity through scripting in FreeCAD.
  • Additional Resources and Support: Lists additional resources, tutorials, and community forums for deeper engagement and help with FreeCAD and Python scripting.

Python scripting tutorial - FreeCAD Documentation

1 of 11

http://www.freecadweb.org/wiki/index.php?title=Python_scripting_tutorial

22/10/2016 08:06

Python scripting tutorial - FreeCAD Documentation

2 of 11

http://www.freecadweb.org/wiki/index.php?title=Python_scripting_tutorial

22/10/2016 08:06

Python scripting tutorial - FreeCAD Documentation

3 of 11

http://www.freecadweb.org/wiki/index.php?title=Python_scripting_tutorial

doc= FreeCAD.newDocument()

22/10/2016 08:06

Python scripting tutorial - FreeCAD Documentation

4 of 11

http://www.freecadweb.org/wiki/index.php?title=Python_scripting_tutorial

doc.

box=doc.addObject("Part::Box","myBox")

doc.recompute()

22/10/2016 08:06

Python scripting tutorial - FreeCAD Documentation

5 of 11

http://www.freecadweb.org/wiki/index.php?title=Python_scripting_tutorial

doc.supportedTypes()

box.

box.Height

box.Height = 5

myvec= FreeCAD.Vector(2,0,0)
myvec
myvec.x
myvec.y
othervec= FreeCAD.Vector(0,3,0)
sumvec=myvec.add(othervec)

box.Placement.
box.Placement.Base
box.Placement.Base =sumvec

otherpla= FreeCAD.Placement()
box.Placement =otherpla

22/10/2016 08:06

Python scripting tutorial - FreeCAD Documentation

6 of 11

http://www.freecadweb.org/wiki/index.php?title=Python_scripting_tutorial

vo=box.ViewObject

vo.Transparency = 80
vo.hide()
vo.show()

22/10/2016 08:06

Python scripting tutorial - FreeCAD Documentation

7 of 11

http://www.freecadweb.org/wiki/index.php?title=Python_scripting_tutorial

doc.supportedTypes()

import Part
Part.

22/10/2016 08:06

Python scripting tutorial - FreeCAD Documentation

8 of 11

http://www.freecadweb.org/wiki/index.php?title=Python_scripting_tutorial

import Mesh
mymesh= Mesh.createSphere()
mymesh.
mymesh.Facets
mymesh.Points

meshobj=doc.addObject("Mesh::Feature","MyMesh")
meshobj.Mesh =mymesh
doc.recompute()

22/10/2016 08:06

Python scripting tutorial - FreeCAD Documentation

9 of 11

http://www.freecadweb.org/wiki/index.php?title=Python_scripting_tutorial

import Part
myshape= Part.makeSphere(10)
myshape.
myshape.Volume
myshape.Area
shapeobj=doc.addObject("Part::Feature","MyShape")
shapeobj.Shape =myshape
doc.recompute()

Part.show(myshape)

import Draft
Draft.
rec= Draft.makeRectangle(5,2)
mvec= FreeCAD.Vector(4,4,0)
Draft.move(rec,mvec)
Draft.move(box,mvec)

22/10/2016 08:06

Python scripting tutorial - FreeCAD Documentation

10 of 11

http://www.freecadweb.org/wiki/index.php?title=Python_scripting_tutorial

from PySide import QtGui


QtGui.QMessageBox.information(None,"Apolloprogram","Houston,wehaveaproblem")

22/10/2016 08:06

Python scripting tutorial - FreeCAD Documentation

11 of 11

http://www.freecadweb.org/wiki/index.php?title=Python_scripting_tutorial

22/10/2016 08:06

Python scripting tutorial - FreeCAD Documentation
http://www.freecadweb.org/wiki/index.php?title=Python_scripting_tutorial
1
Python scripting tutorial - FreeCAD Documentation
http://www.freecadweb.org/wiki/index.php?title=Python_scripting_tutorial
2
doc = FreeCAD.newDocument()
Python scripting tutorial - FreeCAD Documentation
http://www.freecadweb.org/wiki/index.php?title=
doc.
box = doc.addObject("Part::Box","myBox")
doc.recompute()
Python scripting tutorial - FreeCAD Documentation
http://www.fr
doc.supportedTypes()
box.
box.Height
box.Height = 5
myvec = FreeCAD.Vector(2,0,0)
myvec
myvec.x
myvec.y
othervec = FreeCAD.Ve
vo = box.ViewObject
vo.Transparency = 80
vo.hide()
vo.show()
Python scripting tutorial - FreeCAD Documentation
http://www.fre
doc.supportedTypes()
import Part
Part.
Python scripting tutorial - FreeCAD Documentation
http://www.freecadweb.org/wiki/index
import Mesh
mymesh = Mesh.createSphere()
mymesh.
mymesh.Facets
mymesh.Points
 
meshobj = doc.addObject("Mesh::Feature","MyMes
import Part
myshape = Part.makeSphere(10)
myshape.
myshape.Volume
myshape.Area
shapeobj = doc.addObject("Part::Feature","MySh
from PySide import QtGui
QtGui.QMessageBox.information(None,"Apollo program","Houston, we have a problem")
Python scripting t

You might also like