Skip to content

Commit

Permalink
add export to dxf
Browse files Browse the repository at this point in the history
  • Loading branch information
ebrahimraeyat committed Sep 12, 2020
1 parent c4a1df4 commit 9686afa
Show file tree
Hide file tree
Showing 5 changed files with 22,224 additions and 35 deletions.
135 changes: 101 additions & 34 deletions column_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,6 @@ def __init__(self, obj):
def set_properties(self, obj):
self.Type = "ColumnType"

# if not hasattr(obj, "n"):
# obj.addProperty(
# "App::PropertyEnumeration",
# "n",
# "IPE",
# )
# obj.n = ['2', '3']

if not hasattr(obj, "size"):
obj.addProperty(
Expand Down Expand Up @@ -95,7 +88,7 @@ def set_properties(self, obj):
"App::PropertyFloat",
"v_scale",
"column_type",
).v_scale = .5
).v_scale = .25

if not hasattr(obj, "composite_deck"):
obj.addProperty(
Expand All @@ -104,6 +97,70 @@ def set_properties(self, obj):
"Deck",
).composite_deck = True

if not hasattr(obj, "ipe_name"):
obj.addProperty(
"App::PropertyString",
"ipe_name",
"childrens_name",
)
obj.setEditorMode("ipe_name", 1)

if not hasattr(obj, "flang_plates_name"):
obj.addProperty(
"App::PropertyStringList",
"flang_plates_name",
"childrens_name",
)
obj.setEditorMode("flang_plates_name", 1)

if not hasattr(obj, "web_plates_name"):
obj.addProperty(
"App::PropertyStringList",
"web_plates_name",
"childrens_name",
)
obj.setEditorMode("web_plates_name", 1)

if not hasattr(obj, "connection_ipes_name"):
obj.addProperty(
"App::PropertyStringList",
"connection_ipes_name",
"childrens_name",
)
obj.setEditorMode("connection_ipes_name", 1)

if not hasattr(obj, "souble_ipes_name"):
obj.addProperty(
"App::PropertyStringList",
"souble_ipes_name",
"childrens_name",
)
obj.setEditorMode("souble_ipes_name", 1)

if not hasattr(obj, "base_plate_name"):
obj.addProperty(
"App::PropertyStringList",
"base_plate_name",
"childrens_name",
)
obj.setEditorMode("base_plate_name", 1)

if not hasattr(obj, "neshimans_name"):
obj.addProperty(
"App::PropertyStringList",
"neshimans_name",
"childrens_name",
)
obj.setEditorMode("neshimans_name", 1)

if not hasattr(obj, "nardebani_names"):
obj.addProperty(
"App::PropertyStringList",
"nardebani_names",
"childrens_name",
)
obj.setEditorMode("nardebani_names", 1)


def execute(self, obj):
scale = 1000 * obj.v_scale
Expand Down Expand Up @@ -193,7 +250,7 @@ def execute(self, obj):
IPE.ViewObject.ShapeColor = (1.0, 0.0, 0.0)

# souble ipe creation
souble_ipe_names = []
souble_ipes_name = []
souble_ipe_section = ipe.copy()
for i, n in enumerate(souble_ipes):
if n == 3:
Expand All @@ -205,17 +262,17 @@ def execute(self, obj):
h = souble_ipe_levels[i + 1] - souble_ipe_levels[i]
souble_ipe_obj.Height = h
souble_ipe_obj.ViewObject.ShapeColor = (.80, 0.0, 0.0)
souble_ipe_names.append(souble_ipe_obj.Name)
souble_ipes_name.append(souble_ipe_obj.Name)

flang_plate_names = []
flang_plates_name = []
connection_ipes = []
neshiman_levels = []
neshiman_obj_names = []
neshimans_name = []
step_file = join(dirname(abspath(__file__)),"shapes", "neshiman.step")
if obj.composite_deck:
neshiman_base_z = 0
else:
neshiman_base_z = 100 * obj.v_scale
neshiman_base_z = 100 * obj.v_scale * 2

import ImportGui

