But I can not set transparent to a glass panel.
Code: Select all
"""
Custom Door Object
"""
import ArchCommands,ArchComponent,FreeCAD
from FreeCAD import Vector , Placement
class Door_D1(ArchComponent.Component):
def __init__(self,obj):
ArchComponent.Component.__init__(self,obj)
obj.addProperty("App::PropertyDistance","Width","Door","The Width of this door")
obj.addProperty("App::PropertyDistance","Height","Door","The height of this door")
obj.addProperty("App::PropertyDistance","FrameThickness","Door","The Thickness of this door's frame")
obj.addProperty("App::PropertyDistance","FrameWidth","Door","The Width of this door's frame")
obj.addProperty("App::PropertyDistance","LeafFrameWidth","Door","The Width of this door's frame")
obj.Role = ['Door']
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):
pl = obj.Placement
H1 = obj.Height
W1 = obj.Width
t = obj.FrameThickness
w = obj.FrameWidth
# Door Frame
import Part
points = []
points.append(Vector(0,0,0))
points.append(Vector(0,0,H1))
points.append(Vector(W1,0,H1))
points.append(Vector(W1,0,0))
points.append(Vector(W1-w,0,0))
points.append(Vector(W1-w,0,H1-w))
points.append(Vector(w,0,H1-w))
points.append(Vector(w,0,0))
points.append(Vector(0,0,0))
lines = []
for i in range(1, len(points)):
lines.append(Part.Line(points[i],points[i-1]))
S1 = Part.Shape(lines)
W = Part.Wire(S1.Edges)
face = Part.Face(W)
DoorFrame = face.extrude(Vector(0,t,0))
shapes = []
shapes.append(DoorFrame)
# Door Leaf Frame
w2 = obj.LeafFrameWidth # width of frame of leaf
h2 = H1 - w # height of leaf
W2 = (W1-2*w)/2./2. + w2/2 # width of leaf
points = []
points.append(Vector(w,0,0))
points.append(Vector(w,0,h2))
points.append(Vector(w+W2,0,h2))
points.append(Vector(w+W2,0,0))
points.append(Vector(w,0,0))
lines = []
for i in range(1, len(points)):
lines.append(Part.Line(points[i],points[i-1]))
S1 = Part.Shape(lines)
W = Part.Wire(S1.Edges)
face = Part.Face(W)
points2 = []
points2.append(Vector(w+w2,0,w2))
points2.append(Vector(w+w2,0,h2-w2))
points2.append(Vector(w+W2-w2,0,h2-w2))
points2.append(Vector(w+W2-w2,0,w2))
points2.append(Vector(w+w2,0,w2))
lines2 = []
for i in range(1, len(points2)):
lines2.append(Part.Line(points2[i],points2[i-1]))
S2 = Part.Shape(lines2)
void_2 = Part.Wire(S2.Edges)
face2 = Part.Face(void_2)
face3=face.cut(face2)
LeafFrame = face3.extrude(Vector(0,30,0))
LeafFrame.translate(Vector(0,20+30,0))
LeafFrame2 = LeafFrame.copy()
LeafFrame2.translate(Vector(W2-w2,-30,0))
LeafFrame3 = LeafFrame2.copy()
LeafFrame3.translate(Vector(W2,0,0))
LeafFrame4 = LeafFrame.copy()
LeafFrame4.translate(Vector(W1-w-w-W2,0,0)) #W1-w-W2
shapes.append(LeafFrame)
shapes.append(LeafFrame2)
shapes.append(LeafFrame3)
shapes.append(LeafFrame4)
# Glass
H3 = H1 - w - w2*2 # height of glass
W3 = W2 - w2*2 # width of glass
points = []
points.append(Vector(0,0,0))
points.append(Vector(0,0,H3))
points.append(Vector(W3,0,H3))
points.append(Vector(W3,0,0))
points.append(Vector(0,0,0))
lines = []
for i in range(1, len(points)):
lines.append(Part.Line(points[i],points[i-1]))
S3 = Part.Shape(lines)
W3 = Part.Wire(S3.Edges)
faceFGlass = Part.Face(W3)
LeafGlass = faceFGlass.extrude(Vector(0,6,0))
LeafGlass.translate(Vector(w+w2,+100-20-30+15-3,w2))
#LeafGlass.Transparency = 80
LeafGlass4 = LeafGlass.copy()
LeafGlass4.translate(Vector(W2*3-w2*2,0,0))
LeafGlass2 = LeafGlass.copy()
LeafGlass2.translate(Vector(W2-w2,-30,0))
LeafGlass3 = LeafGlass2.copy()
LeafGlass3.translate(Vector(W2,0,0))
shapes.append(LeafGlass)
shapes.append(LeafGlass2)
shapes.append(LeafGlass3)
shapes.append(LeafGlass4)
if shapes:
obj.Shape = Part.makeCompound(shapes)
obj.Placement = pl
class _ViewProviderDoor(ArchComponent.ViewProviderComponent):
def __init__(self,vobj):
ArchComponent.ViewProviderComponent.__init__(self,vobj)
def getIcon(self):
import Arch_rc
return ":/icons/Arch_Window_Tree.svg"
def makeDoor_D1(width=2600 , height =2050 , FrameWidth= 50, FrameThickness=100 ,
LeafFrameWidth=100,placement = (0,0,0) ):
obj = FreeCAD.ActiveDocument.addObject("Part::FeaturePython","Door")
Door_D1(obj)
obj.Width = width
obj.Height = height
obj.FrameThickness = FrameThickness
obj.FrameWidth = FrameWidth
obj.LeafFrameWidth =LeafFrameWidth
obj.Placement.Base = Vector(placement)
if FreeCAD.GuiUp:
_ViewProviderDoor(obj.ViewObject)
return obj
if __name__=="__main__":
D1 = makeDoor_D1()
FreeCAD.ActiveDocument.recompute()
Msg("\nDone!!\n\n")