Test to change rebar's shape by set new points vector to wire.
Code: Select all
"""
Word size of FreeCAD: 64-bit
Version: 0.19.16616 (Git)
Python version: 3.6.6
"""
from FreeCAD import Vector
import FreeCADGui
def changeUShapeRebar(A= 300 , B=1000 , C=300,
RebarEndType = 0 ,dia=12):
sel = FreeCADGui.Selection.getSelection()[0]
if sel.IfcType=='Reinforcing Bar':
sel.Diameter = dia
sel.Rounding = (3/2+0.5)
if RebarEndType==0: # None
points = [
Vector(0,0,A),
Vector(0,0,0),
Vector(B,0,0),
Vector(B,0,C),
]
elif RebarEndType==1: # Anchored
Lb = 12*dia + 3.5*dia
#if Lb<600 : Lb = 600
points = [
Vector(Lb,0,A),
Vector(0,0,A),
Vector(0,0,0),
Vector(B,0,0),
Vector(B,0,C),
Vector(B-Lb,0,C),
]
Msg(points)
elif RebarEndType==2: # Hook
R = (3/2+0.5)*dia
Lb = 4*dia + R
if Lb<(R+70) : Lb = R+70
points = [
Vector(2*R+0.1,0,A-Lb),
Vector(2*R,0,A),
Vector(0,0,A),
Vector(0,0,0),
Vector(B,0,0),
Vector(B,0,C),
Vector(B-2*R-0.1,0,C),
Vector(B-2*R-0.1,0,C-Lb),
]
wire = sel.OutList[0]
wire.Points = points
if __name__=="__main__":
changeUShapeRebar(RebarEndType=1)
App.activeDocument().recompute()
Msg('Done!\n\n')