개정판 0049f7f8
SEC Drawing Exception Prevention
- Change non-plot layer, Object purge, UCS, Move Title box and Delete outside
Change-Id: I8d61ad5edfe8c8c7176ea62e000af5bac41899ff
DTI_PID/OdReadExMgd/OdReadExMgd.cs | ||
---|---|---|
173 | 173 |
{ |
174 | 174 |
try |
175 | 175 |
{ |
176 |
Extents3d ext = pEnt.GeometricExtents; |
|
176 |
if (pEnt.Bounds != null) |
|
177 |
{ |
|
178 |
Extents3d ext = pEnt.GeometricExtents; |
|
177 | 179 |
|
178 |
XmlAttribute MinExtentsAttr = Program.xml.CreateAttribute("MinExtents"); |
|
179 |
MinExtentsAttr.Value = ext.MinPoint.ToString(); |
|
180 |
node.Attributes.SetNamedItem(MinExtentsAttr); |
|
180 |
XmlAttribute MinExtentsAttr = Program.xml.CreateAttribute("MinExtents");
|
|
181 |
MinExtentsAttr.Value = ext.MinPoint.ToString();
|
|
182 |
node.Attributes.SetNamedItem(MinExtentsAttr);
|
|
181 | 183 |
|
182 |
XmlAttribute MaxExtentsAttr = Program.xml.CreateAttribute("MaxExtents"); |
|
183 |
MaxExtentsAttr.Value = ext.MaxPoint.ToString(); |
|
184 |
node.Attributes.SetNamedItem(MaxExtentsAttr); |
|
184 |
XmlAttribute MaxExtentsAttr = Program.xml.CreateAttribute("MaxExtents"); |
|
185 |
MaxExtentsAttr.Value = ext.MaxPoint.ToString(); |
|
186 |
node.Attributes.SetNamedItem(MaxExtentsAttr); |
|
187 |
} |
|
185 | 188 |
} |
186 |
catch (System.Exception) |
|
189 |
catch (System.Exception ex)
|
|
187 | 190 |
{ |
188 | 191 |
} |
189 | 192 |
|
... | ... | |
488 | 491 |
|
489 | 492 |
DBObjectCollection objColl = new DBObjectCollection(); |
490 | 493 |
|
491 |
if (!pBlkRef.Name.ToUpper().StartsWith(BLOCK_GRAPHIC)) |
|
494 |
if (!pBlkRef.Name.ToUpper().StartsWith(BLOCK_GRAPHIC) && pBlkRef.Bounds != null)
|
|
492 | 495 |
{ |
493 | 496 |
pBlkRef.Explode(objColl); |
497 |
|
|
494 | 498 |
foreach (var obj in objColl) |
495 | 499 |
{ |
496 | 500 |
if (obj is DBText) |
... | ... | |
525 | 529 |
} |
526 | 530 |
catch (System.Exception) |
527 | 531 |
{ |
528 |
|
|
529 | 532 |
} |
530 | 533 |
} |
531 | 534 |
|
... | ... | |
3399 | 3402 |
/************************************************************************/ |
3400 | 3403 |
private void chageColorAllObjects(Database pDb) |
3401 | 3404 |
{ |
3405 |
List<string> exceptLayerList = new List<string>(); |
|
3406 |
using (LayerTable pTable = (LayerTable)pDb.LayerTableId.Open(OpenMode.ForRead)) |
|
3407 |
{ |
|
3408 |
foreach (ObjectId id in pTable) |
|
3409 |
{ |
|
3410 |
using (LayerTableRecord pRecord = (LayerTableRecord)id.Open(OpenMode.ForRead)) |
|
3411 |
{ |
|
3412 |
if (!pRecord.IsPlottable) |
|
3413 |
{ |
|
3414 |
exceptLayerList.Add(pRecord.Name); |
|
3415 |
} |
|
3416 |
} |
|
3417 |
} |
|
3418 |
} |
|
3419 |
|
|
3402 | 3420 |
using (Transaction tr = pDb.TransactionManager.StartTransaction()) |
3403 | 3421 |
{ |
3404 | 3422 |
BlockTable bt = (BlockTable)tr.GetObject(pDb.BlockTableId, OpenMode.ForRead); |
... | ... | |
3410 | 3428 |
if (ent == null) continue; |
3411 | 3429 |
|
3412 | 3430 |
ent.ColorIndex = 7; |
3431 |
if (exceptLayerList.Contains(ent.Layer)) |
|
3432 |
{ |
|
3433 |
ent.Layer = "0"; |
|
3434 |
} |
|
3413 | 3435 |
|
3414 | 3436 |
if (ent is BlockReference) |
3415 | 3437 |
{ |
3416 |
changeColorBlocks(tr, (BlockReference)ent); |
|
3438 |
changeColorBlocks(tr, (BlockReference)ent, exceptLayerList);
|
|
3417 | 3439 |
} |
3418 | 3440 |
} |
3419 | 3441 |
|
... | ... | |
3432 | 3454 |
if (ent == null) continue; |
3433 | 3455 |
|
3434 | 3456 |
ent.ColorIndex = 7; |
3457 |
if (exceptLayerList.Contains(ent.Layer)) |
|
3458 |
{ |
|
3459 |
ent.Layer = "0"; |
|
3460 |
} |
|
3435 | 3461 |
} |
3436 | 3462 |
} |
3437 | 3463 |
|
... | ... | |
3446 | 3472 |
Entity ent = tr.GetObject(entId, OpenMode.ForWrite, false, true) as Entity; |
3447 | 3473 |
if (ent == null) continue; |
3448 | 3474 |
ent.ColorIndex = 0;//ByBlock |
3475 |
if (exceptLayerList.Contains(ent.Layer)) |
|
3476 |
{ |
|
3477 |
ent.Layer = "0"; |
|
3478 |
} |
|
3449 | 3479 |
} |
3450 | 3480 |
} |
3451 | 3481 |
|
... | ... | |
3456 | 3486 |
/************************************************************************/ |
3457 | 3487 |
/* Change the color of blocks */ |
3458 | 3488 |
/************************************************************************/ |
3459 |
private void changeColorBlocks(Transaction tr, BlockReference blkRef) |
|
3489 |
private void changeColorBlocks(Transaction tr, BlockReference blkRef, List<string> exceptLayerList)
|
|
3460 | 3490 |
{ |
3461 | 3491 |
if (blkRef == null) return; |
3462 | 3492 |
|
... | ... | |
3466 | 3496 |
{ |
3467 | 3497 |
AttributeReference attRef = tr.GetObject(objectId, OpenMode.ForWrite, false, true) as AttributeReference; |
3468 | 3498 |
attRef.ColorIndex = 7; |
3499 |
if (exceptLayerList.Contains(attRef.Layer)) |
|
3500 |
{ |
|
3501 |
attRef.Layer = "0"; |
|
3502 |
} |
|
3469 | 3503 |
} |
3470 | 3504 |
} |
3471 | 3505 |
|
... | ... | |
3480 | 3514 |
ent.ColorIndex = 7; |
3481 | 3515 |
|
3482 | 3516 |
if (ent is BlockReference) |
3483 |
{ |
|
3484 |
|
|
3485 |
changeColorBlocks(tr, (BlockReference)ent); |
|
3517 |
{ |
|
3518 |
changeColorBlocks(tr, (BlockReference)ent, exceptLayerList); |
|
3486 | 3519 |
} |
3487 | 3520 |
} |
3488 | 3521 |
} |
... | ... | |
4089 | 4122 |
writeLine(indent, $"OID = {id.ToString()}, Error = {ex.Message}"); |
4090 | 4123 |
} |
4091 | 4124 |
} |
4125 |
public void prepareDump(Database pDb) |
|
4126 |
{ |
|
4127 |
// Purge Object(Layer X, Linetype X) |
|
4128 |
ObjectIdCollection oids = new ObjectIdCollection(); |
|
4129 |
using (Transaction tr = pDb.TransactionManager.StartOpenCloseTransaction()) |
|
4130 |
{ |
|
4131 |
for (long i = 0; i < pDb.Handseed.Value; i++) |
|
4132 |
{ |
|
4133 |
ObjectId id = ObjectId.Null; |
|
4134 |
pDb.TryGetObjectId(new Handle(i), out id); |
|
4135 |
if (id != ObjectId.Null && !id.IsErased) oids.Add(id); |
|
4136 |
} |
|
4137 |
|
|
4138 |
pDb.Purge(oids); |
|
4139 |
try |
|
4140 |
{ |
|
4141 |
foreach (ObjectId oid in oids) |
|
4142 |
{ |
|
4143 |
if (oid.IsErased) continue; |
|
4144 |
|
|
4145 |
DBObject obj = tr.GetObject(oid, OpenMode.ForWrite, false, true) as DBObject; |
|
4146 |
obj.Erase(true); |
|
4147 |
} |
|
4148 |
} |
|
4149 |
catch (System.Exception ex) |
|
4150 |
{ |
|
4151 |
} |
|
4152 |
|
|
4153 |
tr.Commit(); |
|
4154 |
} |
|
4155 |
|
|
4156 |
// SEC Title box Move & Erase |
|
4157 |
using (BlockTable pTable = (BlockTable)pDb.BlockTableId.Open(OpenMode.ForRead)) |
|
4158 |
{ |
|
4159 |
string blockName = "Title box"; |
|
4160 |
Extents3d extents = new Extents3d(); |
|
4161 |
bool isOK = false; |
|
4162 |
if (pTable.Has(blockName)) |
|
4163 |
{ |
|
4164 |
using (BlockTableRecord pBlock = (BlockTableRecord)pTable[BlockTableRecord.ModelSpace].Open(OpenMode.ForRead, false, true)) |
|
4165 |
{ |
|
4166 |
foreach (ObjectId entid in pBlock) |
|
4167 |
{ |
|
4168 |
using (Entity pEnt = (Entity)entid.Open(OpenMode.ForRead, false, true)) |
|
4169 |
{ |
|
4170 |
if (pEnt.GetRXClass().Name != "AcDbBlockReference") continue; |
|
4171 |
BlockReference blockRef = (BlockReference)pEnt; |
|
4172 |
if (blockRef.Name.Equals(blockName)) |
|
4173 |
{ |
|
4174 |
isOK = true; |
|
4175 |
extents = blockRef.GeometricExtents; |
|
4176 |
break; |
|
4177 |
} |
|
4178 |
} |
|
4179 |
} |
|
4180 |
} |
|
4181 |
} |
|
4182 |
|
|
4183 |
if (isOK) |
|
4184 |
{ |
|
4185 |
Vector3d vec = extents.MinPoint.GetVectorTo(Point3d.Origin); |
|
4186 |
extents.TransformBy(Matrix3d.Displacement(vec)); |
|
4187 |
using (BlockTableRecord pBlock = (BlockTableRecord)pTable[BlockTableRecord.ModelSpace].Open(OpenMode.ForRead, false, true)) |
|
4188 |
{ |
|
4189 |
foreach (ObjectId entid in pBlock) |
|
4190 |
{ |
|
4191 |
using (Entity entity = (Entity)entid.Open(OpenMode.ForWrite, false, true)) |
|
4192 |
{ |
|
4193 |
if (entity != null) |
|
4194 |
entity.TransformBy(Matrix3d.Displacement(vec)); |
|
4195 |
try |
|
4196 |
{ |
|
4197 |
if (entity.Bounds != null) |
|
4198 |
{ |
|
4199 |
Extents3d entExtents = entity.GeometricExtents; |
|
4200 |
if ((entExtents.MinPoint.X >= extents.MinPoint.X && entExtents.MinPoint.Y >= extents.MinPoint.Y |
|
4201 |
&& entExtents.MinPoint.X <= extents.MaxPoint.X && entExtents.MinPoint.Y <= extents.MaxPoint.Y) |
|
4202 |
|| (entExtents.MaxPoint.X >= extents.MinPoint.X && entExtents.MaxPoint.Y >= extents.MinPoint.Y |
|
4203 |
&& entExtents.MaxPoint.X <= extents.MaxPoint.X && entExtents.MaxPoint.Y <= extents.MaxPoint.Y)) |
|
4204 |
{ |
|
4205 |
} |
|
4206 |
else |
|
4207 |
{ |
|
4208 |
entity.Erase(); |
|
4209 |
} |
|
4210 |
} |
|
4211 |
} |
|
4212 |
catch (System.Exception ex) |
|
4213 |
{ |
|
4214 |
} |
|
4215 |
} |
|
4216 |
} |
|
4217 |
} |
|
4218 |
} |
|
4219 |
} |
|
4220 |
|
|
4221 |
// Viewport Ucs |
|
4222 |
using (ViewportTable pTable = (ViewportTable)pDb.ViewportTableId.Open(OpenMode.ForRead)) |
|
4223 |
{ |
|
4224 |
foreach (ObjectId id in pTable) |
|
4225 |
{ |
|
4226 |
using (ViewportTableRecord pRecord = (ViewportTableRecord)id.Open(OpenMode.ForRead)) |
|
4227 |
{ |
|
4228 |
if (pRecord.Name == "*Active") |
|
4229 |
{ |
|
4230 |
CoordinateSystem3d cs3d = pRecord.Ucs; |
|
4231 |
if (cs3d.Origin != Point3d.Origin || cs3d.Xaxis != new Vector3d(1, 0, 0) || cs3d.Yaxis != new Vector3d(0, 1, 0)) |
|
4232 |
{ |
|
4233 |
pRecord.UpgradeOpen(); |
|
4234 |
pRecord.SetUcsToWorld(); |
|
4235 |
} |
|
4236 |
if (pRecord.ViewTwist != 0) |
|
4237 |
{ |
|
4238 |
pRecord.UpgradeOpen(); |
|
4239 |
pRecord.ViewTwist = 0; |
|
4240 |
} |
|
4241 |
if (pRecord.ViewDirection != new Vector3d(0, 0, 1)) |
|
4242 |
{ |
|
4243 |
pRecord.UpgradeOpen(); |
|
4244 |
pRecord.ViewDirection = new Vector3d(0, 0, 1); |
|
4245 |
} |
|
4246 |
} |
|
4247 |
} |
|
4248 |
} |
|
4249 |
} |
|
4250 |
pDb.UpdateExt(true); |
|
4251 |
} |
|
4092 | 4252 |
public void dumpHeader(Database pDb, int indent, XmlNode node) |
4093 | 4253 |
{ |
4094 | 4254 |
if (node != null) |
... | ... | |
4935 | 5095 |
/* Dump the database */ |
4936 | 5096 |
/****************************************************************/ |
4937 | 5097 |
DbDumper dumper = new DbDumper(); |
5098 |
dumper.prepareDump(pDb); |
|
4938 | 5099 |
dumper.ExplodeAndPurgeNestedBlocks(pDb); |
4939 | 5100 |
if (Program.getDrawing == 1) |
4940 | 5101 |
{ |
내보내기 Unified diff