Skip to content

Instantly share code, notes, and snippets.

@5263
5263 / mink2offset.py
Created February 15, 2014 14:03
Convert FreeCAD Minkowski Sum Features to Offset Features
import FreeCAD,OpenSCADFeatures
for obj in FreeCAD.ActiveDocument.Objects:
if obj.TypeId == "Part::FeaturePython" and hasattr(obj,'Proxy') and isinstance(obj.Proxy,OpenSCADFeatures.CGALFeature) \
and len(obj.Children) == 2:
print [(child.TypeId,child.PropertiesList) for child in obj.Children]
if obj.Children[0].TypeId in ['Part::Cylinder','Part::Sphere']:
OpenSCADFeatures.OffsetShape(obj,obj.Children[1],float(obj.Children[0].Radius))
obj.touch()
elif obj.Children[1].TypeId in ['Part::Cylinder','Part::Sphere']:
OpenSCADFeatures.OffsetShape(obj,obj.Children[0],float(obj.Children[1].Radius))
@5263
5263 / wire2bez.py
Last active August 29, 2015 13:56
FreeCAD Macro to convert a wire into a piecevise Bezier curve
import FreeCAD
def segments2points(segments,degree):
pts=segments[0].getPoles()[0:1]
for seg in segments:
if seg.Degree < degree:
seg.Increase(degree)
pts.extend(seg.getPoles()[1:])
return pts
@5263
5263 / diffblame.py
Created February 1, 2014 13:42
git blame on git diff results
#!/usr/bin/env python
"""usage: diffblame.py START..END [path]"""
import os,sys,subprocess
gitpath = subprocess.Popen(["git", "rev-parse","--show-toplevel"],\
stdout=subprocess.PIPE).communicate()[0].strip()
diff = subprocess.Popen(["git", "diff","-U0"]+sys.argv[1:],\
stdout=subprocess.PIPE).communicate()[0]
for l in diff.splitlines():
if l=='':
@5263
5263 / piscator.py
Last active December 17, 2015 17:49
Import ft designer (*.ftm) files into FreeCAD
import os
if open.__module__ == '__builtin__':
pythonopen = open # to distinguish python built-in open function from the one declared here
ftdpath='C:/Program Files (x86)/fischertechnik designer'
partnamelang='NAME' #german
#partnamelang='ENG' #english
@5263
5263 / dtg.py
Last active December 12, 2015 10:08
Date/Time Group
def gettimeszonestg(tz,dt1=None):
if tz is None:
return 'J'
else:
utco=tz.utcoffset(dt1)
if utco.days>=0:
tzg = 'ZABCDEFGHIKLM'[utco.seconds//3600]
else:
tzg = 'ZNOPQRSTUVWXY'[(-utco).seconds//3600]
if utco.seconds % 3600 == 1800:
@5263
5263 / decalc.py
Last active December 11, 2015 22:58
query the calc database
#/usr/bin/env python
import sqlite3
conn=sqlite3.connect('memento.sqlite')
cr=conn.cursor()
calcslist=cr.execute("SELECT * FROM `entry`").fetchall()
calcsdict=dict((entry[0].lower(),entry) for entry in calcslist)
conn.close()
if __name__ = '__main__':
import sys
@5263
5263 / testimport.py
Created January 15, 2013 17:30
Automaticly import and check OpenSCAD files into FreeCAD
import FreeCAD
import importCSG
#import prototype
importmod=importCSG
dirpath=''
def comparewithstl(filename,obj,doc):
# import MeshPart
import Mesh
import OpenSCADUtils
@5263
5263 / thingiverse1.py
Created January 9, 2013 23:05
thingiverse api experiments
token_type='Bearer'
access_token=''
baseurl='https://api.thingiverse.com/'
meurl='https://api.thingiverse.com/users/me'
import urllib2, base64
import json
def isfiletype(name,suffixes=('fcstd','scad','brep','brp')):
return any([name.lower().endswith(suffix) for suffix in suffixes])
@5263
5263 / decmagellan.py
Created July 29, 2012 09:01
Decode information from Magellan Serial 6-DOF input devices
#!/usr/bin/env python
#with information from http://paulbourke.net/dataformats/spacemouse/
smkeys=('1','2','3','4','5','6','7','8', '*','L','R','?')
nibble2sm=('0','A','B','3','D','5','6','G','H','9',':','K','<','M','N','?')
sm2nibble=dict(zip(nibble2sm,range(16)))
sm2nibble2=lambda x:ord(x) & 0xf
binary=False
def sm2coord(cstr):
@5263
5263 / hamster.py
Created July 13, 2012 16:46
start and end hamster activities by manipulationg the DB
#!/usr/bin/env python
import sqlite3,datetime,sys
def buildactdict(c):
c.execute('SELECT id,name from categories')
catdict=dict(((cat[0], cat[1]) for cat in c.fetchall()))
c.execute('SELECT id,name,category_id from activities')
actdict=dict(((act[0], '%s@%s' % (act[1],catdict.get(act[2]))) \
for act in c.fetchall()))
return actdict
def findunfinished(c):