Spiralbohrer

In diesem Forum Fragen und Diskussionen in Deutsch
Forum rules
Foren-Regeln und hilfreiche Informationen

WICHTIG: Bitte zuerst lesen, bevor Sie posten
mario52
Posts: 2683
Joined: Wed May 16, 2012 2:13 pm

Re: Spiralbohrer

Postby mario52 » Sun Jan 22, 2017 1:50 pm

hi
the future version Macro FCSpring create the complete spring with circle
for the moment other forme give (with my method)

Image
the mode point by microelly2 is perfect i study one method ....
freecad-heini-1 wrote:is it possible to change your macro that it snaps the centerpoint of the circle and snaps the endpoint of the helix to orientate the sketch perpendicular to the curve?
If you talk about my little macro

principe :
the line is cut in x points (here Number=500 cuts begin 0 to 499 you can modify)

Code: Select all

    pointsDirection = lineSelected.Shape.discretize(Number=500)             # discretize the path line first selection
the perpendicularity is calculate between 2 points modify :
1:

Code: Select all

v=pointsDirection[0].sub(pointsDirection[1])          # perpendicular of first > second point
Macro_perpendicular_01.png
Macro_perpendicular_01.png (2.3 KiB) Viewed 660 times
2:

Code: Select all

    v=pointsDirection[-1].sub(pointsDirection[-2])       # perpendicular of last > before last point
    pl.Base = pointsDirection[-1]                        # position last point
Macro_perpendicular_02.png
Macro_perpendicular_02.png (2.61 KiB) Viewed 660 times
3:

Code: Select all

    v=pointsDirection[100].sub(pointsDirection[101])   # perpendicular of point 100 > point 101
    pl.Base = pointsDirection[100]                     # position point 100
Macro_perpendicular_03.png
Macro_perpendicular_03.png (2.67 KiB) Viewed 660 times
4:

Code: Select all

   v=pointsDirection[0].sub(pointsDirection[-1])         # perpendicular of first point > last point
   pl.Base = pointsDirection[0]                          # position first point
Macro_perpendicular_04.png
Macro_perpendicular_04.png (3 KiB) Viewed 660 times
for discretize other parameters

Code: Select all

#http://forum.freecadweb.org/viewtopic.php?f=12&t=16336#p129468
#Discretizes the edge and returns a list of points.
#The function accepts keywords as argument:
#discretize(Number=n) => gives a list of 'n' equidistant points
#discretize(QuasiNumber=n) => gives a list of 'n' quasi equidistant points (is faster than the method above)
#discretize(Distance=d) => gives a list of equidistant points with distance 'd'
#discretize(Deflection=d) => gives a list of points with a maximum deflection 'd' to the edge
#discretize(QuasiDeflection=d) => gives a list of points with a maximum deflection 'd' to the edge (faster)
#discretize(Angular=a,Curvature=c,[Minimum=m]) => gives a list of points with an angular deflection of 'a'
#and a curvature deflection of 'c'. Optionally a minimum number of points
#can be set which by default is set to 2.
if this macro you is interesting i can create complete gui macro parametrisable

bon weekend

mario
Maybe you need a special feature, go into Macros_recipes and Code_snippets, Dialog creation. My macros on Gist.github.
freecad-heini-1
Posts: 5994
Joined: Tue Jan 07, 2014 11:10 am
Contact:

Re: Spiralbohrer

Postby freecad-heini-1 » Sun Jan 22, 2017 5:26 pm

Thank you very much Mario. I will check this in deep next week.
mario52
Posts: 2683
Joined: Wed May 16, 2012 2:13 pm

Re: Spiralbohrer

Postby mario52 » Sat Apr 08, 2017 10:01 am

hi microelly2

problem with our macros on circle:

y work on my macro "perpendicular to wire" for use with my macro "rotate to point" and i adapt for Best way to convert line drawing image to Freecad file but problem with circle : my macro and your macro