Expand All @@ -236,7 +293,7 @@ def execute(self, obj):
h = merge_flang_levels[i + 1] - merge_flang_levels[i]
PLATE.Height = h
PLATE.ViewObject.ShapeColor = (0.0, 0.0, 1.0)
flang_plate_names.append(PLATE.Name)
flang_plates_name.append(PLATE.Name)
# create neshimans
for lev in levels[1:]:
if merge_flang_levels[i] < lev * scale < merge_flang_levels[i + 1]:
Expand All @@ -250,12 +307,13 @@ def execute(self, obj):
o = new_instances.pop()
o.Placement.Base = FreeCAD.Vector(0, y, z) + obj.Placement.Base
o.ViewObject.ShapeColor = (1.0, 1.0, 0.0)
Draft.scale(o, FreeCAD.Vector(1, 1, obj.v_scale), copy=False)
neshiman_obj_names.append(o.Name)
Draft.scale(o, FreeCAD.Vector(1, 1, obj.v_scale * 2), copy=False)
neshimans_name.append(o.Name)
neshiman_levels.append(lev)

nardebani_names = []
if obj.pa_baz:
flangs_and_3ipes = flang_plate_names + souble_ipe_names
flangs_and_3ipes = flang_plates_name + souble_ipes_name
empty_levels = find_empty_levels(flangs_and_3ipes, levels, scale)
print(f"empty_levels = {empty_levels}")
if empty_levels:
Expand Down Expand Up @@ -290,7 +348,7 @@ def execute(self, obj):
width = bb.XLength - bf / 2
height = 5
y = (d + height) / 2
# flangs_and_ipes = connection_ipes + flang_plate_names
# flangs_and_ipes = connection_ipes + flang_plates_name
# flangs_and_ipes = sorted(flangs_and_ipes, key=lambda name: FreeCAD.ActiveDocument.getObject(name).Base.Shape.BoundBox.ZMin)
# for i in range(len(flangs_and_ipes) - 1):
# o1 = FreeCAD.ActiveDocument.getObject(flangs_and_ipes[i])
Expand All @@ -315,7 +373,7 @@ def execute(self, obj):
PLATE.Height = .15 * scale
PLATE.ViewObject.ShapeColor = (0.0, 0.0, 1.0)
_obj_ = Draft.make_ortho_array(PLATE, v_z=FreeCAD.Vector(0.0, 0.0, space), n_x=1, n_y=1, n_z=n_z)
flang_plate_names.append(_obj_.Name)
nardebani_names.append(_obj_.Name)

for lev in levels[1:]:
if lev not in neshiman_levels:
Expand All @@ -331,11 +389,11 @@ def execute(self, obj):
o = new_instances.pop()
o.Placement.Base = FreeCAD.Vector(0, y, z) + obj.Placement.Base
o.ViewObject.ShapeColor = (1.0, 1.0, 0.0)
Draft.scale(o, FreeCAD.Vector(1, 1, obj.v_scale), copy=False)
neshiman_obj_names.append(o.Name)
Draft.scale(o, FreeCAD.Vector(1, 1, obj.v_scale * 2), copy=False)
neshimans_name.append(o.Name)
neshiman_levels.append(lev)

web_plate_names = []
web_plates_name = []
for i, plate in enumerate(merge_web_plates):
if plate:
width = plate[0]
Expand All @@ -352,7 +410,7 @@ def execute(self, obj):
h = merge_web_levels[i + 1] - merge_web_levels[i]
PLATE.Height = h
PLATE.ViewObject.ShapeColor = (0.0, 1.0, 0.0)
web_plate_names.append(PLATE.Name)
web_plates_name.append(PLATE.Name)

# insert BASE PLATE
h = .02 * scale
Expand All @@ -365,8 +423,17 @@ def execute(self, obj):
base_plate.Placement.Base = FreeCAD.Vector(x, y, z)
base_plate.ViewObject.ShapeColor = (1.0, 0.0, 0.0)

