Test Create ArchRebar2 Object

A forum dedicated to the Arch module development
chakkree
Posts: 140
Joined: Tue Jun 30, 2015 12:58 am
Location: Bangkok Thailand

Test Create ArchRebar2 Object

Postby chakkree » Wed Jun 29, 2016 10:54 am

from ArchPrecast + ArchRebar, I try to create reinforcing bar object.
First, Sample is U-Shape rebar.

Code: Select all

import ArchCommands,ArchComponent,FreeCAD
from FreeCAD import Vector
import Draft
import DraftGeomUtils

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.Role = ['Rebar']
        self.Type = "Rebar"

    def getProfile(self,obj,noplacement=True):
        return []

    def getExtrusionVector(self,obj,noplacement=True):
        return FreeCAD.Vector()
       
    def execute(self,obj):       
        if self.clone(obj):
            return


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")       


    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)
        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 _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 makeRebar2(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

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))

    FreeCAD.ActiveDocument.recompute()
    Msg("\nDone!!\n\n")


ArchRebar2.png
ArchRebar2.png (330.41 KiB) Viewed 1399 times
Attachments
TestArchRebar2_01.FCStd
(9.26 KiB) Downloaded 12 times
User avatar
yorik
Site Admin
Posts: 8633
Joined: Tue Feb 17, 2009 9:16 pm
Location: São Paulo, Brazil
Contact:

Re: Test Create ArchRebar2 Object

Postby yorik » Wed Jun 29, 2016 1:46 pm

Good test! I haven't tried yet to put rebars in precast elements. Normally it should work, but we never know...
chakkree
Posts: 140
Joined: Tue Jun 30, 2015 12:58 am
Location: Bangkok Thailand

Re: Test Create ArchRebar2 Object

Postby chakkree » Thu Jun 30, 2016 7:16 am

new class object in ArchRebar2.py -> Stirrup Type 1


Code: Select all

"""
   ArchRebar2.py
"""
import ArchCommands,ArchComponent,FreeCAD
from FreeCAD import Vector
import Draft
import DraftGeomUtils

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.Role = ['Rebar']
        self.Type = "Rebar"

    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


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")       


    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)
        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")       


    def execute(self,obj):       
        if self.clone(obj):
            return

        pl = obj.Placement
        dia = obj.diameter
        A = obj.A
        B = obj.B

        R = 4*dia /2.

        import Part
        points = []
        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))

        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)
        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 _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 makeRebar2(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 makeStirrup(dia=6 , A=150 , B=350 , placement = (0,0,0) ):
    obj = FreeCAD.ActiveDocument.addObject("Part::FeaturePython","Stirrup")

    _Rebar_Stirrup(obj)
    obj.diameter = dia
    obj.A = A
    obj.B = B
    obj.Placement.Base = Vector(placement)

    if FreeCAD.GuiUp:
        _ViewProviderRebar(obj.ViewObject)

    return obj


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 = 125
    for z in range(150,3000-150 , spacing):
        stirrup1 = makeStirrup(A=150, B = 150 ,placement = (0, 0, z))
        stirrup1.ViewObject.ShapeColor=(0.67,1.00,0.50)

    FreeCAD.ActiveDocument.recompute()
    Msg("\nDone!!\n\n")



ArchRebar2_Stirrup.png
ArchRebar2_Stirrup.png (367.25 KiB) Viewed 1384 times
Attachments
TestArchRebar2_02.FCStd
(70.56 KiB) Downloaded 12 times
chakkree
Posts: 140
Joined: Tue Jun 30, 2015 12:58 am
Location: Bangkok Thailand

Re: Test Create ArchRebar2 Object

Postby chakkree » Thu Jun 30, 2016 2:08 pm

Stirrup Type 2

Code: Select all

"""
   ArchRebar2.py
"""

import ArchCommands,ArchComponent,FreeCAD
from FreeCAD import Vector
import Draft
import DraftGeomUtils

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.Role = ['Rebar']
        self.Type = "Rebar"

    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

        points = []

        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)
        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")       


    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)
        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::PropertyEnumeration","Type","Rebar","The Type of hook rebar")       
        obj.Type = ['1','2']

    def execute(self,obj):       
        if self.clone(obj):
            return

        pl = obj.Placement
        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))


        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)
        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 _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 makeRebar2(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 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


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)

    FreeCAD.ActiveDocument.recompute()
    Msg("\nDone!!\n\n")


ArchRebar2_Stirrup2.png
ArchRebar2_Stirrup2.png (539.6 KiB) Viewed 1364 times
Attachments
TestArchRebar2_StirrupType2.FCStd
(100.92 KiB) Downloaded 18 times
chakkree
Posts: 140
Joined: Tue Jun 30, 2015 12:58 am
Location: Bangkok Thailand

Re: Test Create ArchRebar2 Object

Postby chakkree » Thu Jun 30, 2016 4:43 pm

Reinforcement in Simple Beam.

ArchRebar_SimpleBeam.png
ArchRebar_SimpleBeam.png (517.92 KiB) Viewed 1357 times

TestArchRebar2_SimpleBeam.FCStd
(146.7 KiB) Downloaded 18 times
chakkree
Posts: 140
Joined: Tue Jun 30, 2015 12:58 am
Location: Bangkok Thailand

Re: Test Create ArchRebar2 Object

Postby chakkree » Sun Jul 03, 2016 10:07 am

to test footing reinforcement used U-shape rebar + stirrup type 1

ArchRebar2_Footing.png
ArchRebar2_Footing.png (326.56 KiB) Viewed 1240 times
TestArchRebar2_Footing.FCStd
(20.88 KiB) Downloaded 18 times
TestArchRebar2_Footing3.FCStd
(97.62 KiB) Downloaded 17 times
chakkree
Posts: 140
Joined: Tue Jun 30, 2015 12:58 am
Location: Bangkok Thailand

Re: Test Create ArchRebar2 Object

Postby chakkree » Sun Aug 14, 2016 3:34 pm

Now (14 Aug 2016) All above source code can not work correctly on FreeCAD 0.17.8203(approx.)
But All above source code can run correctly on FreeCAD 0.16

Error_in_017-8203.PNG
Error_in_017-8203.PNG (246.72 KiB) Viewed 1114 times
chakkree
Posts: 140
Joined: Tue Jun 30, 2015 12:58 am
Location: Bangkok Thailand

Re: Test Create ArchRebar2 Object

Postby chakkree » Mon Aug 15, 2016 2:19 am

From this forum "Part.makeTube" locking up then crashing FreeCAD, can work on FreeCAD 0.16 and FreeCAD 0.17.

I'll try to replace code from that to ArchRebar2 class object.
User avatar
bernd
Posts: 3924
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland

Re: Test Create ArchRebar2 Object

Postby bernd » Fri Aug 19, 2016 4:35 pm

Wow, very cool !!! we should integrate this kind of stirups in the FreeCAD gui. It is not possible to do the in scetcher. viewtopic.php?f=23&t=16375#p129608
User avatar
cnirbhay
Posts: 85
Joined: Wed Aug 17, 2016 4:24 pm

Re: Test Create ArchRebar2 Object

Postby cnirbhay » Fri Aug 19, 2016 5:34 pm

The reinforcement part is just awesome chakkree.