Lego bricks in FreeCAD

Here's the place for discussion related to coding in FreeCAD, C++ or Python. Design, interfaces and structures.
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
User avatar
mase
Posts: 29
Joined: Thu Jun 25, 2015 9:31 am

Lego bricks in FreeCAD

Post by mase »

People of FreeCAD
----------------------

SO.... What about to create a LEGO BRICK libary for FreeCAD :)



The aim for this projekt is learning useful stuff:
[*] get use to with freecad
[*] improving my english
[*] get use to git (maintaining the libary)
[*] And MAYBE create addon for adding the lego bricks and to put them together.

Help is very much appreciated. I would be happy to have some feedback about my drawings.
[*] right measurements about the bricks
[*] opinion about the constructions ( how they are made)
[*] opinion about the construction is properly draw. (I read that in an .fcstd u can verify how the construction is drawn)
Here is the url of the legolib https://github.com/mase-tech/FreeCAD-LEGO


Feel free to suggest, help and correct me :)

kindly greetings from germany
mase
Last edited by mase on Tue Jul 21, 2015 1:34 pm, edited 18 times in total.
Feel free to visit :)

axonometric branch https://github.com/mase-tech/FreeCAD/tr ... etric_view
User avatar
microelly2
Veteran
Posts: 4688
Joined: Tue Nov 12, 2013 4:06 pm
Contact:

Re: Lego bricks in FreeCAD

Post by microelly2 »

schöne idee

maybe that you want to improve my ideas of a brick factory
http://freecadbuch.de/doku.php?id=blog: ... _bausteine
I think this kind of toys is a good way to learn parametric modeling and the benefits of FreeCAD

another interesting project is a tool for wood connections:
starting here
http://www.selbst.de/moebel-holz-artike ... 41509.html
User avatar
mase
Posts: 29
Joined: Thu Jun 25, 2015 9:31 am

Re: Lego bricks in FreeCAD

Post by mase »

schöne idee
find ich auch :) . ich habe mir gestern nacht noch deine seite angeschaut und deine youtube videos. gefällt mir!
Feel free to visit :)

axonometric branch https://github.com/mase-tech/FreeCAD/tr ... etric_view
ulrich1a
Veteran
Posts: 1957
Joined: Sun Jul 07, 2013 12:08 pm

Re: Lego bricks in FreeCAD

Post by ulrich1a »

There may be a lot of people, who have played with lego-bricks including me. Are you aware of leocad?: http://www.leocad.org/trac
There exists already a large library of lego-bricks. Allthough this library states, it does not have exact dimensions of the lego-bricks. This would of course be necessary for FreeCAD. And it would be fun, if one day the 3D-printers, you can afford to buy, are exact enough to print usable leo-bricks.
If one would write an importer to FreeCAD for this library, you will have more bricks, than you ever had as real parts.

Ulrich
User avatar
mase
Posts: 29
Joined: Thu Jun 25, 2015 9:31 am

Re: Lego bricks in FreeCAD

Post by mase »

If one would write an importer to FreeCAD for this library, you will have more bricks, than you ever had as real parts.
Very good idea. But I aim to use freecad to draw the lego pieces. Btw thanks for the link leocad.

The first step is to measure the bricks and draw them. Then the community should correct them. At the point we have enough stones I will try to modify the assembly module for fast lego contructions.
Feel free to visit :)

axonometric branch https://github.com/mase-tech/FreeCAD/tr ... etric_view
User avatar
wandererfan
Veteran
Posts: 6265
Joined: Tue Nov 06, 2012 5:42 pm
Contact:

Re: Lego bricks in FreeCAD

Post by wandererfan »

http://www.forum.freecadweb.org/viewtop ... ego#p56816
http://www.thingiverse.com/thing:20778

Somebody once made a "Lego.py". I found this in my files, but I can't find the original post. It's very slow.

Code: Select all

import FreeCAD,Part,math

