Nuts And Bolts in DRAWEXE ?

Hello,
at this URL we can see a nut and a bolt without any threads

http://www.opencascade.org/ex/att/42_pump_bolt.brep.gz
http://www.opencascade.org/ex/att/50_pump_nut.brep.gz

I red also the tutorial.pdf to see how they proceed for the design of the little threads at the top of the little bottle... but a programer approache is used with link to the OpenCASCADE library. I want to simply use the DRAWEXE program to build my own threaded nuts and bolts.

I red also:
http://www.opencascade.org/org/forum/thread_1080/
and I dont understand what I can do with all this information (wish seem to be usefull but my knowledge in geometry and in programming is too low)

Is somebody can e-mail-me a simple nut and a simple bolt that I can run in the DRAWEXE program using the simple command:

DRAWEXE> source MyFile.tcl

I want the commande line program that I can source in DRAWEXE, not only the simple .brep file.

It seem then many persons want to know how to do that. (threaded nuts and bolts) It is a must to be include in the samples directory of the next version of OpenCASCADE. It a funny example for new commer in OpenCASCADE and in mechanical design.

Thank you very mutch.

fpga's picture

Well, after many experimentation, I was able to answer to my own question. But the result is not perfect. Try my Super Power Spiral Artwork and give me a feedback.
Thank's in advance.

=============threads.tcl================
# This programm create thread for a bolt. For a nut, create
# the nut casing and cut your nut case with this thread.
# ==> Feel free to include this example in your Next CASCAD version
####################################################################
# To use threads.tcl as an external function, enable this bloc
# by making: if { 1 == 1 } {
if { 1 == 0 } {
proc thread {{BoltRadius 1} {ThreadPerLength 1} {ThreadedLength 1} ReturnedShapeName} {
dset rbolt $BoltRadius
dset tpl $ThreadPerLength
dset lthread $ThreadedLength
upvar $ReturnedShapeName threadsolid
dset pi 3.1415926535897931
puts "ReturnedShapeName=$ReturnedShapeName\n"
}}

# To use threads.tcl as an autonomous programm, make a if { 1 == 1 } {
# Take care to use "external function" OR "autonomous programm" at a time
# Here, you have to define manualy your threads size configuration
if { 1 == 1 } {
clear
dset rbolt 3 ; # Bolt Radius
dset tpl 1 ; # The "How many Thread Per Length" definition.
dset lthread 6 # The "Length" of the nedded threads.
}

puts "Make a thread:\n\
\t BoltRadius=[dval rbolt],\
ThreadedLength=[dval lthread],\
ThreadPerLength=[dval tpl]\n"

dset dpt 32 ; # This is the Dot Per Thread definition.
# 32 is a greate value.
dset deep [dval (1/([dval tpl]*2))] ; # This is how deep is a thread.
# By default, this value is equal to 0,5 thread width.

dset dX [dval (2*pi/[dval dpt])] ; # This define the angular degree
# of rotation of a Dot, whish will paint a thread.
puts "dX=[dval dX], pi=[dval pi], dpt=[dval dpt]"

if { 1 == 1 } { ; # This bloc define some simple and usefull visual
# limit referance.
point c0 0 0 0
point c1 $rbolt 0 1/[dval (tpl*2)]
point c2 $rbolt 0 1
point c3 $rbolt 0 2

circle climitIN 0 0 0 ($rbolt-(1/($tpl*2)))
circle climitOUT 0 0 0 $rbolt
}

# This is a kind of Home Made "Profile" of a thread.
# du*****U We create a complete threaded rod by making the spiral
# * * rotation of this profile. This profile is limited by
# * O five 3D Spiral Curves named: d,D,O,U,du. After, we will
# * * use the thruesections command to make five faces limited
# d******D by these five 3D curves. Thes curve are made by the
# "interpol" commande, wish work by the bias of an ASCII
# files.
# Files are filled by a simple recusive "puts" command.
# For debug purpose, you can enable/disable each blocs
# of creation of any of the d,D,O,U,du 3D Curves.
#
if { 1 == 1 } { ; # Creation of the "U" 3D Curve.

puts "open pntsU.dat\n"

set fid [open "pntsU.dat" w]
puts $fid "[dval ((((lthread*tpl)+1)*dpt)+1)] 3d"

for {dset t 1} {[dval t] <= [dval ((lthread*tpl)+1)]} {dset t t+1} {

for {dset i 1} {[dval i] <= [dval dpt]} {dset i i+1} {

dset x [dval ([dval dX]*[dval (i-1)])]

puts $fid "[dval (rbolt-(1/(tpl*2)))*cos([dval x])] \
[dval (rbolt-(1/(tpl*2)))*sin([dval x])] \
[dval (((i-1)/(dpt*tpl))-(1/(tpl*1.00001))+((t)/tpl))]"

}
}

dset i 1
dset x [dval ([dval dX]*[dval (i-1)])]

puts $fid "[dval (rbolt-(1/(tpl*2)))*cos([dval x])] \
[dval (rbolt-(1/(tpl*2)))*sin([dval x])] \
[dval (((i-1)/(dpt*tpl))-(1/(tpl*1.00001))+((t)/tpl))]"

close $fid
puts "close pntsU.dat\n"
interpol U "pntsU.dat"
mkedge U U
wire U U
puts "Made Wire U\n"
}

