-
Notifications
You must be signed in to change notification settings - Fork 0
/
setlateral.py
307 lines (234 loc) · 8.09 KB
/
setlateral.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
import win32com.client # For Application connection
import pythoncom
from pyautocad import Autocad,APoint,aDouble,aInt,aShort
import random as rand
import time
import os
import sys
import glob
def vtpt(x, y, z=0):
return win32com.client.VARIANT(pythoncom.VT_ARRAY | pythoncom.VT_R8, (x, y, z))
def vtobj(obj):
return win32com.client.VARIANT(pythoncom.VT_ARRAY | pythoncom.VT_DISPATCH, obj)
def vtFloat(lis):
""" list converted to floating points"""
return win32com.client.VARIANT(pythoncom.VT_ARRAY | pythoncom.VT_R8, lis)
def vtint(val):
return win32com.client.VARIANT(pythoncom.VT_ARRAY | pythoncom.VT_I2, val)
def vtvariant(var):
return win32com.client.VARIANT(pythoncom.VT_ARRAY | pythoncom.VT_VARIANT, var)
try:
acad = win32com.client.Dispatch("AutoCAD.Application")
doc = acad.ActiveDocument #Document Object
model = doc.ModelSpace
except:
print ("AutoCAD isn't running!")
def delss(setss,doc):
try:
doc.SelectionSets.Item(setss).Delete()
except:
a="Delete selection failed"
#selecionar de acuerdo al criterio de filtro
acad.ZoomExtents
delss('ss1',doc)
ssget1 = doc.SelectionSets.Add('ss1')
SELECT_ALL = int(5) # 5=variable de autocad para selecionar todo
#selecciona entidad circulo, Codigo dxf=0, Filterdata="Circle"
#selecciona radio del circulo, Codigo dxf=40, Filerdata=10, Todos los cirulos con radio =10
#selecciona layer, Codigo dxf=8, Filterdata="uno", y que estan en el layer uno
pt1=vtpt(0,0,0)
pt2=vtpt(0,0,0)#Necesario para parte del filtro
FilterType=vtint((0,8))
FilterData=vtvariant(('Text','Sewer'))
#selecionar de acuerdo al criterio de filtro
ssget1.Select(SELECT_ALL,pt1,pt2,FilterType,FilterData)
#Contar entidades
icount = ssget1.Count
print(icount)
for iobj in ssget1:
iobj.Erase()
dataType = (1001, 1000, 1000, 1040, 1040, 1040, 1040, 1040, 1000, 1040, 1040, 1040, 1040, 1040, 1040,1000) # Define Xdata
data = ('Sewer', 'name1' , ' ',3 , 0.7 , .013 , 0 , 0 , '0' , 2 , 1,0,0,0, 0,' ')
dataTypemaa = (1001, 1040, 1040, 1040, 1040, 1040, 1040, 1040, 1040, 1040, 1000) # Define Xdata
datamaa = ('MAA', 0 , 0, 0 , 0 , 0 , 0 , 0 , 0 , 0 , ' ')
delss('ss1',doc)
mainsel1 = doc.SelectionSets.Add("ss1")
alor=vtpt(0,0,0) #Necesario para parte del filtro
FilterType=vtint((0,8))
FilterData=vtvariant(('Line','Sewer'))
mainsel1.Select(int(5),pt1,pt2,FilterType,FilterData)
sscount = mainsel1.Count +1
print('ss=',sscount)
if sscount>1:
elem= mainsel1[0]
ssobj = [elem for c in range(mainsel1.Count+1)]
xdatamaa =mainsel1[0].GetXData("MAA", dataTypemaa, datamaa)
maa = [xdatamaa[1] for c in range(mainsel1.Count+1)]
#for elem in mainsel1:
#startpoint=elem.startpoint
#endpoint=elem.endpoint
#lineobj=model.AddLine(vtpt(startpoint[0],startpoint[1],0),vtpt(endpoint[0],endpoint[1],0))
#elem.erase()
totlenmax=0
jmax=0
ma5=[]
ma4=[]
i=0 # print (Xdata)
for elem1 in mainsel1:
datamaa1=None
dataTypemaa1=None
xdatamaa =elem1.GetXData("MAA", dataTypemaa, datamaa)
dataTypemaa=xdatamaa[0]
datamaa=xdatamaa[1]
ssobj[int(datamaa[1])]=elem1
maa[int(datamaa[1])]='MAA',datamaa[1],abs(datamaa[2]),* datamaa[3:8],0,datamaa[9] ,' '
if totlenmax<datamaa[9]:
totlenmax=datamaa[9]
jmax=int(datamaa[1])
j1=0
j2=0
j1=int(datamaa[3])
j2=int(datamaa[4])
if j1==0:
ma5.append(int(datamaa[1]))
if j2>0:
ma4.append(int(datamaa[1]))
maa[0]='MAA',0,0,0,0,0,0,0,0,0,' '
#datamaa = *datamaa[0:9], 0, ' '
#datamaa='MAA',datamaa[1],abs(datamaa[2]),* datamaa[3:]
#dataTypemaa1 = vtint(dataTypemaa) # Converse dataType format
#datamaa1= vtvariant(datamaa)
#elem1.SetXData( dataTypemaa1, datamaa1)
#elem1.color=6
for i in range(1, sscount):
xdatamaa =ssobj[i].GetXData("MAA", dataTypemaa, datamaa)
datamaa=xdatamaa[1]
if totlenmax<datamaa[9]:
totlenmax=datamaa[9]
jmax=int(datamaa[1])
# Total Length
for jj in ma5:
#print(jj)
totlen=0
while jj>0 :
totlen=totlen + ssobj[jj].length
totlen8=maa[jj][8]
#print('totlen',totlen,'ma8' ,totlen8)
if totlen >= totlen8:
maa[jj]=*maa[jj][0:8] , totlen , maa[jj][9] , ' '
#print('totlen8',maa[jj])
jj=abs(int(maa[jj][2]))
if maa[jj][8]>totlen :
print(totlen,maa[jj][8])
jj=0
for jj in ma4:
j1=0
j2=0
j3=0
print('j3',maa[jj][2],maa[jj][4],maa[jj][5])
j1=int(maa[jj][3])
j2=int(maa[jj][4])
j3=int(maa[jj][5])
if j2>0 and maa[j2][8]> maa[j1][8] and maa[j2][8]> maa[j3][8]:
maa[jj]='MAA',jj,maa[jj][2],j2,j1,j3,*maa[jj][6:]
if j3>0 and maa[j3][8]> maa[j1][8] and maa[j3][8]> maa[j2][8]:
maa[jj]='MAA',jj,maa[jj][2],j3,j1,j2,*maa[jj][6:]
for i in range(1,sscount) :
j1=0
j2=0
j3=0
j1=int(maa[i][3])
j2=int(maa[i][4])
j3=int(maa[i][5])
#if j1>0:
# maa[j1]='MAA',j1,i,*maa[j1][3:]
#ssobj[j1].color=7
if j2>0:
maa[j2]='MAA',j2,-i,*maa[j2][3:]
if j3>0:
maa[j3]='MAA',j3,-i,*maa[j3][3:]
#ssobj[jmax].color=2
ii=0
for jj in ma5:
ii +=1
if ii>7:
ii=1
while jj>0 :
print(jj)
ssobj[int(jj)].color=ii
jj=maa[int(jj)][2]
ma=[]
jj=jmax
print('jmax',jmax)
ssobj[jmax].color=7
point1=ssobj[jmax].startpoint
model.addtext('AA'+ maa[jmax][10],vtpt(point1[0],point1[1],0),50)
print ('jmax',jmax,maa[jmax][9])
ii=0
ll=0
while jj >0 and ii<sscount :
ii +=1
maa[jj]= *maa[jj][0:10] ,'A'
print(maa[jj])
ssobj[jj].color=7
j1=int(maa[jj][3])
print(maa[j1])
if j1>0:
maa[j1]= *maa[j1][0:10] ,'A'
#ssobj[j1].color=51
j2=int(maa[jj][4])
if j2>0:
#ssobj[j2].color=21
ll=ll+1
maa[j2]= *maa[j2][0:10] ,'A'+ str(ll)
ma.append(j2)
j3=int(maa[jj][5])
if j3>3:
#ssobj[j3].color=43
ll=ll+1
maa[j3]= *maa[j3][0:10] ,'A'+ str(ll)
ma.append(j3)
j4=int(maa[jj][6])
jj=abs(int(maa[jj][2]))
print (ma)
while len(ma)>0 :
jj=ma[0]
ma.remove(ma[0])
latname=maa[jj][10]
print('lat',latname)
ll=0
while jj > 0 :
maa[jj]=* maa[jj][0:10],latname
#ssobj[jj].color=121
j2=int(maa[jj][4])
print (maa[j2][10])
if maa[j2][10]==' ':
#ssobj[j2].color=171
ll=ll+1
maa[j2]= *maa[j2][0:10] ,latname + "-" + str(ll)
ma.append(j2)
j3=int(maa[jj][5])
if maa[j3][10]==' ':
#ssobj[jj].color=151
ll=ll+1
maa[j3]= *maa[j3][0:10] ,latname + "-" + str(ll)
ma.append(j2)
j4=int(maa[jj][6])
jj=int(maa[jj][3])
for i in range(1,sscount) :
point1=ssobj[i].startpoint
model.addtext(maa[i][10],vtpt(point1[0],point1[1],0),5)
print(maa[i])
#--------------------------------------------------------------------
dataTypemaa = (1001, 1040, 1040, 1040, 1040, 1040, 1040, 1040, 1040, 1040, 1000)
for i in range(1,sscount) :
datamaa1=None
dataTypemaa1==None
xdatamaa =ssobj[i].GetXData("MAA", dataTypemaa, datamaa)
#dataTypemaa=xdatamaa[0]
datamaa=xdatamaa[1]
print('ma=',maa[i])
datamaa=maa[i]
dataTypemaa1 = vtint(dataTypemaa) # Converse dataType format
datamaa1= vtvariant(datamaa)
ssobj[i].SetXData( dataTypemaa1, datamaa1)