class Lego:
    '''return a lego brick'''
    def __init__(self,obj, unitsX=4, unitsY=2,unitsZ=1,modifier=0):
        obj.addProperty("App::PropertyInteger","unitsX","Lego","Size in knobs in X direction.").unitsX = unitsX
        obj.addProperty("App::PropertyInteger","unitsY","Lego","Size in knobs in Y direction.").unitsY = unitsY
        obj.addProperty("App::PropertyInteger","unitsZ","Lego","Size in knobs in Z direction.").unitsZ = unitsZ
        obj.addProperty("App::PropertyInteger","modifier","Lego","Variant No ").modifier = modifier
        obj.Proxy = self

    def onChanged(self, fp, prop):
        "Do something when a property has changed"
        pass

    def execute(self, fp):
        fp.Shape=Lego.buildshape(fp.unitsX, fp.unitsY, fp.unitsZ,fp.modifier)

    @staticmethod
    def buildshape(unitsX, unitsY,unitsZ,modifier):
        gap=0.1
        gaps=2*gap
        unitSize = 8
        height=9.6
        knobHeight=1.8
        knobRadius=4.8/2
        wall=1.5
        upWall=5.5 #// guessed
        supportthickness=0.6 # 0.15x4 or 0.20x3
        maxsupportlayerthickness=0.15
        supportdistance=4 # 4x4=16mm^2, printer option
        cylRadius = (unitSize*math.sqrt(2)-2*knobRadius)/2 #0000003,2568542494923801952067548968388
        cylWall = round(3.25685,5)
        l=unitSize*unitsX-gaps
        w= unitSize*unitsY-gaps
        c1=Part.makeBox(l, w, height,FreeCAD.Vector(-l/2.0,-w/2.0,0))
        c2=Part.makeBox(l-gaps-2*wall, w-gaps-2*wall, height,FreeCAD.Vector(-(l-gaps-2*wall)/2.0,-(w-gaps-2*wall)/2.0,-1*upWall))
        d1=c1.cut(c2)
        shape1=d1 # box
        knobs=Part.Shape()
# shape1=Part.Shape()#makeBox(1,1,1)
        knob=Part.makeCylinder(knobRadius,knobHeight+upWall/2,FreeCAD.Vector(0,0,height-upWall/2.0))
        for x in range(unitsX):
            for y in range(unitsY):
                newknob=knob.copy()
                newknob.translate((x*unitSize, y*unitSize, 0))
                if knobs.isNull():
                    knobs=newknob
                else:
                    knobs=knobs.fuse(newknob)
        knobs.translate(((1-unitsX)*unitSize/2, (1-unitsY)*unitSize/2, 0))
        if (unitsX > 1 and unitsY > 1)or(modifier==-1):
            cyl=Part.makeCylinder(cylRadius,height-upWall/2 ).cut(Part.makeCylinder(cylRadius-cylWall,height))
            cyl.translate((0,0,upWall/8))
            cyls=Part.Shape()
            for x in range(unitsX-1):
                for y in range(unitsY-1):
                    newcyl=cyl.copy()
                    newcyl.translate((x*unitSize, y*unitSize, 0))
                    if cyls.isNull():
                        cyls=newcyl
                    else:
                        cyls=cyls.fuse(newcyl)
            cyls.translate(((2-unitsX)*unitSize/2, (2-unitsY)*unitSize/2, 0))
    
            if modifier==2: #
                newknobs=knobs.copy() #
                newknobs.translate((0,0,height*unitsZ-height)) #
                shape1=shape1.fuse(newknobs) #
# return shape1 #
            for x in my_range(1,unitsX,2):
                 zmodifier=0
                 if modifier<=0:
                     zmodifier=0
                 else:
                     zmodifier=1
                 carrycy =Part.makeCylinder(unitSize/2,height*unitsZ-height ) # height+ # *(1-zmodifier)
                 carrycy.translate((unitSize*unitsX/2-x*unitSize,-unitSize/2-wall,height))
                 wallnearwallbase=Part.makeBox(l, w, height,FreeCAD.Vector(-l/2.0,-w/2.0+unitSize*unitsY,0)) #-wall*(1-zmodifier)
                 wallnearwall=Part.makeBox(l-gaps-2*wall, w-gaps-2*wall, height,FreeCAD.Vector(-(l-gaps-2*wall)/2.0,-(w-gaps-2*wall)/2.0+unitSize*unitsY,-1*upWall))
                 shape1=shape1.fuse(carrycy) # carry cylynder
                 wallnearwallbase=wallnearwallbase.cut(wallnearwall)#knobs=knobs.cut(wallnearwall)
                 wallnearwallbase.translate((0,-unitSize*unitsY,height*unitsZ-height))
                 if zmodifier==0:
                     shape1=shape1.cut(wallnearwallbase)#knobs=knobs.cut(wallnearwall)
                 else:
                     shape1=shape1.fuse(wallnearwallbase)#knobs=knobs.cut(wallnearwall)
# else:
            c1_=Part.makeBox(l, wall, height*unitsZ,FreeCAD.Vector(-l/2.0,-w/2.0-wall*2,0))
            c2_=Part.makeBox(l, wall, height,FreeCAD.Vector(-l/2.0,-w/2.0-wall,0))
            shape1=shape1.fuse(c2_) # side panel base
            shape1=shape1.fuse(c1_) # side panel
#.fuse(c1_)
            shape1=shape1.fuse(knobs)#
            shape1=shape1.fuse(cyls)#.removeSplitter() #
