@@ -32,6 +32,7 @@ def __init__(self, plan_name: str = "Survey Plan", scale: float = 1.0, dxf_versi
3232 self .doc .header ["$AUNITS" ] = 1 # Degrees/minutes/seconds
3333 self .doc .header ["$AUPREC" ] = 3 # 0d00'00"
3434 self .doc .header ["$ANGBASE" ] = 90.0 # set 0° direction to North
35+ print (dxf_version )
3536
3637 def setup_layers (self ):
3738 self .doc .layers .add (name = "LABELS" , color = colors .BLACK )
@@ -228,6 +229,18 @@ def add_greenspace(self, points: List[Tuple[float, float]], coords):
228229 hatch .set_pattern_fill ('ANSI31' , scale = 0.5 )
229230 hatch .paths .add_polyline_path (coords , is_closed = True )
230231
232+ def add_label_mtext (self , text : str , x : float , y : float , angle : float = 0.0 , height : float = 1.0 ):
233+ x = x * self .scale
234+ y = y * self .scale
235+ height = height * self .scale
236+
237+ text = self .msp .add_mtext (text = text , dxfattribs = {'style' : 'SURVEY_TEXT' })
238+ text .dxf .attachment_point = ezdxf .enums .MTextEntityAlignment .MIDDLE_CENTER
239+ text .dxf .char_height = height
240+ text .set_location ((x , y ))
241+ text .set_rotation (angle )
242+
243+
231244 def add_label (self , text : str , x : float , y : float , angle : float = 0.0 , height : float = 1.0 ):
232245 x = x * self .scale
233246 y = y * self .scale
@@ -258,7 +271,7 @@ def add_text(self, text: str, x: float, y: float, height: float = 1.0, rotation:
258271 dxfattribs = {
259272 'layer' : 'TEXT' ,
260273 'height' : height ,
261- 'style' : 'STANDARD ' ,
274+ 'style' : 'SURVEY_TEXT ' ,
262275 "rotation" : rotation ,
263276 }
264277 ).set_placement (
@@ -289,7 +302,7 @@ def draw_north_arrow(self, x: float, y: float, height: float = 100.0):
289302 'color' : 5 ,
290303 }
291304 ).set_placement (
292- ( - height * 0.3 , height - (height * 0.25 )),
305+ ( - height * 0.3 , height - (height * 0.2 )),
293306 align = TextEntityAlignment .MIDDLE_CENTER
294307 )
295308
@@ -300,7 +313,7 @@ def draw_north_arrow(self, x: float, y: float, height: float = 100.0):
300313 'color' : 5 ,
301314 }
302315 ).set_placement (
303- (height * 0.2 , height - (height * 0.25 )),
316+ (height * 0.2 , height - (height * 0.2 )),
304317 align = TextEntityAlignment .MIDDLE_CENTER
305318 )
306319
@@ -560,7 +573,7 @@ def draw_topo_point(self, x: float, y: float, z: float = 0, label: str = None, t
560573 dxfattribs = {
561574 'layer' : 'SPOT_HEIGHTS' ,
562575 'height' : text_height ,
563- 'style' : 'Standard ' ,
576+ 'style' : 'SURVEY_TEXT ' ,
564577 'color' : 7 # Black/White
565578 }
566579 ).set_placement (
@@ -594,7 +607,7 @@ def add_grid_mesh_label(self, x: float, y: float, z: float, label: str, text_hei
594607 self .msp .add_text (label , dxfattribs = {
595608 "layer" : "GRID_MESH" ,
596609 "height" : text_height ,
597- "style" : "Standard " ,
610+ "style" : "SURVEY_TEXT " ,
598611 "rotation" : rotation
599612 }).set_placement ((x , y , z ),)
600613
@@ -618,7 +631,7 @@ def add_grid_mesh_corner_coords(self, x: float, y: float, z: float, label: str,
618631 self .msp .add_text (label , dxfattribs = {
619632 "layer" : "GRID_MESH" ,
620633 "height" : text_height ,
621- "style" : "Standard " ,
634+ "style" : "SURVEY_TEXT " ,
622635 "rotation" : rotation
623636 }).set_placement ((x , y , z ),)
624637
@@ -734,51 +747,51 @@ def save_dwg(self, dxf_filepath: str, filepath: str = None):
734747 filepath = f"{ self .get_filename ()} .dwg"
735748 odafc .convert (dxf_filepath , filepath )
736749
750+ def save (self , paper_size : str = "A4" , orientation : str = "portrait" ):
751+ # with tempfile.TemporaryDirectory() as tmpdir:
752+ filename = self .get_filename ()
753+ dxf_path = os .path .join ("" , f"{ filename } .dxf" )
754+ dwg_path = os .path .join ("" , f"{ filename } .dwg" )
755+ pdf_path = os .path .join ("" , f"{ filename } .pdf" )
756+ zip_path = os .path .join ("" , f"{ filename } .zip" )
757+
758+ self .save_dxf (dxf_path )
759+ self .save_dwg (dxf_path , dwg_path )
760+ self .save_pdf (pdf_path , paper_size = paper_size , orientation = orientation )
761+
762+ # Create a ZIP file containing all three formats
763+ with zipfile .ZipFile (zip_path , "w" ) as zipf :
764+ zipf .write (dxf_path , os .path .basename (dxf_path ))
765+ zipf .write (dwg_path , os .path .basename (dwg_path ))
766+ zipf .write (pdf_path , os .path .basename (pdf_path ))
767+
768+ # url = upload_file(zip_path, folder="survey_plans", file_name=filename)
769+ # if url is None:
770+ # raise Exception("Upload failed")
771+ return "url"
772+
737773 # def save(self, paper_size: str = "A4", orientation: str = "portrait"):
738- # # with tempfile.TemporaryDirectory() as tmpdir:
739- # filename = self.get_filename()
740- # dxf_path = os.path.join("" , f"{filename}.dxf")
741- # dwg_path = os.path.join("" , f"{filename}.dwg")
742- # pdf_path = os.path.join("" , f"{filename}.pdf")
743- # zip_path = os.path.join("" , f"{filename}.zip")
774+ # with tempfile.TemporaryDirectory() as tmpdir:
775+ # filename = self.get_filename()
776+ # dxf_path = os.path.join(tmpdir , f"{filename}.dxf")
777+ # dwg_path = os.path.join(tmpdir , f"{filename}.dwg")
778+ # pdf_path = os.path.join(tmpdir , f"{filename}.pdf")
779+ # zip_path = os.path.join(tmpdir , f"{filename}.zip")
744780 #
745- # self.save_dxf(dxf_path)
746- # self.save_dwg(dxf_path, dwg_path)
747- # self.save_pdf(pdf_path, paper_size=paper_size, orientation=orientation)
781+ # self.save_dxf(dxf_path)
782+ # self.save_dwg(dxf_path, dwg_path)
783+ # self.save_pdf(pdf_path, paper_size=paper_size, orientation=orientation)
748784 #
749- # # Create a ZIP file containing all three formats
750- # with zipfile.ZipFile(zip_path, "w") as zipf:
751- # zipf.write(dxf_path, os.path.basename(dxf_path))
752- # zipf.write(dwg_path, os.path.basename(dwg_path))
753- # zipf.write(pdf_path, os.path.basename(pdf_path))
785+ # # Create a ZIP file containing all three formats
786+ # with zipfile.ZipFile(zip_path, "w") as zipf:
787+ # zipf.write(dxf_path, os.path.basename(dxf_path))
788+ # zipf.write(dwg_path, os.path.basename(dwg_path))
789+ # zipf.write(pdf_path, os.path.basename(pdf_path))
754790 #
755- # # url = upload_file(zip_path, folder="survey_plans", file_name=filename)
756- # # if url is None:
757- # # raise Exception("Upload failed")
758- # return "url"
759-
760- def save (self , paper_size : str = "A4" , orientation : str = "portrait" ):
761- with tempfile .TemporaryDirectory () as tmpdir :
762- filename = self .get_filename ()
763- dxf_path = os .path .join (tmpdir , f"{ filename } .dxf" )
764- dwg_path = os .path .join (tmpdir , f"{ filename } .dwg" )
765- pdf_path = os .path .join (tmpdir , f"{ filename } .pdf" )
766- zip_path = os .path .join (tmpdir , f"{ filename } .zip" )
767-
768- self .save_dxf (dxf_path )
769- self .save_dwg (dxf_path , dwg_path )
770- self .save_pdf (pdf_path , paper_size = paper_size , orientation = orientation )
771-
772- # Create a ZIP file containing all three formats
773- with zipfile .ZipFile (zip_path , "w" ) as zipf :
774- zipf .write (dxf_path , os .path .basename (dxf_path ))
775- zipf .write (dwg_path , os .path .basename (dwg_path ))
776- zipf .write (pdf_path , os .path .basename (pdf_path ))
777-
778- url = upload_file (zip_path , folder = "survey_plans" , file_name = filename )
779- if url is None :
780- raise Exception ("Upload failed" )
781- return url
791+ # url = upload_file(zip_path, folder="survey_plans", file_name=filename)
792+ # if url is None:
793+ # raise Exception("Upload failed")
794+ # return url
782795
783796
784797
0 commit comments