Your macro first circle
Halphen_Micro_00.png
Halphen_Micro_00.png (31.91 KiB) Viewed 587 times
My macro second circle
Halphen_Mario_01.png
Halphen_Mario_01.png (11.87 KiB) Viewed 587 times
your macro second circle
Halphen_Micro_01.png
Halphen_Micro_01.png (12.57 KiB) Viewed 587 times
with pathArray Align = True ( ?? ) first circle
Halphen_Draft_PathArray_01.png
Halphen_Draft_PathArray_01.png (14.79 KiB) Viewed 587 times
Halphen_00.FCStd
(354.73 KiB) Downloaded 23 times
Your macro replace # h=QtGui.QDial() to h=QtGui.QDoubleSpinBox() and add create copy of triangle on point

Code: Select all

# -*- coding: utf-8 -*-

import numpy as np
import Draft

def srun(w):

   bc=w.path.Shape.Edge1.Curve
   c=w.target

   pa=bc.LastParameter
   ps=bc.FirstParameter

   v=w.ha.value()*0.01
   v=ps +(pa-ps)*v

   t=bc.tangent(v)[0]
   p=bc.value(v)

   zarc=np.arctan2(t.y,t.x)
   zarc *=180.0/np.pi

   harc=np.arcsin(t.z)
   harc *=180.0/np.pi

   pl=App.Placement()
   pl.Rotation=App.Rotation(FreeCAD.Vector(0,1,0,),90-harc)

   pa=App.Placement()
   pa.Rotation=App.Rotation(FreeCAD.Vector(0,0,1,),zarc)
   pl2=pa.multiply(pl)

   pl2.Base=p
   c.Placement=pl2

   x = Draft.scale(c,copy=True)
   x.Placement=pl2



from PySide import QtGui, QtCore

def MyDialog(path,target):

   w=QtGui.QWidget()
   w.path=path
   w.target=target

   box = QtGui.QVBoxLayout()
   w.setLayout(box)
   w.setWindowFlags(QtCore.Qt.WindowStaysOnTopHint)



   l=QtGui.QLabel("Position" )
   box.addWidget(l)

#   h=QtGui.QDial()
   h=QtGui.QDoubleSpinBox()

   h.setMaximum(100)
   h.setMinimum(0)
   w.ha=h
   srun(w)

   h.valueChanged.connect(lambda:srun(w))
   box.addWidget(h)


   w.show()
   return w


def run():
   [path,target]=Gui.Selection.getSelection()
   MyDialog(path,target)

# selektion:
# 1. pfad spline
# 2. zu platzierendes objekt


run()

my macro modified for create triangle along the circle

Code: Select all

# -*- coding: utf-8 -*-
import Draft, Part

sel = FreeCADGui.Selection.getSelection()                               # Select an object

lineSelected = FreeCADGui.Selection.getSelectionEx()[0].SubObjects[0]   # first object the Path object or SubObjects
myCircle     = sel[1]                                                   # second object

pointsDirection  = []

pointsDirection = lineSelected.discretize(Number=3600)                   # discretize the path line first selection

for i in range(50,3600,50):
    pl = FreeCAD.Placement()
    print i
#    Part.show(myCircle.Shape)                    # create repro shape object
#    Draft.scale(myCircle,delta=App.Vector(1.0, 1.0, 1.0),center=App.Vector(pointsDirection[i]),copy=True,legacy=True)
    Draft.scale(myCircle,copy=True)
    
    try:
        v=pointsDirection[i-1].sub(pointsDirection[i+1])                            # avec vecteurs 1 et 2 (direction debut ligne)
        r=App.Rotation(App.Vector(0,0,1),v)
    except Exception:
        None
    pl.Rotation.Q = r.Q
    pl.Base = pointsDirection[i]
    App.ActiveDocument.ActiveObject.Placement = pl
       
del pointsDirection[:]
FreeCAD.ActiveDocument.recompute()
Mario
Maybe you need a special feature, go into Macros_recipes and Code_snippets, Dialog creation. My macros on Gist.github.