if { 1 == 1 } { ; # Creation of the "du" 3D Curve.
# For this 3D Curve, the best theoretical approache was to
# use x=0 and y=0, and use only a linear z axis, to have a
# nice full filled threaded rod. But if we do that, we seem to
# face some capacities limitation with the "thruesection" command.
# It dosen't seem to like the fact to have a common limit on
# itself by the "center axis"

puts "open pntsdu.dat\n"

set fid [open "pntsdu.dat" w]
puts $fid "[dval ((((lthread*tpl)+1)*dpt)+1)] 3d"

for {dset t 1} {[dval t] <= [dval ((lthread*tpl)+1)]} {dset t t+1} {

for {dset i 1} {[dval i] <= [dval dpt]} {dset i i+1} {

dset x [dval ([dval dX]*[dval (i-1)])]

puts $fid "[dval ((1/(tpl*2)))*cos([dval x])] \
[dval ((1/(tpl*2)))*sin([dval x])] \
[dval (((i-1)/(dpt*tpl))-(1/(tpl*1.00))+((t)/tpl))]"

}
}

dset i 1
dset x [dval ([dval dX]*[dval (i-1)])]

puts $fid "[dval ((1/(tpl*2)))*cos([dval x])] \
[dval ((1/(tpl*2)))*sin([dval x])] \
[dval (((i-1)/(dpt*tpl))-(1/(tpl*1.00))+((t)/tpl))]"

close $fid
puts "close pntsdu.dat\n"
interpol du "pntsdu.dat"
mkedge du du
wire du du
puts "Made Wire du\n"
}

if { 1 == 1 } { ; # Creation of the "O" 3D Curve.
puts "open pntsO.dat\n"

set fid [open "pntsO.dat" w]
puts $fid "[dval ((((lthread*tpl)+1)*dpt)+1)] 3d"

for {dset t 1} {[dval t] <= [dval ((lthread*tpl)+1)]} {dset t t+1} {

for {dset i 1} {[dval i] <= [dval dpt]} {dset i i+1} {

dset x [dval dX]*[dval (i-1)]

puts $fid "[dval (rbolt*cos([dval x]))] \
[dval (rbolt*sin([dval x]))] \
[dval (((i-1)/(dpt*tpl))+((t-1)/tpl)-(1/(tpl*1.00))+(1/(tpl*2)))]"

}
}

dset i 1
dset x [dval dX]*[dval (i-1)]

puts $fid "[dval (rbolt*cos([dval x]))] \
[dval (rbolt*sin([dval x]))] \
[dval (((i-1)/(dpt*tpl))+((t-1)/tpl)-(1/(tpl*1.00))+(1/(tpl*2)))]"

close $fid
interpol O "pntsO.dat"
mkedge O O
wire O O
puts "Made Wire O\n"

}

if { 1 == 1 } { ; # Creation of the "D" 3D Curve.
puts "open pntsD.dat\n"

set fid [open "pntsD.dat" w]
puts $fid "[dval ((((lthread*tpl)+1)*dpt)+1)] 3d"

for {dset t 1} {[dval t] <= [dval ((lthread*tpl)+1)]} {dset t t+1} {

for {dset i 1} {[dval i] <= [dval dpt]} {dset i i+1} {

dset x [dval dX]*[dval (i-1)]

puts $fid "[dval (rbolt-(1/(tpl*2)))*cos([dval x])] \
[dval (rbolt-(1/(tpl*2)))*sin([dval x])] \
[dval (((i-1)/(dpt*tpl))+((t-1)/tpl)-(1.00001/(tpl*1.00)))]"

}
}

dset i 1
dset x [dval dX]*[dval (i-1)]

puts $fid "[dval (rbolt-(1/(tpl*2)))*cos([dval x])] \
[dval (rbolt-(1/(tpl*2)))*sin([dval x])] \
[dval (((i-1)/(dpt*tpl))+((t-1)/tpl)-(1.00001/(tpl*1.00)))]"

close $fid
interpol D "pntsD.dat"
mkedge D D
wire D D
puts "Made Wire D\n"

}

