## 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: 3222
Joined: Wed May 16, 2012 2:13 pm

### Re: Spiralbohrer

hi
the future version Macro FCSpring create the complete spring with circle
for the moment other forme give (with my method) 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.sub(pointsDirection)          # perpendicular of first > second point`` Macro_perpendicular_01.png (2.3 KiB) Viewed 826 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 (2.61 KiB) Viewed 826 times
3:

Code: Select all

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

Code: Select all

``````   v=pointsDirection.sub(pointsDirection[-1])         # perpendicular of first point > last point
pl.Base = pointsDirection                          # position first point`````` Macro_perpendicular_04.png (3 KiB) Viewed 826 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, Topological_data_scripting, Dialog creation. My macros on Gist.github.
Posts: 7354
Joined: Tue Jan 07, 2014 11:10 am
Contact:

### Re: Spiralbohrer

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

### Re: Spiralbohrer

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 Halphen_Micro_00.png (31.91 KiB) Viewed 753 times
My macro second circle Halphen_Mario_01.png (11.87 KiB) Viewed 753 times Halphen_Micro_01.png (12.57 KiB) Viewed 753 times
with pathArray Align = True ( ?? ) first circle Halphen_Draft_PathArray_01.png (14.79 KiB) Viewed 753 times
Halphen_00.FCStd
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)
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()

pa=App.Placement()
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" )

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

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

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

w.show()
return w

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

# selektion:
# 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().SubObjects   # first object the Path object or SubObjects
myCircle     = sel                                                   # second object

pointsDirection  = []

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

for i in range(50,3600,50):
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[:]