alles neu mit black formatiert. handler_context.py impl. um weniger Übergabeparameter zu haben
This commit is contained in:
+90
-48
@@ -3,22 +3,32 @@ import plant2dxf
|
||||
from ezdxf import units
|
||||
from ezdxf.entities import Line
|
||||
from ezdxf.addons import importer
|
||||
from ezdxf.math import Matrix44, X_AXIS,Y_AXIS,Z_AXIS
|
||||
def dreh_block(block_name: str, to_doc,lib_doc, winkel) :
|
||||
"""Nimmt ein schon importierten Block und erstellt einen neuen der an der y_axis oder x_axis gedreht wird
|
||||
"""
|
||||
dreh_block_name = block_name +f"_{math.degrees(winkel)}"
|
||||
layer, color = get_insert_color_layer(lib_doc,block_name)
|
||||
if (dreh_block_name in to_doc.blocks):
|
||||
return dreh_block_name
|
||||
block_zwischen = to_doc.blocks.new(name=block_name + f"zwischenschrit_{winkel}", base_point=(0,0,0))
|
||||
block = to_doc.blocks.new(name=dreh_block_name, base_point=(0,0,0))
|
||||
if block_name == "200000146_ES-Element_90_rechts" or block_name =="400102632_ES-Element_90_links" or block_name =="200000241_AS-Element_90_rechts" or block_name =="200000217_AS-Element_90_links":
|
||||
from ezdxf.math import Matrix44, X_AXIS, Y_AXIS, Z_AXIS
|
||||
|
||||
|
||||
def dreh_block(block_name: str, to_doc, lib_doc, winkel):
|
||||
"""Nimmt ein schon importierten Block und erstellt einen neuen der an der y_axis oder x_axis gedreht wird"""
|
||||
dreh_block_name = block_name + f"_{math.degrees(winkel)}"
|
||||
layer, color = get_insert_color_layer(lib_doc, block_name)
|
||||
if dreh_block_name in to_doc.blocks:
|
||||
return dreh_block_name
|
||||
block_zwischen = to_doc.blocks.new(
|
||||
name=block_name + f"zwischenschrit_{winkel}", base_point=(0, 0, 0)
|
||||
)
|
||||
block = to_doc.blocks.new(name=dreh_block_name, base_point=(0, 0, 0))
|
||||
if (
|
||||
block_name == "200000146_ES-Element_90_rechts"
|
||||
or block_name == "400102632_ES-Element_90_links"
|
||||
or block_name == "200000241_AS-Element_90_rechts"
|
||||
or block_name == "200000217_AS-Element_90_links"
|
||||
):
|
||||
rotation_matrix = Matrix44.axis_rotate(X_AXIS, winkel)
|
||||
else:
|
||||
else:
|
||||
rotation_matrix = Matrix44.axis_rotate(Y_AXIS, winkel)
|
||||
|
||||
block_zwischen.add_blockref(block_name,(0,0,0),dxfattribs={"layer":layer,"color": color})
|
||||
block_zwischen.add_blockref(
|
||||
block_name, (0, 0, 0), dxfattribs={"layer": layer, "color": color}
|
||||
)
|
||||
for e in block_zwischen:
|
||||
copy = e.copy()
|
||||
copy.transform(rotation_matrix)
|
||||
@@ -26,7 +36,7 @@ def dreh_block(block_name: str, to_doc,lib_doc, winkel) :
|
||||
return dreh_block_name
|
||||
|
||||
|
||||
def import_block(block_name: str, from_doc, to_doc, winkel = None) -> None:
|
||||
def import_block(block_name: str, from_doc, to_doc, winkel=None) -> None:
|
||||
"""Importiert Blockdefinition block_name von from_doc nach to_doc.
|
||||
|
||||
- Kopiert alle Entities des Blocks
|
||||
@@ -41,16 +51,16 @@ def import_block(block_name: str, from_doc, to_doc, winkel = None) -> None:
|
||||
|
||||
# Alle Linientypen importieren
|
||||
imp.import_table("linetypes")
|
||||
if ((block_name in to_doc.blocks)):
|
||||
if block_name in to_doc.blocks:
|
||||
# speichern der attdef elemente in eine Liste falks diese verhanden sind und gibt diese zurück
|
||||
for ent in src:
|
||||
copy = ent.copy()
|
||||
|
||||
if ent.dxftype() == "ATTDEF":
|
||||
att_def[ent.dxf.tag] =ent.dxf.text
|
||||
att_def[ent.dxf.tag] = ent.dxf.text
|
||||
if ent.dxftype() == "INSERT":
|
||||
|
||||
import_block(ent.dxf.name,from_doc, to_doc,None)
|
||||
import_block(ent.dxf.name, from_doc, to_doc, None)
|
||||
|
||||
if att_def != {}:
|
||||
return att_def
|
||||
@@ -87,21 +97,22 @@ def import_block(block_name: str, from_doc, to_doc, winkel = None) -> None:
|
||||
except Exception:
|
||||
pass
|
||||
# kopiert die elemente von dem element aus dem block und speichert diese in den block für dass Modelspace auf und # speichern der attdef elemente in eine Liste falks diese verhanden sind und gibt diese zurück
|
||||
|
||||
|
||||
for ent in src:
|
||||
copy = ent.copy()
|
||||
|
||||
if ent.dxftype() == "ATTDEF":
|
||||
att_def[ent.dxf.tag] =ent.dxf.text
|
||||
att_def[ent.dxf.tag] = ent.dxf.text
|
||||
if ent.dxftype() == "INSERT":
|
||||
import_block(ent.dxf.name,from_doc, to_doc,None)
|
||||
import_block(ent.dxf.name, from_doc, to_doc, None)
|
||||
tgt.add_entity(copy)
|
||||
|
||||
|
||||
if att_def != {}:
|
||||
return att_def
|
||||
|
||||
|
||||
|
||||
def get_insert_color_layer(lib_doc, blockname):
|
||||
"""Gibt den Layer und die Color für den Jeweiligen block in der Libary datei zurück"""
|
||||
"""Gibt den Layer und die Color für den Jeweiligen block in der Libary datei zurück"""
|
||||
msp_lib = lib_doc.modelspace()
|
||||
color = 0
|
||||
layer = 0
|
||||
@@ -111,34 +122,65 @@ def get_insert_color_layer(lib_doc, blockname):
|
||||
layer = insert.dxf.layer
|
||||
return layer, color
|
||||
|
||||
def rotatate_and_left_motor_umlenk(doc, lib_doc,config):
|
||||
motor_rotation = float(config.get("Ils 2.0 core winkel","winkel_motor"))
|
||||
umlenk_rotation = float(config.get("Ils 2.0 core winkel","winkel_umlenk"))
|
||||
block_Vario_Umlenkstation_500mm ="Vario_Umlenkstation_500mm"
|
||||
|
||||
def rotatate_and_left_motor_umlenk(doc, lib_doc, config):
|
||||
motor_rotation = float(config.get("Ils 2.0 core winkel", "winkel_motor"))
|
||||
umlenk_rotation = float(config.get("Ils 2.0 core winkel", "winkel_umlenk"))
|
||||
block_Vario_Umlenkstation_500mm = "Vario_Umlenkstation_500mm"
|
||||
block_Vario_Motorstation_500mm = "Vario_Motorstation_500mm"
|
||||
blockname_motor_links = block_Vario_Motorstation_500mm +"_links"
|
||||
blockname_motor_links = block_Vario_Motorstation_500mm + "_links"
|
||||
blockname_umlenk_links = block_Vario_Umlenkstation_500mm + "_links"
|
||||
import_block(block_Vario_Umlenkstation_500mm,lib_doc,doc)
|
||||
import_block(block_Vario_Motorstation_500mm,lib_doc,doc)
|
||||
turn_two_blocks_left(doc, block_Vario_Umlenkstation_500mm, block_Vario_Motorstation_500mm, blockname_motor_links, blockname_umlenk_links)
|
||||
import_block(block_Vario_Umlenkstation_500mm, lib_doc, doc)
|
||||
import_block(block_Vario_Motorstation_500mm, lib_doc, doc)
|
||||
turn_two_blocks_left(
|
||||
doc,
|
||||
block_Vario_Umlenkstation_500mm,
|
||||
block_Vario_Motorstation_500mm,
|
||||
blockname_motor_links,
|
||||
blockname_umlenk_links,
|
||||
)
|
||||
|
||||
block_Vario_Umlenkstation_500mm =dreh_block(block_Vario_Umlenkstation_500mm,doc,lib_doc,math.radians(umlenk_rotation))
|
||||
block_Vario_Motorstation_500mm =dreh_block(block_Vario_Motorstation_500mm,doc,lib_doc,math.radians(motor_rotation))
|
||||
blockname_motor_links =dreh_block(blockname_motor_links,doc,lib_doc,math.radians(umlenk_rotation))
|
||||
blockname_umlenk_links =dreh_block(blockname_umlenk_links,doc,lib_doc,math.radians(motor_rotation))
|
||||
return block_Vario_Umlenkstation_500mm,block_Vario_Motorstation_500mm,blockname_motor_links,blockname_umlenk_links
|
||||
block_Vario_Umlenkstation_500mm = dreh_block(
|
||||
block_Vario_Umlenkstation_500mm, doc, lib_doc, math.radians(umlenk_rotation)
|
||||
)
|
||||
block_Vario_Motorstation_500mm = dreh_block(
|
||||
block_Vario_Motorstation_500mm, doc, lib_doc, math.radians(motor_rotation)
|
||||
)
|
||||
blockname_motor_links = dreh_block(
|
||||
blockname_motor_links, doc, lib_doc, math.radians(umlenk_rotation)
|
||||
)
|
||||
blockname_umlenk_links = dreh_block(
|
||||
blockname_umlenk_links, doc, lib_doc, math.radians(motor_rotation)
|
||||
)
|
||||
return (
|
||||
block_Vario_Umlenkstation_500mm,
|
||||
block_Vario_Motorstation_500mm,
|
||||
blockname_motor_links,
|
||||
blockname_umlenk_links,
|
||||
)
|
||||
|
||||
def turn_two_blocks_left(doc, block_1_name_zwischen, block_2_name_zwischen, block_2_left_name, block_1_left_name):
|
||||
|
||||
def turn_two_blocks_left(
|
||||
doc,
|
||||
block_1_name_zwischen,
|
||||
block_2_name_zwischen,
|
||||
block_2_left_name,
|
||||
block_1_left_name,
|
||||
):
|
||||
blockname1 = block_1_name_zwischen
|
||||
blockname2 = block_2_name_zwischen
|
||||
if block_2_left_name not in doc.blocks:
|
||||
matrix = Matrix44.scale(1,-1,1)
|
||||
block1_zwischen = doc.blocks.new(name=block_1_name_zwischen + "zwischenschrit", base_point=(0,0,0))
|
||||
block2_zwischen = doc.blocks.new(name=block_2_name_zwischen + "zwischenschrit", base_point=(0,0,0))
|
||||
block_2 = doc.blocks.new(name=block_2_left_name,base_point=(0,0,0))
|
||||
block_1_left_name = doc.blocks.new(name=block_1_left_name,base_point=(0,0,0))
|
||||
block1_zwischen.add_blockref(blockname1,(0,0,0))
|
||||
block2_zwischen.add_blockref(blockname2,(0,0,0))
|
||||
matrix = Matrix44.scale(1, -1, 1)
|
||||
block1_zwischen = doc.blocks.new(
|
||||
name=block_1_name_zwischen + "zwischenschrit", base_point=(0, 0, 0)
|
||||
)
|
||||
block2_zwischen = doc.blocks.new(
|
||||
name=block_2_name_zwischen + "zwischenschrit", base_point=(0, 0, 0)
|
||||
)
|
||||
block_2 = doc.blocks.new(name=block_2_left_name, base_point=(0, 0, 0))
|
||||
block_1_left_name = doc.blocks.new(name=block_1_left_name, base_point=(0, 0, 0))
|
||||
block1_zwischen.add_blockref(blockname1, (0, 0, 0))
|
||||
block2_zwischen.add_blockref(blockname2, (0, 0, 0))
|
||||
for e in block2_zwischen:
|
||||
copy = e.copy()
|
||||
copy.transform(matrix)
|
||||
@@ -149,11 +191,11 @@ def turn_two_blocks_left(doc, block_1_name_zwischen, block_2_name_zwischen, bloc
|
||||
copy.transform(matrix)
|
||||
block_1_left_name.add_entity(copy)
|
||||
|
||||
|
||||
def add_attributes_to_block(block, attributes):
|
||||
|
||||
"""
|
||||
Fügt einem bestehenden ezdxf-Block Attribut-Definitionen hinzu.
|
||||
|
||||
|
||||
Parameter:
|
||||
block – ein ezdxf.blocks.BlockLayout Objekt
|
||||
attributes – Liste von Tupeln [(tag, value), ...]
|
||||
@@ -161,8 +203,8 @@ def add_attributes_to_block(block, attributes):
|
||||
for tag, value in attributes.items():
|
||||
tag = tag
|
||||
value = value
|
||||
a =block.add_attrib(
|
||||
a = block.add_attrib(
|
||||
tag=tag,
|
||||
text=value,
|
||||
)
|
||||
a.is_invisible = True
|
||||
a.is_invisible = True
|
||||
|
||||
Reference in New Issue
Block a user