Skip to content

Instantly share code, notes, and snippets.

View yorikvanhavre's full-sized avatar

Yorik van Havre yorikvanhavre

View GitHub Profile
f = open("/path/to/myfile.ncc")
s1 = f.read()
from PathScripts import pre_example
s2 = pre_example.parse(s1)
import Path
p = Path.Path(s2)
@yorikvanhavre
yorikvanhavre / getTool
Created December 21, 2014 16:12
a getTool function for parametric paths
def getTool(self,obj,number=0):
"retrieves a tool from a hosting object with a tooltable, if any"
for o in obj.InList:
if hasattr(o,"Tooltable"):
return o.Tooltable.getTool(number)
# not found? search one level up
for o in obj.InList:
return self.getTool(o,number)
return None
class ViewProviderPath:
def __init__(self,vobj): #mandatory
obj.addProperty("App::PropertyFloat","SomePropertyName","PropertyGroup","Description of this property")
obj.Proxy = self
def __getstate__(self): #mandatory
return None
def __setstate__(self,state): #mandatory
def export(objectslist,filename):
gfile = open(filename,"wb") # open the file with write permission
for obj in objectslist:
if hasattr(obj,"Path"): # not all objects might be paths
gfile.write(obj.Path.toGCode()) # this simply dumps the path data as internal gcode
commands = obj.Path.Commands # but we could also do stuff with the commands list
gfile.close()
print "successfully exported " + filename
@yorikvanhavre
yorikvanhavre / soclipplane
Created February 27, 2015 20:50
Add a SoClipPlane to the FreeCAD view with Pivy
>>> from pivy import coin
>>> sg=Gui.ActiveDocument.ActiveView.getSceneGraph()
>>> clip = coin.SoClipPlane()
>>> clip.on.setValue(False)
>>> plane = coin.SbPlane(coin.SbVec3f(0,0,1),1000)
>>> plane
<pivy.coin.SbPlane; proxy of <Swig Object of type 'SbPlane *' at 0x7fd8424b62a0> >
>>> clip.plane.setValue(plane)
>>> sg.addChild(clip)
>>> clip.on.setValue(True)
@yorikvanhavre
yorikvanhavre / convert.sh
Created July 28, 2015 18:04
replace colors in librecad icons
convert zoomwindow.png -fill darkgrey -transparent white -fuzz 50% -fill white -opaque black test.png
@yorikvanhavre
yorikvanhavre / getrecentfiles.py
Last active August 2, 2018 12:40
get list of recent documents in linux
#!/usr/bin/python
# -*- coding: UTF-8 -*-
import re,os,gtk,gio,magic
def geticon(filename):
m = magic.open(magic.MAGIC_MIME)
m.load()
mime = m.file(filename).split(";")[0]
mime = gio.content_type_get_icon(mime).get_names()
@yorikvanhavre
yorikvanhavre / openfoam_obj_exporter.py
Created January 24, 2016 15:21
An openFOAM-tailored OBJ exporter for FreeCAD
#***************************************************************************
#* *
#* Copyright (c) 2015 *
#* Yorik van Havre <[email protected]> *
#* *
#* This program is free software; you can redistribute it and/or modify *
#* it under the terms of the GNU Lesser General Public License (LGPL) *
#* as published by the Free Software Foundation; either version 2 of *
#* the License, or (at your option) any later version. *
#* for detail see the LICENCE text file. *
@yorikvanhavre
yorikvanhavre / mdview.php
Created March 3, 2016 15:45
This script generates a nice HTML rendering of a Markdown file that is hosted and shared on an owncloud server, using strapdownjs.com.
<?php
// mdview.php by Yorik van Havre, GPL license
// This script generates a nice HTML rendering of a Markdown file that is hosted and
// shared on an owncloud server, using strapdownjs.com.
// To use it, simply place this file somewhere on your web space, and call it with the
// following arguments: http://path/to/mdview.php?file=XXXXXXXX&theme=spacelab
// the XXXXXXX is the share code from the link you obtain when sharing a file in owncloud.
// theme is optional, and can be one of the themes described on strapdownjs.com. If not
// provided, the spacelab theme is used (with a bit of changes I did in the <style> tag below)
@yorikvanhavre
yorikvanhavre / fetch.py
Created June 2, 2016 18:09
sample fetch script for freecad
class plugin:
author = "xyz"
type = "macro"
description = "this plugin does this"
baseurl = "http://github.com/mymacro"
infourl = "http://github.com/mymacro/README.md"
class Fetch:
def __init__():