[Closed]Test Create ArchRebar2 Object

A forum dedicated to the Draft, Arch and BIM workbenches development.
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
User avatar
chakkree
Posts: 327
Joined: Tue Jun 30, 2015 12:58 am
Location: Bangkok Thailand

[Closed]Test Create ArchRebar2 Object

Post by chakkree »

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 5391 times
Attachments
TestArchRebar2_01.FCStd
(9.26 KiB) Downloaded 78 times
Last edited by chakkree on Wed Jul 12, 2017 3:09 am, edited 1 time in total.
User avatar
yorik
Founder
Posts: 13640
Joined: Tue Feb 17, 2009 9:16 pm
Location: Brussels
Contact:

Re: Test Create ArchRebar2 Object

Post by yorik »

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

Re: Test Create ArchRebar2 Object

Post by chakkree »

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 5376 times
Attachments
TestArchRebar2_02.FCStd
(70.56 KiB) Downloaded 68 times
User avatar
chakkree
Posts: 327
Joined: Tue Jun 30, 2015 12:58 am
Location: Bangkok Thailand

Re: Test Create ArchRebar2 Object

Post by chakkree »

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 5356 times
Attachments
TestArchRebar2_StirrupType2.FCStd
(100.92 KiB) Downloaded 73 times
User avatar
chakkree
Posts: 327
Joined: Tue Jun 30, 2015 12:58 am
Location: Bangkok Thailand

Re: Test Create ArchRebar2 Object

Post by chakkree »

Reinforcement in Simple Beam.
ArchRebar_SimpleBeam.png
ArchRebar_SimpleBeam.png (517.92 KiB) Viewed 5349 times
TestArchRebar2_SimpleBeam.FCStd
(146.7 KiB) Downloaded 76 times
User avatar
chakkree
Posts: 327
Joined: Tue Jun 30, 2015 12:58 am
Location: Bangkok Thailand

Re: Test Create ArchRebar2 Object

Post by chakkree »

to test footing reinforcement used U-shape rebar + stirrup type 1
ArchRebar2_Footing.png
ArchRebar2_Footing.png (326.56 KiB) Viewed 5232 times
TestArchRebar2_Footing.FCStd
(20.88 KiB) Downloaded 79 times
TestArchRebar2_Footing3.FCStd
(97.62 KiB) Downloaded 79 times
User avatar
chakkree
Posts: 327
Joined: Tue Jun 30, 2015 12:58 am
Location: Bangkok Thailand

Re: Test Create ArchRebar2 Object

Post by chakkree »

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 5106 times
User avatar
chakkree
Posts: 327
Joined: Tue Jun 30, 2015 12:58 am
Location: Bangkok Thailand

Re: Test Create ArchRebar2 Object

Post by chakkree »

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
Veteran
Posts: 12849
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland
Contact:

Re: Test Create ArchRebar2 Object

Post by bernd »

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
Post Reply