FreeCAD & Python | Using the API for automation
Introduction to FreeCAD Python API. Automate the creation of parts from a CSV (or database) - In this video I use Pandas to read a CSV and send the values as variables into FreeCAD.
The FreeCAD code is programmed mainly in C++, but relies heavily on Python
The FreeCAD source code is fully multi-platform
FreeCAD can be compiled and run without its Graphical User Interface, the code in App is independent of any GUI-related library
-solid core functionality is programmed in C++ and end-user tools are written in Python
-To get started we will look at creating parts from a CSV, without using the GUI
-This could be useful for 3d printing, eg export files as .stl
Example of what can be made with FreeCAD :
? https://forum.freecadweb.org/viewtopic.php?f=24&t=59466
FreeCAD API official documentation
? https://wiki.freecadweb.org/FreeCAD_API
TL;DW
conda install PyQt
? https://anaconda.org/anaconda/pyqt
Install FreeCAD:
? https://forum.freecadweb.org/viewtopic.php?f=4&t=56744
? https://anaconda.org/freecad/freecad
git clone https://github.com/FreeCAD/FreeCAD.git freecad-source
(get the dependencies using your method of choice)
mkdir freecad-build
cd freecad-build
cmake ../freecad-source
make
sudo make install
or
sudo add-apt-repository -y ppa:freecad-maintainers/freecad-stable
sudo apt-get update
sudo apt-get install freecad
Download Macro:
? https://wiki.freecadweb.org/Macro_Pyramid
Run from command line - no GUI!
-------------------------------------------------------------
# Example Code: file is called fc.py
#+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
#|r|e|d|a|n|d|g|r|e|e|n|.|c|o|.|u|k|
#+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
import FreeCAD as App
#from PySide import QtGui
import pandas as pd
df = pd.read_csv("c.csv") # (read from SQL eventually)
j = len(df)
for i in range(0,j):
fn =(df.iloc[i]['name'])
lw =(df.iloc[i]['width'])
lh =(df.iloc[i]['height'])
# Make new document for each part - per line of CSV
doc = App.newDocument()
doc.FileName = fn + ".FCStd"
App.ActiveDocument.addObject("Part::Box","Box")
App.ActiveDocument.ActiveObject.Label = "Cube"
App.ActiveDocument.recompute()
#Gui.SendMsgToActiveView("ViewFit")
# Uses object called by internal name 'Box'
my_box = FreeCAD.ActiveDocument.getObject('Box')
my_box.Height = float(lw)
my_box.Width = float(lh)
doc.save()
-------------------------------------------------------------
Run with example data file : "c.csv"
name,height,width
a1,10,33
a2,3,44
a3,8,28
a4,14,38
-------------------------------------------------------------
From cli type:
[rag@~]$ freecadcmd fc.py
It will make 4 parts, with sizes as per your csv.
-------------------------------------------------------------
Visit redandgreen blog for more Tutorials
=========================================
? http://redandgreen.co.uk/about/blog/
Subscribe to the YouTube Channel
=================================
? https://www.youtube.com/c/DrPiCode
Follow on Twitter - to get notified of new videos
=================================================
? https://twitter.com/RngWeb
? Become a patron ?
? https://www.patreon.com/drpi
Buy Dr Pi a coffee (or Tea)
☕ https://www.buymeacoffee.com/DrPi
Proxies
=================================================
If you need a good, easy to use proxy, I was recommended this one, and having used ScraperAPI for a while I can vouch for them. If you were going to sign up anyway, then maybe you would be kind enough to use the link and the coupon code below?
You can also do a full working trial first as well, (unlike some other companies). The trial doesn't ask for any payment details either so all good! ?
? 10% off ScraperAPI : https://www.scraperapi.com?fpr=ken49
◼️ Coupon Code: DRPI10
(You can also get started with 1000 free API calls. No credit card required.)
Thumbs up yeah? (cos Algos..)
#freecad #tutorial #python
Видео FreeCAD & Python | Using the API for automation автора Компуктерные гонщики
Видео FreeCAD & Python | Using the API for automation автора Компуктерные гонщики
Информация
1 декабря 2023 г. 0:26:56
00:21:15
Похожие видео