-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMH-NumberingBeamsAndSheets.mcr
396 lines (317 loc) · 10 KB
/
MH-NumberingBeamsAndSheets.mcr
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
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
#Version 8
#BeginDescription
Last modified by: Leif Isacsson, Myresjohus
07.01.2010 - version 1.1
#End
#Type O
#NumBeamsReq 0
#NumPointsGrip 0
#DxaOut 0
#ImplInsert 1
#FileState 1
#MajorVersion 1
#MinorVersion 1
#KeyWords Numbering Spikreglar in Layout
#BeginContents
/*
*
* REVISION HISTORY
* -------------------------
*
* Created by: Leif Isacsson, Myresjohus
* date: 07.01.2010
* version 1.0: Pilot version
* version 1.1:
*
*/
Unit (1,"mm");//script uses mm
//Invalid position fro numbering
String arSBmCodeSteelBm[] = {
"SD1"
};
//Properties
//Select dimstyle
PropString sDimStyle(0, _DimStyles, T("|Dimension style|"));
//PropDouble dTextHeightNumbers(0, U(50), T("|Textheight numbering|"));
//PropDouble dTextHeightLabels(1, U(75), T("|Textheight labels|"));
PropInt nColorNumbers(0, -1, T("|Color numbers|"));
PropInt nColorLabels(1, 1, T("|Color numbers|"));
String arSYesNo[] = {T("|Yes|"), T("|No|")};
int arNYesNo[] = {_kYes, _kNo};
//Number
PropString sNumberBeams(1, arSYesNo, T("|Number beams|"));
int bNumberBeams = arNYesNo[arSYesNo.find(sNumberBeams, 0)];
PropString sNumberSheets(2, arSYesNo, T("|Number sheets|"));
int bNumberSheets = arNYesNo[arSYesNo.find(sNumberSheets, 0)];
PropString sNumberTsls(3, arSYesNo, T("|Number tsls|"));
int bNumberTsls = arNYesNo[arSYesNo.find(sNumberTsls, 0)];
//Label
PropString sLabelBeams(4, arSYesNo, T("|Label beams|"));
int bLabelBeams = arNYesNo[arSYesNo.find(sLabelBeams, 0)];
PropString sLabelSheets(5, arSYesNo, T("|Label sheets|"));
int bLabelSheets = arNYesNo[arSYesNo.find(sLabelSheets, 0)];
// filter beams with beamcode
PropString sFilterBC(6,"",T("Filter beams with beamcode"));
String sFBC = sFilterBC + ";";
String arSFBC[0];
int nIndexBC = 0;
int sIndexBC = 0;
while(sIndexBC < sFBC.length()-1){
String sTokenBC = sFBC.token(nIndexBC);
nIndexBC++;
if(sTokenBC.length()==0){
sIndexBC++;
continue;
}
sIndexBC = sFBC.find(sTokenBC,0);
arSFBC.append(sTokenBC);
}
// filter GenBeams with label
PropString sFilterLabel(7,"",T("Filter beams/sheets with (sub)label/material"));
String sFLabel = sFilterLabel + ";";
String arSFLabel[0];
int nIndexLabel = 0;
int sIndexLabel = 0;
while(sIndexLabel < sFLabel.length()-1){
String sTokenLabel = sFLabel.token(nIndexLabel);
nIndexLabel++;
if(sTokenLabel.length()==0){
sIndexLabel++;
continue;
}
sIndexLabel = sFilterLabel.find(sTokenLabel,0);
arSFLabel.append(sTokenLabel);
}
String arSRange[] = {T("|Selected element|"), T("|Floorgroup|")};
PropString sRange(8, arSRange, T("|Range|"));
int nRange = arSRange.find(sRange,0);
if( _bOnInsert ){
_Viewport.append(getViewport(T("Select the viewport that holds the element.")));
showDialog("_Default");
return;
}
if(_Viewport.length()==0){eraseInstance();return;}
Viewport vp = _Viewport[0];
// check if the viewport has hsb data
if (!vp.element().bIsValid()) return;
CoordSys ms2ps = vp.coordSys();
CoordSys ps2ms = ms2ps; ps2ms.invert();
double dVpScale = ms2ps.scale();
Display dpNumbers(nColorNumbers);
dpNumbers.dimStyle(sDimStyle);
//dpNumbers.textHeight(dTextHeightNumbers * dVpScale);
Display dpLabels(nColorLabels);
dpLabels.dimStyle(sDimStyle);
//dpLabels.textHeight(dTextHeightLabels * dVpScale);
Display dp(3);
Element arEl[0];
//Group info
Group grpElem = vp.element().elementGroup();
Group grpFloor(grpElem.namePart(0), grpElem.namePart(1),"");
if( nRange == 0 ){
arEl.append(vp.element());
}
else if( nRange == 1 ){
Group grpElem = vp.element().elementGroup();
Group grpFloor(grpElem.namePart(0), grpElem.namePart(1),"");
Entity arEntFloor[] = grpFloor.collectEntities(TRUE, Element(), _kModelSpace);
for( int i=0;i<arEntFloor.length();i++ ){
Element el = (Element)arEntFloor[i];
if( el.bIsValid() ){
arEl.append(el);
}
}
}
//Coordsys of wordl
CoordSys csWorld(_Pt0, _XW, _YW, _ZW);
Plane pnWorld(_Pt0, _ZW);
//Planeprofile withinvalid locations of floorgroup
PlaneProfile ppFloorGroup(csWorld);
//Beams of floorgroup
Entity arEntBmFloor[] = grpFloor.collectEntities(FALSE, Beam(), _kModelSpace);
Beam arBmFloor[0];
for( int i=0;i<arEntBmFloor.length();i++ ){
Beam bm = (Beam)arEntBmFloor[i];
if( nRange == 1 ){
if( (arSFBC.find(bm.name("beamcode").token(0)) == -1) &&
(arSFLabel.find(bm.label()) == -1) &&
(arSFLabel.find(bm.subLabel()) == -1) &&
(arSFLabel.find(bm.hsbId()) == -1) &&
(arSFLabel.find(bm.material()) == -1))
{
arBmFloor.append(bm);
}
}
if( arSBmCodeSteelBm.find(bm.beamCode().token(0)) != -1 ){
ppFloorGroup.unionWith(bm.realBody().shadowProfile(pnWorld));
}
}
//Go over elements
for( int e=0;e<arEl.length();e++ ){
Element el = arEl[e];
CoordSys csEl = el.coordSys();
Vector3d vxEl = csEl.vecX();
Vector3d vyEl = csEl.vecY();
Vector3d vzEl = csEl.vecZ();
GenBeam arGenBm[0];
Beam arBm[0];
if( e==0 )
arBm.append(arBmFloor);
Sheet arSh[0];
TslInst arTslInst[0];
//Filters
GenBeam arGBeamsTmp[] = el.genBeam(); // collect all
for(int i=0;i<arGBeamsTmp.length();i++){
if( arGBeamsTmp[i].bIsDummy() )continue;
if( (arSFBC.find(arGBeamsTmp[i].name("beamcode").token(0)) == -1) &&
(arSFLabel.find(arGBeamsTmp[i].label()) == -1) &&
(arSFLabel.find(arGBeamsTmp[i].subLabel()) == -1) &&
(arSFLabel.find(arGBeamsTmp[i].hsbId()) == -1) &&
(arSFLabel.find(arGBeamsTmp[i].material()) == -1))
{
arGenBm.append(arGBeamsTmp[i]);
}
}
Beam arBmsTmp[] = el.beam();
for(int i=0;i<arBmsTmp.length();i++){
if( arBmsTmp[i].bIsDummy() )continue;
if( (arSFBC.find(arBmsTmp[i].name("beamcode").token(0)) == -1) &&
(arSFLabel.find(arBmsTmp[i].label()) == -1) &&
(arSFLabel.find(arBmsTmp[i].subLabel()) == -1) &&
(arSFLabel.find(arBmsTmp[i].hsbId()) == -1) &&
(arSFLabel.find(arBmsTmp[i].material()) == -1))
{
arBm.append(arBmsTmp[i]);
}
}
Sheet arShTmp[] = el.sheet(); // collect all
Point3d arPtSh[0];
String arSLabelSh[0];
for(int i=0;i<arShTmp.length();i++){
Sheet sh = arShTmp[i];
if( (arSFLabel.find(sh.label()) == -1) &&
(arSFLabel.find(sh.subLabel()) == -1) &&
(arSFLabel.find(sh.material()) == -1))
{
int bDisplayInformation = TRUE;
for( int j=0;j<arPtSh.length();j++ ){
Point3d pt = arPtSh[j];
String sLabel = arSLabelSh[j];
if( (pt-sh.ptCen()).length() < U(50) && sLabel == sh.label() ){
bDisplayInformation = FALSE;
break;
}
}
if( bDisplayInformation ){
arPtSh.append(sh.ptCen());
arSLabelSh.append(sh.label());
arSh.append(sh);
}
}
}
arTslInst.append(el.tslInst());
//Planeprofile with all text locations
PlaneProfile ppAllTxt(csWorld);
ppAllTxt.unionWith(ppFloorGroup);
String arSTxt[0];
Point3d arPtTxt[0];
Display arDisplay[0];
Vector3d arVTransformation[0];
Vector3d arVxTxt[0];
Vector3d arVyTxt[0];
if( bNumberBeams || bLabelBeams ){
for( int i=0;i<arBm.length();i++ ){
Beam bm = arBm[i];
Vector3d vxBm = bm.vecX();
if( vxBm.dotProduct(_XW+_YW) < 0 )
vxBm= -vxBm;
Vector3d vyBm = vzEl.crossProduct(vxBm);
if( bNumberBeams ){
String sTxt = bm.posnum();
arSTxt.append(sTxt);
Point3d ptTxt = bm.ptCen() + 2 * bm.dD(vyBm) * vyBm; ptTxt.transformBy(ms2ps);
arPtTxt.append(ptTxt);
arDisplay.append(dpNumbers);
arVTransformation.append(vxBm);
arVxTxt.append(vxBm);
arVyTxt.append(vyBm);
}
if( bLabelBeams ){
String sTxt = bm.label();
arSTxt.append(sTxt);
Point3d ptTxt = bm.ptCen() - 2 * bm.dD(vyBm) * vyBm; ptTxt.transformBy(ms2ps);
arPtTxt.append(ptTxt);
arDisplay.append(dpLabels);
arVTransformation.append(vyBm);
arVxTxt.append(vxBm);
arVyTxt.append(vyBm);
}
}
}
if( bNumberSheets || bLabelSheets ){
for( int i=0;i<arSh.length();i++ ){
Sheet sh = arSh[i];
Vector3d vxSh = sh.vecX();
Vector3d vySh = vzEl.crossProduct(vxSh);
if( bNumberSheets ){
String sTxt = sh.posnum();
arSTxt.append(sTxt);
Point3d ptTxt = sh.ptCen() + vySh * U(100); ptTxt.transformBy(ms2ps);
arPtTxt.append(ptTxt);
arDisplay.append(dpNumbers);
arVTransformation.append(vxSh);
arVxTxt.append(_XW);
arVyTxt.append(_YW);
}
if( bLabelSheets ){
String sTxt = sh.label();
arSTxt.append(sTxt);
Point3d ptTxt = sh.ptCen() - vySh * U(100); ptTxt.transformBy(ms2ps);
arPtTxt.append(ptTxt);
arDisplay.append(dpLabels);
arVTransformation.append(vySh);
arVxTxt.append(_XW);
arVyTxt.append(_YW);
}
}
}
if( bNumberTsls ){
for( int i=0;i<arTslInst.length();i++ ){
TslInst tsl = arTslInst[i];
}
}
for( int i=0;i<arPtTxt.length();i++ ){
Point3d ptTxt = arPtTxt[i];
String sTxt = arSTxt[i];
Display dp = arDisplay[i];
Vector3d vTransformation = arVTransformation[i];
double dLTxt = dp.textLengthForStyle(sTxt, sDimStyle);
double dHTxt = dp.textHeightForStyle(sTxt, sDimStyle);
Vector3d vxTxt = arVxTxt[i];//_XW;
Vector3d vyTxt = arVyTxt[i];//_YW;
PLine plTxt(_ZW);
LineSeg lnSegTxt(ptTxt - vxTxt * .5 * dLTxt - vyTxt * .5 * dHTxt, ptTxt + vxTxt * .5 * dLTxt + vyTxt * .5 * dHTxt);
plTxt.createRectangle(lnSegTxt, vxTxt, vyTxt);
PlaneProfile ppThisTxt(plTxt);
ppThisTxt.shrink(-.25 * dHTxt);
// dpNumbers.draw(ppThisTxt);
PlaneProfile ppTmp = ppThisTxt;
ppTmp.intersectWith(ppAllTxt);
int nNrOfExecutionLoops =0;
while( ppTmp.area() > 0 && nNrOfExecutionLoops < 15){
LineSeg lnSeg = ppTmp.extentInDir(vTransformation);
double dTransformation = abs(vTransformation.dotProduct(lnSeg.ptEnd() - lnSeg.ptStart()));
ptTxt.transformBy(vTransformation * dTransformation);
ppThisTxt.transformBy(vTransformation * dTransformation);
ppTmp = ppThisTxt;
ppTmp.intersectWith(ppAllTxt);
nNrOfExecutionLoops++;
}
ppAllTxt.unionWith(ppThisTxt);
dp.draw(sTxt, ptTxt, vxTxt, vyTxt, 0, 0);
}
}
//dp.draw(ppAllTxt);
#End
#BeginThumbnail
#End