Strumenti Utente



tutorial_freecad:playground

Tutorial FreeCAD Playground

Macro freecad

Stampa funzioni

# F = variable used in the function,
# X = initial value of x,
# Nb = Number of step,
# Z = function express with x
# ZZ = function express with xx
 
import FreeCAD, FreeCADGui, Part
import math

F=800
X=-500
Nb=10
Step=1000/Nb
Y=0
for I in range(Nb):
    XX=X+Step 
    Z=X*X/(4*F)
    ZZ=XX*XX/(4*F)
    if I==0:
        print "Le test est vrai !"
        nomme=Part.makeLine((X,Y,Z),(XX,Y,ZZ))
        WWire=Part.Wire([nomme])
    else:
        print "Le test est 2 !"
        nomme=Part.makeLine((X,Y,Z),(XX,Y,ZZ))		
        WWire=Part.Wire([WWire,nomme])
    X=XX 

Part.show(WWire)

FreeCAD and pyQt

import FreeCAD, FreeCADGui, Part
from PyQt4 import QtGui,QtCore
 
def proceed():
    try:
        u = (int(l1.text()),float(l2.text()))   
        v = (int(l3.text()),float(l4.text()))
    except:
        FreeCAD.Console.PrintError("Wrong input! Only numbers allowed...\n")
    sel = FreeCADGui.Selection.getSelection()
    if sel:
        sel = sel[0]
        name = sel.Name   
        shape = sel.Shape
        for column in range(u[0]):
            for row in range(v[0]):
                if (column != 0) or (row != 0):
                    delta = FreeCAD.Vector(column*u[1],row*v[1],0)
                    newshape = sel.Shape.copy()
                    newshape.translate(delta)
                    newobject = FreeCAD.ActiveDocument.addObject("Part::Feature",name)
                    newobject.Shape = newshape
    else:
        FreeCAD.Console.PrintError("Error: One object must be selected")
    hide()

def hide():
    dialog.hide()

dialog = QtGui.QDialog()
dialog.resize(200,300)
dialog.setWindowTitle("Array")
la = QtGui.QVBoxLayout(dialog)
t1 = QtGui.QLabel("number of columns")
la.addWidget(t1)
l1 = QtGui.QLineEdit()
la.addWidget(l1)
t2 = QtGui.QLabel("distance between columns")
la.addWidget(t2)
l2 = QtGui.QLineEdit()
la.addWidget(l2)
t3 = QtGui.QLabel("number of rows")
la.addWidget(t3)
l3 = QtGui.QLineEdit()
la.addWidget(l3)
t4 = QtGui.QLabel("distance between rows")   
la.addWidget(t4)
l4 = QtGui.QLineEdit()
la.addWidget(l4)
okbox = QtGui.QDialogButtonBox(dialog)
okbox.setOrientation(QtCore.Qt.Horizontal)
okbox.setStandardButtons(QtGui.QDialogButtonBox.Cancel|QtGui.QDialogButtonBox.Ok)
la.addWidget(okbox)
QtCore.QObject.connect(okbox, QtCore.SIGNAL("accepted()"), proceed)
QtCore.QObject.connect(okbox, QtCore.SIGNAL("rejected()"), hide)
QtCore.QMetaObject.connectSlotsByName(dialog)
dialog.show()

Barra filettata