if { 1 == 1 } { ; # Creation of the "d" 3D Curve.
# For this 3D Curve, the best theoretical approache was to
# use x=0 and y=0, and use only a linear z axis, to have a
# nice full filled threaded rod. But if we do that, we seem to
# face some capacities limitation with the "thruesection" command.
# It dosen't seem to like the fact to have a common limit on
# itself by the "center axis"

set fid [open "pntsd.dat" w]
puts $fid "[dval ((((lthread*tpl)+1)*dpt)+1)] 3d"

for {dset t 1} {[dval t] <= [dval ((lthread*tpl)+1)]} {dset t t+1} {

for {dset i 1} {[dval i] <= [dval dpt]} {dset i i+1} {

dset x [dval dX]*[dval (i-1)]

puts $fid "[dval ((1/(tpl*2)))*cos([dval x])] \
[dval ((1/(tpl*2)))*sin([dval x])] \
[dval (((i-1)/(dpt*tpl))+((t-1)/tpl)-(1/(tpl*1.00)))]"

}
}

dset i 1
dset x [dval dX]*[dval (i-1)]

puts $fid "[dval ((1/(tpl*2)))*cos([dval x])] \
[dval ((1/(tpl*2)))*sin([dval x])] \
[dval (((i-1)/(dpt*tpl))+((t-1)/tpl)-(1/(tpl*1.00)))]"

close $fid
interpol d "pntsd.dat"
mkedge d d
wire d d
puts "Made Wire d\n"

}

fit
if { 1 == 1 } { ; # Now we need to build the Thread SHELL.
# To do this, we use the "thrusections" command.
# And we need also to generate the two ending cap
# to close the two end of the 3D Thread Shell.
# To do this, we explode 3 time each "thrusections"
# result, to have the edge of each ends, to be able
# to build a closed wire whish will be use to
# make a plane to cap each end. When all faces of our
# thread are close, we can perform the" mksol" commande
# to have the final result.
#
# du*****U
# * *
# * O
# * *
# d******D
#
thrusections dD issolid isruled d D
explode dD
explode dD_1
explode dD_1_1

thrusections DO issolid isruled D O
explode DO
explode DO_1
explode DO_1_1

thrusections OU issolid isruled O U
explode OU
explode OU_1
explode OU_1_1

thrusections Udu issolid isruled U du
explode Udu
explode Udu_1
explode Udu_1_1

thrusections dud issolid isruled du d
explode dud
explode dud_1
explode dud_1_1

puts "Makeing the two ending cap\n"

wire startcap dD_1_1_4 DO_1_1_4 OU_1_1_4 Udu_1_1_4 dud_1_1_4
mkplane startcap startcap
wire endcap dD_1_1_2 DO_1_1_2 OU_1_1_2 Udu_1_1_2 dud_1_1_2
mkplane endcap endcap

puts "Made 7 plans to build the 3D thread.\n"

sewing threadshell dD DO OU Udu dud startcap endcap
puts "Glue all the 7 plans to create the 3D shell.\n"

mksol threadsolid threadshell
puts "Made the 3D Solid thread"

# unset dD DO OU UUu Uuu udu dud

# This is where I strat to have some problem. The resulting threads
# has problem to be "cut", "fuse", "bopcut", "bopfuse"...
# and I saw also some problem of visualisation in the FreeCAD software.
# Why the result is not usable ?

# To try to fixe the useability problem, I took the decision to
# make a "compound"
# (fuse and bopfuse didn't work, but compound work fine!)
# And proceed after to make a "common" of an oversized cylinder AND
# the compound result to try to see a pure Threded ROD... well
# the result is not perfect ! Why ? I don't know ?????

pcylinder stud [dval (rbolt-deep-0.0)] [dval (lthread+(4/(tpl)))]
ttranslate stud 0 0 -[dval (3/(2*tpl))]

compound threadsolid stud cthreadsolid

pcylinder stud [dval (rbolt+1.0000)] [dval (lthread+(0/(tpl)))]
# ttranslate stud 0 0 -[dval (3/(2*tpl))]
puts "Creating a cylinder to clean all tollerance"

# Now, this is the result: fthreadsolid
common fthreadsolid stud cthreadsolid

# fuse threadsolid stud threadsolid

puts "Thread Creation job is finished, Rusulting 3D Shape name is: fthreadsolid \n \
The shape seem to be nice :-), now try to cut or fuse it ! \n
Any comments, patch, or suggestion are welcome. "
# puts "Thread Creation job is finished, Rusulting 3D Shape name is: $ReturnedShapeName \n"
}

# }

# Feel free to try my Artwork, and give me a feedback if you have any idea.
# I made also all the other function to create a Very nice Nut
# and a very nice Hexagon Bolt, 6 pans grade 12 ;-)

fpga's picture

Well, I re-post the Thread Profile Design because
the web editor seem to trunk white space. I replaced it by "." to show also the filled area.
#
# du*****U
# *........*
# *..........O
# *........*
# d******D
#

fpga's picture

Well, to see it correctly, "copy" here and and "paste" in an editor with "fixed font" ! And you will see it correctly.

This is a new and last try with "="
#
# du*****U
# *========*
# *==========O
# *========*
# d******D
#