childrens_name = flang_plate_names + web_plate_names + [IPE.Name] + \
[base_plate.Name] + connection_ipes + neshiman_obj_names + souble_ipe_names
obj.ipe_name = IPE.Name
obj.flang_plates_name = flang_plates_name
obj.web_plates_name = web_plates_name
obj.base_plate_name = [base_plate.Name]
obj.connection_ipes_name = connection_ipes
obj.neshimans_name = neshimans_name
obj.souble_ipes_name = souble_ipes_name
obj.nardebani_names = nardebani_names

childrens_name = [IPE.Name] + flang_plates_name + web_plates_name + nardebani_names + \
[base_plate.Name] + connection_ipes + neshimans_name + souble_ipes_name
old_childrens_name = obj.childrens_name
obj.childrens_name = childrens_name
for name in old_childrens_name:
Expand Down Expand Up @@ -449,7 +516,7 @@ def getIcon(self):



def make_column_type(heights, sections_name, size=16, pa_baz=False, base_level=0, extend_length=1.2, pos=(0, 0)):
def make_column_type(heights, sections_name, size=16, pa_baz=False, base_level=0, extend_length=.8, pos=(0, 0)):
'''
'''
Expand All @@ -472,15 +539,15 @@ def make_column_type(heights, sections_name, size=16, pa_baz=False, base_level=0
if __name__ == '__main__':
make_column_type([4, 3.2, 3.2, 3.2, 3.3, 5], ['2IPE30PL200x8w200x5', '2IPE30PL200x8w200x5', '2IPE30PL200x8','2IPE30PL200x8', '2IPE30w200x5', '2IPE30w200x5'], base_level=-1.2, pos=(0, 0), size="30")
make_column_type([4, 3.2, 3.2, 3.2, 3.3, 5], ['2IPE24PL300x8w200x5', '2IPE24PL250x8w200x5', '2IPE24PL200x8','2IPE24PL200x8', '2IPE24w150x5', '2IPE24w150x5'], base_level=-1.2, pos=(2000, 0), size="24", pa_baz=True)
# make_column_type([4, 3.2, 3.2, 3.2, 3.3, 5], ['2IPE24w200x5', '2IPE24PL250x8w200x5', '2IPE24PL200x8','2IPE24PL200x8', '2IPE24w150x5', '2IPE24w150x5'], base_level=-1.2, pos=(4000, 0), size="24", pa_baz=True)
# make_column_type([4, 3.2, 3.2, 3.2, 3.3, 5], ['2IPE14', '2IPE14', '2IPE14', '2IPE14', '2IPE14', '2IPE14'], base_level=-1.2, pos=(6000, 0), size="14", pa_baz=True)
# make_column_type([4, 3.2, 3.2, 3.2, 3.3, 5, 3, 3], ['3IPE18PL310x10w140x8', '3IPE18PL310x10', '3IPE18PL310x8', '3IPE18PL230x8', '3IPE18PL230x6', '3IPE18', '3IPE18', '3IPE18'], base_level=-1.2, pos=(8000, 0), size="18", pa_baz=True)
# make_column_type([4, 3.2, 3.2, 3.2, 3.3, 5, 3, 3], ['2IPE18PL310x10w140x8', '2IPE18PL310x10', '2IPE18PL310x8', '2IPE18PL230x8', '2IPE18PL230x6', '2IPE18PL230x6', '2IPE18PL230x6', '2IPE18PL230x6w140x8'], base_level=-1.2, pos=(10000, 0), size="18", pa_baz=True)
make_column_type([4, 3.2, 3.2, 3.2, 3.3, 5], ['2IPE24w200x5', '2IPE24PL250x8w200x5', '2IPE24PL200x8','2IPE24PL200x8', '2IPE24w150x5', '2IPE24w150x5'], base_level=-1.2, pos=(4000, 0), size="24", pa_baz=True)
make_column_type([4, 3.2, 3.2, 3.2, 3.3, 5], ['2IPE14', '2IPE14', '2IPE14', '2IPE14', '2IPE14', '2IPE14'], base_level=-1.2, pos=(6000, 0), size="14", pa_baz=True)
make_column_type([4, 3.2, 3.2, 3.2, 3.3, 5, 3, 3], ['3IPE18PL310x10w140x8', '3IPE18PL310x10', '3IPE18PL310x8', '3IPE18PL230x8', '3IPE18PL230x6', '3IPE18', '3IPE18', '3IPE18'], base_level=-1.2, pos=(8000, 0), size="18", pa_baz=True)
make_column_type([4, 3.2, 3.2, 3.2, 3.3, 5, 3, 3], ['2IPE18PL310x10w140x8', '2IPE18PL310x10', '2IPE18PL310x8', '2IPE18PL230x8', '2IPE18PL230x6', '2IPE18PL230x6', '2IPE18PL230x6', '2IPE18PL230x6w140x8'], base_level=-1.2, pos=(10000, 0), size="18", pa_baz=True)

# make_column_type([4, 3.2, 3.2, 3.2, 3.3, 5, 3, 3], ['2IPE18PL310x10w140x8', '3IPE18PL310x10', '3IPE18', '2IPE18', '3IPE18PL310x10', '2IPE18', '2IPE18', '2IPE18'], base_level=-1.2, pos=(12000, 0), size="18", pa_baz=True)
make_column_type([4, 3.2, 3.2, 3.2, 3.3, 5, 3, 3], ['2IPE18PL310x10w140x8', '3IPE18PL310x10', '3IPE18', '2IPE18', '3IPE18PL310x10', '2IPE18', '2IPE18', '2IPE18'], base_level=-1.2, pos=(12000, 0), size="18", pa_baz=True)

# make_column_type([4, 3.2, 3.2, 3.2, 3.3, 5, 3, 3], ['2IPE14', '3IPE14PL170x6', '3IPE14PL170x6', '3IPE14', '3IPE14', '3IPE14', '3IPE14', '3IPE14'], base_level=-1.2, pos=(14000, 0), size="14", pa_baz=True)
# make_column_type([4, 3.2, 3.2, 3.2, 3.3, 5, 3, 3], ['2IPE14', '2IPE14', '2IPE14', '2IPE14', '2IPE14', '3IPE14', '3IPE14', '3IPE14'], base_level=-1.2, pos=(16000, 0), size="14", pa_baz=True)
# make_column_type([4, 3.2, 3.2, 3.2, 3.3, 5, 3, 3], ['2IPE16', '3IPE16PL280x8', '3IPE16PL280x8', '3IPE16PL200x6', '3IPE16PL200x6', '3IPE16', '3IPE16'], base_level=-1.2, pos=(18000, 0), size="16", pa_baz=True)
make_column_type([4, 3.2, 3.2, 3.2, 3.3, 5, 3, 3], ['2IPE14', '3IPE14PL170x6', '3IPE14PL170x6', '3IPE14', '3IPE14', '3IPE14', '3IPE14', '3IPE14'], base_level=-1.2, pos=(14000, 0), size="14", pa_baz=True)
make_column_type([4, 3.2, 3.2, 3.2, 3.3, 5, 3, 3], ['2IPE14', '2IPE14', '2IPE14', '2IPE14', '2IPE14', '3IPE14', '3IPE14', '3IPE14'], base_level=-1.2, pos=(16000, 0), size="14", pa_baz=True)
make_column_type([4, 3.2, 3.2, 3.2, 3.3, 5, 3, 3], ['2IPE16', '3IPE16PL280x8', '3IPE16PL280x8', '3IPE16PL200x6', '3IPE16PL200x6', '3IPE16', '3IPE16'], base_level=-1.2, pos=(18000, 0), size="16", pa_baz=True)


2 changes: 1 addition & 1 deletion column_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def set_properties(self, obj):
"App::PropertyFloat",
"v_scale",
"column_type",
).v_scale = .5
).v_scale = .25

