Part.__sortEdges__(spath.Edges) is the key.
Next Step, I'll try to create more shape of rebar.
Code: Select all
"""
ArchRebar2.py
"""
import ArchCommands,ArchComponent,FreeCAD
from FreeCAD import Vector , Placement
import Draft
import DraftGeomUtils , DraftVecUtils
from math import cos , radians
class _Rebar(ArchComponent.Component):
def __init__(self,obj):
ArchComponent.Component.__init__(self,obj)
obj.addProperty("App::PropertyDistance","diameter","Rebar","The diameter of this rebar")
obj.addProperty("App::PropertyDistance","Length","Rebar","The Length of this rebar")
obj.addProperty("App::PropertyString","ShapeCode","Rebar","The Shape code of this rebar")
obj.setEditorMode("Length", 1) # read-only
obj.setEditorMode("ShapeCode", 1) # read-only
obj.Role = ['Rebar']
self.Type = "Rebar"
#obj.diameter = ['6 mm' , '9 mm' , '12 mm']
def getProfile(self,obj,noplacement=True):
return []
def getExtrusionVector(self,obj,noplacement=True):
return FreeCAD.Vector()
def setShapeCode(self , ShapeCode):
pass
def execute(self,obj):
if self.clone(obj):
return
dia = obj.diameter
R = 5*dia /2.
points = []
lines = []
for i in range(1, len(points)):
lines.append(Part.Line(points[i],points[i-1]))
spath = Part.Shape(lines)
edge1 = Part.__sortEdges__(spath.Edges)
wpath = Part.Wire(edge1)
wire = Part.Wire(wpath)
wire = DraftGeomUtils.filletWire(wire,R)
bpoint = points[0]
bvec = points[1].sub(points[0]).normalize()
circle = Part.makeCircle(dia/2,bpoint,bvec)
circle = Part.Wire(circle)
bar = wire.makePipeShell([circle],True,False,2)
shapes = []
shapes.append(bar)
obj.Shape = bar
class _Rebar_U_shape(_Rebar):
def __init__(self,obj):
_Rebar.__init__(self,obj)
obj.addProperty("App::PropertyDistance","A","Rebar","The A length of this rebar")
obj.addProperty("App::PropertyDistance","B","Rebar","The B length of this rebar")
obj.ShapeCode="00"
def execute(self,obj):
if self.clone(obj):
return
pl = obj.Placement
dia = obj.diameter
A = obj.A
B = obj.B
R = 5*dia /2.
#R = 0
import Part
points = []
points.append(Vector(0,0,A))
points.append(Vector(0,0,0))
points.append(Vector(B,0,0))
points.append(Vector(B,0,A))
for i in range(0, len(points)):
Msg(points[i])
Msg('\n')
lines = []
for i in range(1, len(points)):
lines.append(Part.Line(points[i],points[i-1]))
spath = Part.Shape(lines)
#wpath = Part.Wire(spath.Edges)
edge1 = Part.__sortEdges__(spath.Edges)
wpath = Part.Wire(edge1)
wire = Part.Wire(wpath)
wire = DraftGeomUtils.filletWire(wire,R)
bpoint = points[0]
bvec = points[1].sub(points[0]).normalize()
circle = Part.makeCircle(dia/2,bpoint,bvec)
circle = Part.Wire(circle)
bar = wire.makePipeShell([circle],True,False,2)
shapes = []
shapes.append(bar)
obj.Shape = bar
class _Rebar_L_shape(_Rebar):
def __init__(self,obj):
_Rebar.__init__(self,obj)
obj.addProperty("App::PropertyDistance","A","Rebar","The A length of this rebar")
obj.addProperty("App::PropertyDistance","B","Rebar","The B length of this rebar")
obj.ShapeCode="02"
def execute(self,obj):
if self.clone(obj):
return
pl = obj.Placement
dia = obj.diameter
A = obj.A
B = obj.B
R = 5*dia /2.
import Part
points = []
points.append(Vector(0,0,A))
points.append(Vector(0,0,0))
points.append(Vector(B,0,0))
#points.append(Vector(B,0,A))
lines = []
for i in range(1, len(points)):
lines.append(Part.Line(points[i],points[i-1]))
spath = Part.Shape(lines)
#wpath = Part.Wire(spath.Edges)
edge1 = Part.__sortEdges__(spath.Edges)
wpath = Part.Wire(edge1)
wire = Part.Wire(wpath)
wire = DraftGeomUtils.filletWire(wire,R)
bpoint = points[0]
bvec = points[1].sub(points[0]).normalize()
circle = Part.makeCircle(dia/2,bpoint,bvec)
circle = Part.Wire(circle)
bar = wire.makePipeShell([circle],True,False,2)
shapes = []
shapes.append(bar)
obj.Shape = bar
class _Rebar_Stirrup(_Rebar):
def __init__(self,obj):
_Rebar.__init__(self,obj)
obj.addProperty("App::PropertyDistance","A","Rebar","The A length of this rebar")
obj.addProperty("App::PropertyDistance","B","Rebar","The B length of this rebar")
obj.addProperty("App::PropertyInteger","n","Rebar","The Number of stirrups")
obj.addProperty("App::PropertyEnumeration","Type","Rebar","The Type of hook rebar")
obj.addProperty("App::PropertyLength","Spacing","Rebar","The spacing between the bars")
obj.n = 1
obj.Spacing = 150
obj.Type = ['1','2','3']
def execute(self,obj):
if self.clone(obj):
return
pl = obj.Placement
#dia = int(obj.diameter.split()[0] )
dia = obj.diameter
A = obj.A
B = obj.B
R = 4*dia /2.
import Part
points = []
if obj.Type=='1':
points.append(Vector(-A/2.,+B/2.-R-12*dia,0))
points.append(Vector(-A/2.,+B/2.,0))
points.append(Vector(+A/2.,+B/2.,0))
points.append(Vector(+A/2.,-B/2.,0))
points.append(Vector(-A/2.,-B/2.,+dia))
points.append(Vector(-A/2.,+B/2.,+dia))
points.append(Vector(-A/2.+R+12*dia,+B/2.,+dia))
elif obj.Type=='2':
#Msg('Type=2\n')
x = -A/2.; y =+B/2.
dy = R + R* cos(radians(45))
x1 = x + R - R* cos(radians(45))
y1 = y - dy
l_hook = 6*dia*cos(radians(45))
points.append(Vector(x1+l_hook ,y1-l_hook,0))
points.append(Vector(x1-dy,y,0))
#points.append(Vector(-A/2.,+B/2.,0))
points.append(Vector(+A/2.,+B/2.,0))
points.append(Vector(+A/2.,-B/2.,0))
points.append(Vector(-A/2.,-B/2.,+dia))
x1 = x + R + R* cos(radians(45))
y1 = y - R + R* cos(radians(45))
points.append(Vector(x,y1+dy,+dia))
points.append(Vector(x1+l_hook,y1-l_hook,+dia))
elif obj.Type=='3':
l_hook = 6*dia*cos(radians(45))
x = -A/2.; y =-B/2.
dx = R + R* cos(radians(45))
dy = dx
x1 = x + dx
y1 = y + R - R* cos(radians(45))
points.append(Vector(x1+l_hook,y1+l_hook,0))
points.append(Vector(x,y1-dy,0))
x = -A/2.; y =+B/2.
points.append(Vector(x,y,0))
points.append(Vector(+A/2.,+B/2.,0))
points.append(Vector(+A/2.,-B/2.,0))
points.append(Vector(-A/2.,-B/2.,+dia))
x1 = x + R + R* cos(radians(45))
y1 = y - R + R* cos(radians(45))
points.append(Vector(x,y1+dy,+dia))
points.append(Vector(x1+l_hook,y1-l_hook,+dia))
lines = []
for i in range(1, len(points)):
lines.append(Part.Line(points[i],points[i-1]))
spath = Part.Shape(lines)
#wpath = Part.Wire(spath.Edges)
edge1 = Part.__sortEdges__(spath.Edges)
wpath = Part.Wire(edge1)
wire = Part.Wire(wpath)
wire = DraftGeomUtils.filletWire(wire,R)
bpoint = points[0]
bvec = points[1].sub(points[0]).normalize()
circle = Part.makeCircle(dia/2,bpoint,bvec)
circle = Part.Wire(circle)
bar = wire.makePipeShell([circle],True,False,2)
shapes = []
if obj.n ==1:
shapes.append(bar)
#if hasattr(obj,"Spacing"):
#obj.Spacing = 0
else:
#interval = size - (obj.OffsetStart.Value + obj.OffsetEnd.Value)
#interval = interval / (obj.n - 1)
for i in range(obj.n):
if i==0:
shapes.append(bar)
if i>0:
bar = bar.copy()
bar.translate(Vector(0,0,obj.Spacing ))
shapes.append(bar)
if shapes:
obj.Shape = Part.makeCompound(shapes)
obj.Placement = pl
class _ViewProviderRebar(ArchComponent.ViewProviderComponent):
def __init__(self,vobj):
ArchComponent.ViewProviderComponent.__init__(self,vobj)
vobj.ShapeColor = (0.67,0.00,0.00)
def getIcon(self):
import Arch_rc
return ":/icons/Arch_Rebar_Tree.svg"
def makeRebarU(dia=12 , A=300 , B=1000 , placement = (0,0,0) ):
obj = FreeCAD.ActiveDocument.addObject("Part::FeaturePython","Reinforcing Bar")
_Rebar_U_shape(obj)
obj.diameter = dia
obj.A = A
obj.B = B
obj.Placement.Base = Vector(placement)
if FreeCAD.GuiUp:
_ViewProviderRebar(obj.ViewObject)
return obj
def makeRebarL(dia=12 , A=300 , B=1000 , placement = (0,0,0) ):
obj = FreeCAD.ActiveDocument.addObject("Part::FeaturePython","Reinforcing Bar")
_Rebar_L_shape(obj)
obj.diameter = dia
obj.A = A
obj.B = B
obj.Placement.Base = Vector(placement)
if FreeCAD.GuiUp:
_ViewProviderRebar(obj.ViewObject)
return obj
def makeStirrup(dia=6 , A=150 , B=350 , Type='1' , placement = (0,0,0) ):
obj = FreeCAD.ActiveDocument.addObject("Part::FeaturePython","Stirrup")
_Rebar_Stirrup(obj)
obj.diameter = dia
obj.A = A
obj.B = B
obj.Type = Type
obj.Placement.Base = Vector(placement)
if FreeCAD.GuiUp:
_ViewProviderRebar(obj.ViewObject)
return obj
def Test_Rebar_L():
return makeRebarL(dia= 15 , A = 300 , B = 1000, placement = (0, 0, 0))
def Test_Rebar_U():
return makeRebarU(dia= 15 , A = 300 , B = 1000, placement = (0, 0, 0))
if __name__=="__main__":
#rebar1 = makeRebar2()
#rebar2 = makeRebar2(placement = (0, 500, 0))
#rebar3 = makeRebar2(dia= 25 , placement = (0, 1000, 0))
#rebar4 = makeRebar2(dia= 32 , A = 500 , B = 1200, placement = (0, 1500, 0))
"""
spacing = 100
for z in range(150,3000-150 , spacing):
stirrup1 = makeStirrup(A=150, B = 150, Type='2' ,placement = (0, 0, z))
stirrup1.ViewObject.ShapeColor=(0.67,1.00,0.50)
"""
"""
main1 = makeRebarU(dia= 15 , A = 300 , B = 3800, placement = (0, 0, 0))
pos = Vector(100 , 100-25 , 350)
rot = FreeCAD.Rotation(FreeCAD.Vector(1,0,0),180)
newplace = FreeCAD.Placement(pos,rot )
main1.Placement=newplace
main1.Label='main1'
main2 = makeRebarU(dia= 15 , A = 300 , B = 3800, placement = (0, 0, 0))
pos = Vector(100 , -100+25 , 350)
rot = FreeCAD.Rotation(FreeCAD.Vector(1,0,0),180)
newplace = FreeCAD.Placement(pos,rot )
main2.Placement=newplace
main2.Label='main2'
main3 = makeStirrup(dia= 15 , A = 200 , B = 3800-3*15, placement = (100+1.5*15 , 100-25 , 25+6+15/2))
main3.Label='main3'
main4 = makeStirrup(dia= 15 , A = 200 , B = 3800-3*15, placement = (100+1.5*15 , -100+25 , 25+6+15/2))
main4.Label='main4'
spacing = 100
z = 350/2 + 25+6 -15
for x in range(200+175/2, 3800-spacing , spacing):
stirrup1 = makeStirrup(A=350-15, B = 150+15+6, Type='2' ,placement = (x, 0, z))
stirrup1.Placement.Rotation = FreeCAD.Rotation(FreeCAD.Vector(0,1,0),90)
stirrup1.ViewObject.ShapeColor=(0.67,1.00,0.50)
"""
"""
dx = 100-25
main1 = makeRebarL(dia= 15 , A = 300 , B = 3800, placement = (0, 0, 0))
main1.Label='main1'
pos = Vector(dx , dx , 15*3)
rot = FreeCAD.Rotation(-135,-90,0) # Yaw-Pitch-Roll
newplace = FreeCAD.Placement(pos,rot )
main1.Placement=newplace
main2 = makeRebarL(dia= 15 , A = 300 , B = 3800, placement = (0, 0, 0))
main2.Label='main2'
pos = Vector(-dx , dx , 15*3)
rot = FreeCAD.Rotation(-45,-90,0) # Yaw-Pitch-Roll
newplace = FreeCAD.Placement(pos,rot )
main2.Placement=newplace
main3 = makeRebarL(dia= 15 , A = 300 , B = 3800, placement = (0, 0, 0))
main3.Label='main3'
pos = Vector(-dx , -dx , 15*3)
rot = FreeCAD.Rotation(45,-90,0) # Yaw-Pitch-Roll
newplace = FreeCAD.Placement(pos,rot )
main3.Placement=newplace
main4 = makeRebarL(dia= 15 , A = 300 , B = 3800, placement = (0, 0, 0))
main4.Label='main4'
pos = Vector(dx , -dx , 15*3)
rot = FreeCAD.Rotation(135,-90,0) # Yaw-Pitch-Roll
newplace = FreeCAD.Placement(pos,rot )
main4.Placement=newplace
gap = 1
spacing = 100
b = 200-2*25 + 6 +15 + gap
for z in range(150,3800-400-100 , spacing):
stirrup1 = makeStirrup(A=b, B = b, Type='2' ,placement = (0, 0, z))
stirrup1.ViewObject.ShapeColor=(0.67,1.00,0.50)
"""
if True:
stirrup1 = makeStirrup(A=350, B = 150, Type='3' ,placement = (0, 0, 0))
rot = FreeCAD.Rotation(0,90,0) # Yaw-Pitch-Roll
stirrup1.Placement.Rotation = rot
stirrup1.n=5
#rebar1 = Test_Rebar_L()
#rebar1.Placement.Base = Vector(0,1000,0)
#rebar2 = Test_Rebar_U()
#rebar2.Placement.Base = Vector(0,1500,0)
FreeCAD.ActiveDocument.recompute()
Msg("\nDone!!\n\n")