Codice per creare una barra filettata (tratto da http://forum.freecadweb.org/viewtopic.php?f=3&t=1461)

import Part, FreeCAD, math
from FreeCAD import Base

d = 20.0
p = 2.5
h = p/2

r = d / 2.0
hp = p * math.tan(math.pi/3.0)
dmin = d - 5.0 * hp /8.0
rmin = dmin / 2.0

edges = []
z1 = p/8.0
z2 = 7.0*p/16.0
rmax = r*1.05
edges.append( Part.makeLine((rmin,0,z1), (rmin,0,-z1)) )
edges.append( Part.makeLine((rmin,0,-z1), (r,0,-z2)) )
edges.append( Part.makeLine((r,0,-z2), (rmax,0,-z2)) )
edges.append( Part.makeLine((rmax,0,-z2), (rmax,0,z2)) )
edges.append( Part.makeLine((rmax,0,z2), (r,0,z2), ) )
edges.append( Part.makeLine((r,0,z2), (rmin,0,z1)) )
extSection = Part.Wire( edges )
helix = Part.makeHelix(p,h,r)
makeSolid = True
isFrenet = True
extSolid = helix.makePipeShell([extSection],makeSolid,isFrenet)

intSolid = Part.makeCylinder(r,h,Base.Vector(0,0,0),Base.Vector(0,0,1))

screw = intSolid.cut(extSolid)

Part.show(screw)
import Part, FreeCAD, math
from FreeCAD import Base

def drawHelix(p, h, r):
      edges = []
      nSpire = int(h / p)
      nStep = 16
      t = 0.0
      Dt = 2 * math.pi / nStep
      p1 = (r*math.cos(t), r*math.sin(t), p*t/(2.0*math.pi) )
      p2 = (r*math.cos(t+Dt), r*math.sin(t+Dt), p*(t+Dt)/(2.0*math.pi) )
      for i in range(nSpire*nStep):
          edges.append( Part.makeLine(p1, p2) )
          t += Dt
          p1 = (r*math.cos(t), r*math.sin(t), p*t/(2.0*math.pi) )
          p2 = (r*math.cos(t+Dt), r*math.sin(t+Dt), p*(t+Dt)/(2.0*math.pi) )
      return Part.Wire( edges )

d = 18.0
p = 2.5
h = 10.0

r = d / 2.0
hp = p * math.tan(math.pi/3.0)
dmin = d - 5.0 * hp /8.0
rmin = dmin / 2.0

edges = []
z1 = p/8.0
z2 = 7.0*p/16.0
rmax = r*1.05
edges.append( Part.makeLine((rmin,0,z1), (r,0,z2)) )
# edges.append( Part.makeLine((r,0,z2), (rmax,0,z2)) )
# edges.append( Part.makeLine((rmax,0,z2), (rmax,0,-z2)) )
# edges.append( Part.makeLine((rmax,0,-z2), (r,0,-z2)) )
edges.append( Part.makeLine((r,0,z2), (r,0,-z2)) )
edges.append( Part.makeLine((r,0,-z2), (rmin,0,-z1)) )
edges.append( Part.makeLine((rmin,0,-z1), (rmin,0,z1)) )
extSection = Part.Wire( edges )
// helix = Part.makeHelix(p,h,r)
helix = drawHelix(p,h,r)
makeSolid = True
isFrenet = True
extSolid = helix.makePipeShell([extSection],makeSolid,isFrenet)

intSolid = Part.makeCylinder(r,h,Base.Vector(0,0,0),Base.Vector(0,0,1))

screw = intSolid.cut(extSolid)

Part.show(screw)
import Part, FreeCAD, math
from FreeCAD import Base

d = 5.0
h = 10.0
p = 2.5
r = d/2.0
helix = Part.makeHelix(1,h,r)
edges = []
edges.append( Part.makeLine((2.5,0,-0.125), (2.5,0,0.125)) )
edges.append( Part.makeLine((2.5,0,0.125), (3.1,0,0.419)) )
edges.append( Part.makeLine((3.1,0,0.419), (3.1,0,-0.419)) )
edges.append( Part.makeLine((3.1,0,-0.419), (2.5,0,-0.125)) )
section = Part.Wire(edges)
makeSolid=True
isFrenet=True
pipe = Part.Wire(helix).makePipeShell([section],makeSolid,isFrenet)

cylinder = Part.makeCylinder(r,h,Base.Vector(0,0,0),Base.Vector(0,0,1))

diff = cylinder.cut(pipe)

Part.show(diff)

longHelix bug:

import Part, FreeCAD, math
from FreeCAD import Base

d = 20.0
r1 = d/2
r2 = r1 - 2.0
p = 10.0
h = 5*p
h1 = 5.0
helixExtBot = Part.makeHelix(p,h,r1)
helixExtUp = Part.makeHelix(p,h,r1)
helixExtUp.translate((0,0,h1))
helixIntBot = Part.makeHelix(p,h,r2)
helixIntUp = Part.makeHelix(p,h,r2)
helixIntUp.translate((0,0,h1))
lBotBot = Part.makeLine((r1, 0, 0),(r2, 0, 0))
lBotUp = Part.makeLine((r1, 0, h1),(r2, 0, h1))
lUpBot = Part.makeLine((r1, 0, h),(r2, 0, h))
lUpUp = Part.makeLine((r1, 0, h+h1),(r2, 0, h+h1))

vertExt = Part.makeRuledSurface(helixExtBot, helixExtUp)
vertInt = Part.makeRuledSurface(helixIntBot, helixIntUp)
horBot = Part.makeRuledSurface(helixExtBot, helixIntBot)
horUp = Part.makeRuledSurface(helixExtUp, helixIntUp)
retBot = Part.makeRuledSurface(lBotBot, lBotUp)
retUp = Part.makeRuledSurface(lUpBot, lUpUp)

shell = Part.makeShell( [vertExt.Faces[0], vertInt.Faces[0], horBot.Faces[0], horUp.Faces[0], retBot.Faces[0], retUp.Faces[0]] )
solid = Part.makeSolid(shell)
Part.show(solid)

Compilare FreeCAD su Windows


tutorial_freecad/playground.txt · Ultima modifica: 2016/04/12 16:04 da mickele

Facebook Twitter Google+ Digg Reddit LinkedIn StumbleUpon Email