# shape=shape.fuse(shape1)
# shape=knobs.fuse(d1).removeSplitter()
        else:
            shape1=knobs.fuse(d1).removeSplitter()
        #Part.show(d1.common(cyls))
        
        for x in my_range(1,unitsX*unitSize,supportdistance): #
            origvector=FreeCAD.Vector(-l/2.0+x,-w/2.0-1,-2*supportthickness)
            support=Part.makeBox(supportthickness,w+2,height-upWall-maxsupportlayerthickness+2*supportthickness,origvector)
            support1=Part.makeBox(supportthickness/2,w+2,height-upWall+2*supportthickness,origvector)
            xoffset=0
            yoffset=0
            for ttranslation in range(1,9): # [1,2,3,4,5,6,7,8]
                if ttranslation==1:
                    xoffset=0
                    yoffset=1
                elif ttranslation==2:
                    xoffset=1
                    yoffset=0
                elif ttranslation==3:
                    xoffset=1
                    yoffset=1
                elif ttranslation==4:
                    xoffset=-1
                    yoffset=1
                elif ttranslation==5:
                    xoffset=-1
                    yoffset=-1
                elif ttranslation==6:
                    xoffset=-1
                    yoffset=0
                elif ttranslation==7:
                    xoffset=0
                    yoffset=-1
                elif ttranslation==8:
                    xoffset=1
                    yoffset=-1
# elif ttranslation==2:
# xoffset=1
# elif ttranslation==2:
# xoffset=1
                zOffset = 0.0001
                support.translate((+xoffset,+yoffset,zOffset)) ########################## here
                support1.translate((+xoffset,+yoffset,zOffset)) #
                support=support.cut(shape1)
                support1=support1.cut(shape1)
                support.translate((-xoffset,-yoffset,zOffset)) #
                support1.translate((-xoffset,-yoffset,zOffset)) #
            shape1=shape1.fuse(support)
            shape1=shape1.fuse(support1)
        return shape1

def my_range(start, end, step):
    while start <= end:
        yield start
        start += step
def makeLego(x,y,z,modifier,doc=None):
    doc = doc or FreeCAD.ActiveDocument
    obj=doc.addObject("Part::FeaturePython","Lego")
    Lego(obj)
    obj.unitsX=x
    obj.unitsY=y
    obj.unitsZ=z
    obj.modifier=modifier
    obj.ViewObject.Proxy=0 # just set it to something different from None (this assignment is needed to run an internal notification)
    return obj
            
if __name__ == '__main__':
    #nonparametric
    #Part.show(Lego.buildshape(4,2))
    #parametric
# modifier -1 - mono rail
# modifier 0 - -1 wall
# modifier 1 - full mono wall, upper solid
    makeLego(8,2,6,2)
# makeLego(8,2)
# makeLego(16,2)
User avatar
mase
Posts: 29
Joined: Thu Jun 25, 2015 9:31 am

Re: Lego bricks in FreeCAD

Post by mase »

hey people in need help, in terms of which liscence should I use for the "lego-brick" libary projekt.

Because the name lego is a trademarke, so I don't know which liscence I should use.

Is it legal to draw the lego bricks and get them online. And what about if I develop a lego WB for FreeCAD.
Feel free to visit :)

axonometric branch https://github.com/mase-tech/FreeCAD/tr ... etric_view
triplus
Veteran
Posts: 9471
Joined: Mon Dec 12, 2011 4:45 pm

Re: Lego bricks in FreeCAD

Post by triplus »

mase wrote:hey people in need help, in terms of which liscence should I use for the "lego-brick" libary projekt.

Because the name lego is a trademarke, so I don't know which liscence I should use.

Is it legal to draw the lego bricks and get them online. And what about if I develop a lego WB for FreeCAD.
I am not sure and what you could do is to ask them. In general i think you shouldn't use Lego name and bricks you provide should be different.
User avatar
r-frank
Veteran
Posts: 2180
Joined: Thu Jan 24, 2013 6:26 pm
Location: Möckmühl, Germany
Contact:

Re: Lego bricks in FreeCAD

Post by r-frank »

Hello.

Perhaps you should first have a look at Ldraw.org.
For english people Lugnet.com is a good place to start LEGO Exploration ...
German speaking people may consider to pay 1000Steine.de a visit.
You could also have a look at the different CAD's for Lego like
> LeoCAD
> MLCAD
> and more

how they handle these things ...

Roland
Deutsche FreeCAD Tutorials auf Youtube
My GrabCAD FreeCAD-Projects
FreeCAD lessons for beginners in english

Native german speaker - so apologies for my english, no offense intended :)
triplus
Veteran
Posts: 9471
Joined: Mon Dec 12, 2011 4:45 pm

Re: Lego bricks in FreeCAD

Post by triplus »

Yes probably adding support:

viewtopic.php?t=5637

To import already existing work could work. But as @r-frank suggested it might make sense to get in touch with that community first to get more info.
Post Reply