[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

Re: Test Create ArchRebar2 Object

Post by chakkree »

OK! Fixed! Now it can work corectly(I think :D ) on FreeCAD 0.16 and FreeCAD 0.17
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")
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 »

OS: Debian GNU/Linux 8.5 (jessie)
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.17.8280 (Git)
Build type: Unknown
Branch: occt7netgen
Hash: f2d12e4af256732dfc86d27702b5446bc4fef58d
Python version: 2.7.9
Qt version: 4.8.6
Coin version: 4.0.0a
OCC version: 7.0.0
screen.jpg
screen.jpg (134.92 KiB) Viewed 1955 times
but I had to remove some trailing whitespaces because of intendation errors ...

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()
    FreeCADGui.activeDocument().activeView().viewAxonometric()
    FreeCADGui.SendMsgToActiveView("ViewFit")    
    Msg("\nDone!!\n\n")

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 other diameter and width and legth works too ...
screen.jpg
screen.jpg (112.96 KiB) Viewed 1952 times
It is starting to really make fun !

BTW: @Yorik and chakkree and others
At the moment the rebar and space and count are in one object. But in a building or even in one wall or slab one type (shape) of rebar can be on different places just with other spaces and count. Means we could have two objects one defining the shape of the rebar and one defining the count and the spacing between the rebars.

cheers bernd
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 »

bernd wrote:Means we could have two objects one defining the shape of the rebar and one defining the count and the spacing between the rebars.
This is the case with arch Rebar1 already, you can build two from the same base sketch. since the Rebar2 above builds its own base wire, indeed that doesn't work. But the Rebar2 with all its derivate cases is already pretty powerful... Yes I think the code that builds the base wire should be split from the rest, this would allow the same level of freedom as the Rebar1, where you can if you want, draw yourself your own rebar...
User avatar
chakkree
Posts: 327
Joined: Tue Jun 30, 2015 12:58 am
Location: Bangkok Thailand

Re: Test Create ArchRebar2 Object

Post by chakkree »

Add new shape rebar for basic slab reinforcement.

Code: Select all

"""
   ArchRebar2.py
   22 Aug 2016
"""

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 _Rebar_shape_ACI01(_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::PropertyDistance","G","Rebar","The G length of this rebar")        
        obj.addProperty("App::PropertyDistance","J","Rebar","The J length of this rebar")        
        obj.addProperty("App::PropertyInteger","n","Rebar","The Number  of stirrups")        
        obj.addProperty("App::PropertyLength","Spacing","Rebar","The spacing between the bars")


        obj.ShapeCode="ACI01"
    
    def execute(self,obj):        
        if self.clone(obj):
            return
        
        pl = obj.Placement
        dia = obj.diameter
        A = obj.A
        B = obj.B
        G = obj.G
        J = obj.J

        R = J/2.0
        
        import Part
        V1 = Vector(A,0,J)
        V2 = Vector(J/2.,0,J)
        VC1 = Vector(0,0,J/2.)         
        V3 = Vector(J/2.,0,0)
        V4 = Vector(B-J/2.,0,0)
        VC2 = Vector(B,0,J/2.)
        V5 = Vector(B-J/2.,0,J)
        V6 = Vector(B-G,0,J)

        lines = []
        lines.append( Part.Line(V1,V2) )
        lines.append( Part.Arc(V2,VC1,V3) )
        lines.append( Part.Line(V3,V4) )
        lines.append( Part.Arc(V4,VC2,V5) )
        lines.append( Part.Line(V5,V6) )

        spath = Part.Shape(lines)
        wpath  = Part.Wire(spath.Edges)
        edge1 = Part.__sortEdges__(spath.Edges)
        wpath  = Part.Wire(edge1)
        wire = Part.Wire(wpath)

        bpoint = V1
        bvec = V2.sub(V1).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,obj.Spacing,0 ))
                    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

dia = 9
factor = 6
def makeRebar_shape_ACI01(dia=dia , A=(factor/2+4)*dia , B=1000 , G=(factor/2+4)*dia , J=factor*dia ,
      n=1 , spacing=200,  placement = (0,0,0)):

    obj = FreeCAD.ActiveDocument.addObject("Part::FeaturePython","RebarACI01")
    _Rebar_shape_ACI01(obj)
    obj.diameter = dia
    obj.A = A
    obj.B = B
    obj.G = G
    obj.J = J
    obj.n = n
    obj.Spacing = spacing
    
    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__":
    if False:
        rebar1 = makeRebarU()
        rebar2 = makeRebarU(placement = (0, 500, 0))
        rebar3 = makeRebarU(dia= 25 , placement = (0, 1000, 0))
        rebar4 = makeRebarU(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 False:
        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)
    
    
    if True:
        rebarACI01= makeRebar_shape_ACI01(dia=12 , A = 300 , B=4000 , G=300,J=12*6)
        rebarACI02= makeRebar_shape_ACI01(dia=12 , A = 300 , B=4000 , G=300,J=12*6)    

    FreeCAD.ActiveDocument.recompute()
    Msg("\nDone!!\n\n")
Slab_Rebar_FirstStep.png
Slab_Rebar_FirstStep.png (367.95 KiB) Viewed 1895 times
Attachments
Test_SlabRebar01.FCStd
(28.57 KiB) Downloaded 38 times
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 »

You where defining shape codes as an Attribute! Where do you get the shape code from? Is it some standard from your country, some international standard or just your internal code?
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.I'm not sure on shapecode attribute. may be ... ahhh. :oops:
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 »

yorik wrote:I think the code that builds the base wire should be split from the rest, this would allow the same level of freedom as the Rebar1, where you can if you want, draw yourself your own rebar...
I have another (better) idea: Let's make the rebar1 a sub-case of rebar2.
User avatar
chakkree
Posts: 327
Joined: Tue Jun 30, 2015 12:58 am
Location: Bangkok Thailand

Re: Test Create ArchRebar2 Object

Post by chakkree »

yorik wrote: I have another (better) idea: Let's make the rebar1 a sub-case of rebar2.
Maybe create a new toolbar in ArchWorkbench,"Arch Rebar tool"?
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 »

chakkree wrote:Maybe create a new toolbar in ArchWorkbench,"Arch Rebar tool"?
With drop-down items... Very good idea. I just made one like that for Arch Pipes.
Post Reply