測量境界座標インポートcad

51609 ワード

from pyautocad import Autocad, APoint
import numpy
import tkinter as tk
from tkinter import filedialog, messagebox
from decimal import Decimal
import datetime
today = datetime.date.today()
now = datetime.datetime.now()

print(now.hour,type(now.hour))


'''          '''
window = tk.Tk()
window.title( "        1.0  by:    " )
window.geometry( '490x170+800+200' )  # 290 160     ,+1000 +10               

# window.resizable( 0, 0 )
window['background'] = 'DimGray'

def about():
    tk.messagebox.showinfo( '  ', "        1.0


by: 2021.01.23
:[email protected]"
) menubar = tk.Menu( window ) file_menu = tk.Menu( menubar, tearoff=False ) menubar.add_command( label=' ', command=about ) window.config( menu=menubar ) r_value = tk.IntVar() class Variable: def __init__(self): self.one = "" self.File_path = "" self.File_name = "" self.Save_path = "" self.pnts = None self.layer = None self.r = None self.cp = None self.gd_name = None def r_print(self):# self.r = r_value.get() def get_gravity_point(self,points): """ @brief @param points The points @return The center of gravity point. """ if len( points ) <= 2: return list() area = Decimal( 0.0 ) x, y = Decimal( 0.0 ), Decimal( 0.0 ) for i in range( len( points ) ): lng = Decimal( points[i][0] ) lat = Decimal( points[i][1] ) nextlng = Decimal( points[i - 1][0] ) nextlat = Decimal( points[i - 1][1] ) tmp_area = (nextlng * lat - nextlat * lng) / Decimal( 2.0 ) area += tmp_area x += tmp_area * (lng + nextlng) / Decimal( 3.0 ) y += tmp_area * (lat + nextlat) / Decimal( 3.0 ) x = x / area y = y / area self.cp = APoint(float( x ), float( y )) def open(self): # File_path = filedialog.askopenfilenames( filetypes=[(" ", "txt")], title=" " ) # if not File_path: tk.messagebox.showinfo( ' ', " !" ) else: self.File_path = File_path def formatting(self, path, r): # constant = float(text1_var.get())# with open( path ) as f:# p = [] c = [] val = f.readlines()# if r == 2:# val = [x.split( "," ) for x in val]# , for s in val[:-1]:# A = float( s[0] ) - constant # x B = float( s[1][:-1] ) #y c.append([A,B]) p.append( APoint( A, B ) )# Ax,By pnts = numpy.array( [m for n in p for m in n], dtype=numpy.float )# self.cp = c self.pnts = pnts self.layer = " " #cad elif r == 1: # tb = [] # J1 n = [] # j1 text = [] # j1 d = [] count = 0 # for s in val: # if "J1" in s: # J1 s tb.append( val.index( s ) ) # J1 for q in range( int(len( tb ) / 2) ): # 1,2 3,4 5,6 3 text.append( val[tb[count]:tb[count + 1]] ) count += 2 for r in text: for w in r: k = w.split( "," ) A = float( k[4] ) B = float( k[5] ) - constant # d.append([B,A]) n.append( APoint( B, A ) ) p.append( n ) c.append(d) n = [] d = [] self.cp = c self.pnts = p self.layer = " " elif r == 3: # , tb = [] text = [] n = [] count = 0 d = [] gd_name = [] for s in val: if "@" in s: tb.append( val.index( s ) ) gd_name.append(" "+s.split(",")[0]) self.gd_name = gd_name for q in range( len( tb ) ): if q < len( tb ) - 1: text.append( val[tb[count] + 1:tb[count + 1] - 1] ) count += 1 if q == len( tb ) - 1: text.append( val[tb[count] + 1:-1] ) for r in text: for w in r: k = w.split( "," ) A = float( k[2] ) B = float( k[3] ) - constant n.append( APoint( B, A ) ) d.append([B,A]) p.append( n ) c.append(d) n = [] d = [] self.cp = c self.pnts = p self.layer = " " myobject = Variable() def map(): myobject.open() # cad acad = Autocad( create_if_not_exists=True ) if 5 < now.hour < 10: acad.prompt( ' , !' ) elif 10 < now.hour < 14: acad.prompt( ' , !' ) elif 14 < now.hour < 18: acad.prompt( ' , !' ) elif now.hour > 18: acad.prompt( ' , !' ) for path in myobject.File_path: myobject.formatting( path, myobject.r ) name = path.split("/")[-1][:-4] # layerobj = acad.ActiveDocument.Layers.Add( myobject.layer ) acad.ActiveDocument.ActiveLayer = layerobj # ClrNum = 1 layerobj.color = ClrNum # if myobject.r == 3 or myobject.r == 1: for pnts in myobject.pnts: pnts = numpy.array( [m for n in pnts for m in n], dtype=numpy.float ) pnts = Autocad.aDouble( pnts ) pline_obj = acad.model.AddPolyLine( pnts ) pline_obj.Closed = True # if myobject.r == 1: for c in myobject.cp: myobject.get_gravity_point(c) text = acad.model.AddText( "{0}".format( name ), myobject.cp, 1.5 ) if myobject.r == 3: n = 0 for c in myobject.cp: myobject.get_gravity_point(c) text = acad.model.AddText( "{0}".format( myobject.gd_name[n] ), myobject.cp, 1.5 ) n += 1 n = 0 else: pnts = Autocad.aDouble( myobject.pnts ) pline_obj = acad.model.AddPolyLine( pnts ) pline_obj.Closed = True # myobject.get_gravity_point(myobject.cp) text = acad.model.AddText( "{0}".format( name ), myobject.cp, 1.5 ) # acad.ActiveDocument.Application.preferences.OpenSave.AutoSaveInterval = 0.51 tk.messagebox.showinfo( ' ', " , " ) tk.Radiobutton( window, text=' ', variable=r_value, value=1, command=myobject.r_print , width=12).grid( row=1, column=0 ) tk.Radiobutton( window, text=' ', variable=r_value, value=2, command=myobject.r_print , width=12).grid( row=2, column=0 ) tk.Radiobutton( window, text=' ', variable=r_value, value=3, command=myobject.r_print , width=12).grid( row=3, column=0 ) lable1 = tk.Label(window, text="[ 40 ]", width=15).grid(row=0, column=0) text1_var = tk.StringVar() # text_1 text1_var.set(r'40000000') text1 = tk.Entry(window, textvariable=text1_var, bd=5).grid(row=0, column=1) tk.Button( window, text=" cad", width=15, height=1, command=map, bg="Silver" ).grid( row=5, column=0 ) text20 = tk.Text(window, width=50, height=12) text20.grid(row=1, column=1, rowspan=5, columnspan=2) text20.tag_config("tag_1", backgroun="yellow", foreground="red") text20.insert("insert", "1. cad!

2. :cad ;

"
"3. : ,

"
"4. :cad 【 】+

"
) text20.insert("end", "5. :
[email protected]"
, "tag_1") window.mainloop() #text = acad.model.AddText("{0}".format(text), p, 15)