-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmoload.py
218 lines (170 loc) · 7.28 KB
/
moload.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
import win32com.client # For Application connection
import pythoncom
global maxbasex , maxbasey , minbasex , minbasey , acad
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)
def diaxdata(dia, slope, obj):
dataType = (1001, 1040, 1040, 1040, 1040, 1040, 1040, 1040, 1040, 1040, 1040) # Define Xdata
data = ('Diameter',dia * 10 , slope ,3 , 0.7 , .013 , 0 , 0 , 0 , 2 , 1)
dataType = vtint(dataType) # Converse dataType format
data = vtvariant(data)
obj.SetXData(dataType, data)
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("SS1").Delete()
except:
a="Delete selection failed"
acad.application.Visible = True
AppActivate = acad.application.Caption
print(AppActivate)
doc.Layers.Add("Pview")
layerObj = doc.Layers.Add("EGOUT")
doc.Layers.Add("EDIT")
layerObj = doc.Layers.Add("sewer")
layerObj.Color = 1
layerObj = doc.Layers.Add("area")
layerObj.Color = 6
layerObj = doc.Layers.Add("area-pline")
lyerObj = doc.Layers.Add("Den-pline")
layerObj.Color = 5
layerObj = doc.Layers.Add("area-density")
layerObj.Color = 3
layerObj = doc.Layers.Add("density")
layerObj = doc.Layers.Add("Latral")
layerObj.Color = 5
layerObj = doc.Layers.Add("SHEET-index")
layerObj = doc.Layers.Add("Grid")
layerObj =doc.Layers.Add("POP-TXT")
layerObj.Color = 4
layerObj = doc.Layers.Add("Elevation")
layerObj.Color = 7
layerObj =doc.Layers.Add("GELV")
layerObj.Color = 2
layerObj =doc.Layers.Add("Pview")
doc.ActiveLayer =doc.Layers("sewer")
print('Current Layer=' , doc.ActiveLayer.Name)
delss('ss1',doc)
ssget1 = doc.SelectionSets.Add("SS1")
SELECT_ALL = int(5)
valor=vtpt(0,0,0) #Necesario para parte del filtro
FilterType=vtint((0,8))
FilterData=vtvariant(('Line','Sewer'))
#selecionar de acuerdo al criterio de filtro
ssget1.Select(SELECT_ALL,valor,valor,FilterType,FilterData)
x1=0
y1=0
x2=0
y2=0
#Contar entidades
icount = ssget1.Count
if icount>0:
x2=ssget1[0].startpoint[0]
y2=ssget1[0].startpoint[1]
x1=x2
y1=y2
for elem1 in ssget1:
point2 = elem1.startpoint
if point2[0] > x1:
x1 = point2[0]
if point2[1] > y1:
y1 = point2[1]
#print ('x1=',x1)
if point2[0] < x2:
x2 = point2[0]
if point2[1] < y2:
y2 = point2[1]
point2 = elem1.endpoint
if point2[1] > y1:
y1 = point2[1]
if point2[0] > x1:
x1 = point2[0]
if point2[0] < x2:
x2 = point2[0]
if point2[1] < y2 :
y2 = point2[1]
#print ('base',(minbasex),minbasey)
acad.ZoomWindow (vtpt(x2,y2,0),vtpt(x1,y1,0))
acad.ZoomScaled (0.9, 1)
print(ssget1.Count ,'line')
delss('ss1',doc)
ssget1 = doc.SelectionSets.Add("SS1")
pt1=vtpt(0,0,0) #Necesario para parte del filtro
FilterType=vtint((0,8,0))
FilterData=vtvariant(('Circle','Egout'))
#selecionar de acuerdo al criterio de filtro
ssget1.Select(SELECT_ALL,pt1,pt1,FilterType,FilterData)
FilterData=vtvariant(('Text','Egout'))
ssget1.Select(SELECT_ALL,pt1,pt1,FilterType,FilterData)
#Contar entidades
icount = ssget1.Count
print(icount)
if icount == 0 :
#minbasex=0
minbasey=0
print(x2,y2)
txtobj = model.AddText( 'EGOUT' , vtpt(x1 + 100 , y1 + 100 ,0 ), 100 )
txtobj.layer ='Egout'
txtobj.Alignment = 4
txtobj.TextAlignmentPoint = vtpt(x1 + 100 ,y1 + 100 ,0 )
for i in range( 20 , 40 ,5):
cirobj = model.AddCircle(vtpt(x1 + 100 , y1 + 100,0 ), i//2 )
cirobj.layer = "EGOUT"
diaxdata(i , 0.004 , cirobj)
for i in range(50, 110 , 10):
cirobj = model.AddCircle(vtpt(x1 + 100,y1 + 100,0), i//2 )
cirobj.layer = "EGOUT"
diaxdata(i, 0.001,cirobj)
dataType = (1001, 1040, 1040, 1040, 1040, 1040, 1040, 1040, 1040, 1040, 1040, 1000, 1040) # Define Xdata
data = ("Criteria",0 , 0 ,100, 100 , 0 , 0 , 0 , 0 , 1 , 0, "N", 5)
dataType = vtint(dataType) # Converse dataType format
data = vtvariant(data)
txtobj.SetXData(dataType, data)
dataType = (1001, 1040, 1040, 1040, 1040, 1040, 1040, 1040, 1040, 1040, 1040, 1040, 1040) # Define Xdata
data = ( "Runoff",0 , 0 , 0, 0 , 0 , 180 , 0 , 0 , 1 , .5, 4, 1)
dataType = vtint(dataType) # Converse dataType format
data = vtvariant(data)
txtobj.SetXData(dataType, data)
dataType = (1001, 1040, 1040, 1040, 1040, 1040, 1040, 1040, 1040, 1040, 1040, 1040) # Define Xdata
data = ( "Infiltration",0 , 0 , 0, 0 , 0 , 0, 0 , 0, 0 , 0 , 0)
dataType = vtint(dataType) # Converse dataType format
data = vtvariant(data)
txtobj.SetXData(dataType, data)
dataType = (1001, 1040, 1040, 1040, 1040, 1040, 1040,1040, 1040, 1040, 1040) # Define Xdata
data = ( "Population",0 , 0 , 0, 0 , 0 , 0, 0, 0 , 0 , 0)
dataType = vtint(dataType) # Converse dataType format
data = vtvariant(data)
txtobj.SetXData(dataType, data)
dataType = (1001, 1000, 1000, 1000, 1000, 1000, 1000, 1000,1040, 1040, 1040, 1040) # Define Xdata
data = ( "Title", ' 1' , '2 ' , '3 ', '4 ' , ' 5' , ' 6' , '7', 0 , 0 , 0 , 0)
dataType = vtint(dataType) # Converse dataType format
data = vtvariant(data)
txtobj.SetXData(dataType, data)
dataType = (1001, 1040, 1040, 1040, 1040, 1040, 1040, 1040) # Define Xdata
data = ( "Sheetindex",0 , 0 , 0, 0 , 0 , 0, 0)
dataType = vtint(dataType) # Converse dataType format
data = vtvariant(data)
txtobj.SetXData(dataType, data)
else:
for el1 in ssget1:
if el1.entityname=="AcDbText":
print(el1.entityname)
el1.TextAlignmentPoint = vtpt(x1 + 100 ,y1 + 100 ,0 )
if el1.entityname=="AcDbCircle":
el1.center=vtpt(x1+100,y1+100,0)
acad.ZoomExtents
print ('Acad load')