if not hasattr(obj, "childrens_name"):
obj.addProperty(
Expand Down
111 changes: 111 additions & 0 deletions techdraw.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
import TechDraw
import FreeCADGui as Gui
import FreeCAD
import ezdxf


def add_edges_to_dxf(edges, dxfattribs, block):
for e in edges:
p1 = e.Vertexes[0]
p2 = e.Vertexes[1]
block.add_line((p1.X , -p1.Y), (p2.X , -p2.Y), dxfattribs=dxfattribs)

def get_unique_edges(edges, ct, scale, ignore_len=False):
unique_edges = edges[:]

for e in edges:
if ignore_len:
if e.Length >= ignore_len:
unique_edges.remove(e)

edges = unique_edges[:]

if ct.connection_ipes_name and ignore_len:
print("yes")
connection_ipe_name = ct.connection_ipes_name[0]
connection_ipe = FreeCAD.ActiveDocument.getObject(connection_ipe_name)
bb = connection_ipe.Shape.BoundBox
xmin, xmax = bb.XMin - ct.Placement.Base.x, bb.XMax - ct.Placement.Base.x

for e in edges:
# print(f"xmin = {xmin}, xmax = {xmax}, exmin = {e.BoundBox.XMin}")
# break
if xmin < e.BoundBox.XMin / scale < xmax:
unique_edges.remove(e)

return unique_edges


# def get_unique_edges(edges, current_edges=[]):
# unique_edges = current_edges[:]
# for e in edges:
# if unique_edges:FreeCAD.ActiveDocument.getObject(ct.connection_ipes_name[0]).Height.Value
# p1 = e.firstVertex()
# p2 = e.lastVertex()
# equal = False
# for ce in unique_edges:
# p3 = ce.firstVertex()
# p4 = ce.lastVertex()
# if ((p1.Point == p3.Point) and (p2.Point == p4.Point)):
# equal = True
# break
# if not equal:
# unique_edges.append(e)
# else:
# unique_edges.append(e)
# return unique_edges



page = FreeCAD.ActiveDocument.addObject('TechDraw::DrawPage', 'Page')
FreeCAD.ActiveDocument.addObject('TechDraw::DrawSVGTemplate', 'Template')
templateFileSpec = '/usr/share/freecad-daily/Mod/TechDraw/Templates/A0_Landscape_blank.svg'
FreeCAD.ActiveDocument.Template.Template = templateFileSpec
FreeCAD.ActiveDocument.Page.Template = FreeCAD.ActiveDocument.Template
page.ViewObject.show()

new_dwg = ezdxf.readfile("/home/ebi/ali_momen/TEMPLATE.DXF")
msp = new_dwg.modelspace()

cts = []
for o in FreeCAD.ActiveDocument.Objects:
if hasattr(o, "childrens_name"):
cts.append(o)


for ct in cts:
view = FreeCAD.ActiveDocument.addObject('TechDraw::DrawViewPart','View')
view.HardHidden = True
view.ViewObject.LineWidth = .05
view.ViewObject.HiddenWidth = .005
view.Direction = (1, 0, 0)
# view.XDirection = (0, 0, 1)
view.SmoothVisible = False
# view.Perspective = True

names = [ct.ipe_name] + ct.flang_plates_name + ct.base_plate_name + ct.nardebani_names + \
ct.connection_ipes_name + ct.neshimans_name + ct.souble_ipes_name

view.Source = [FreeCAD.ActiveDocument.getObject(name) for name in names]
page.addView(view)
view.Scale = .005
FreeCAD.ActiveDocument.recompute()
Gui.runCommand('TechDraw_ToggleFrame',0)
visible_edges = view.getVisibleEdges()
visible_edges = get_unique_edges(visible_edges, ct, view.Scale, False)
hidden_edges = view.getHiddenEdges()
h = FreeCAD.ActiveDocument.getObject(ct.ipe_name).Height.Value * view.Scale
hidden_edges = get_unique_edges(hidden_edges, ct, view.Scale, h)



block = new_dwg.blocks.new(name = ct.Name)
IPE = FreeCAD.ActiveDocument.getObject(ct.ipe_name)
h = IPE.Height.Value * view.Scale
add_edges_to_dxf(visible_edges, {'layer':"COL"}, block)
add_edges_to_dxf(hidden_edges, {'layer':"COL", "linetype":"DASHED2", "lineweight": 13}, block)
x = ct.Placement.Base.x
msp.add_blockref(ct.Name, (x * view.Scale, 0))
new_dwg.saveas("/home/ebi/ali_momen/ezdxf.dxf")


9 changes: 9 additions & 0 deletions templates/A0_Landscape_blank.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 9686afa

Please sign in to comment.