- UID
- 658062
- 积分
- 2147
- 精华
- 贡献
-
- 威望
-
- 活跃度
-
- D豆
-
- 在线时间
- 小时
- 注册时间
- 2008-10-22
- 最后登录
- 1970-1-1
|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
本帖最后由 csharp 于 2014-5-7 06:18 编辑
http://www.acadnetwork.com/index.php?action=profile;area=showposts;u=131
- using (Transaction tr = db.TransactionManager.StartTransaction())
- {
- LayerTable lt = (LayerTable)db.LayerTableId.GetObject(OpenMode.ForRead);
- BlockTable bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead);
- BlockTableRecord ms = (BlockTableRecord)tr.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite);
- BlockTableRecord ps = (BlockTableRecord)tr.GetObject(bt[BlockTableRecord.PaperSpace], OpenMode.ForWrite);
- LayoutManager layMgr = LayoutManager.Current;
- Layout lay = (Layout)tr.GetObject(layMgr.GetLayoutId(layMgr.CurrentLayout), OpenMode.ForRead);
- //Collect LayerNames to exclude e.q. Layers OFF or Frozen
- List<string> frozenLayerNames= lt
- .Cast<ObjectId>()
- .Select(id => (LayerTableRecord)tr.GetObject(id, OpenMode.ForRead))
- .Where(ly => ly.IsOff)
- .Where(ly => ly.IsFrozen)
- .Select(ly => ly.Name)
- .ToList();
- //Same but now from within PaperSpace Viewports
- List<string> pvpFrozenLayerNames = lay
- .GetViewports().Cast<ObjectId>()
- .Select(id => (Viewport)tr.GetObject(id, OpenMode.ForRead))
- .SelectMany(pvp => pvp.GetFrozenLayers().Cast<ObjectId>())
- .Distinct().ToArray()
- .Select(id => (LayerTableRecord)tr.GetObject(id, OpenMode.ForRead))
- .Select(ly => ly.Name)
- .ToList();
- // List (visible) Layers named "...~..." and "...TXT..." and NOT "...NOTTOBEINCLUDED..."
- var visLayerNames = lt
- .Cast<ObjectId>()
- .Select(id => (LayerTableRecord)tr.GetObject(id, OpenMode.ForRead))
- .Where(ly => ly.Name.Contains('~'))
- .Where(ly => ly.Name.IndexOf("TXT", StringComparison.CurrentCultureIgnoreCase) > 0)
- .Where(ly => ly.Name.IndexOf("NOTTOBEINCLUDED", StringComparison.CurrentCultureIgnoreCase) < 0)
- .Where(ly => !ly.IsOff)
- .Where(ly => !ly.IsFrozen)
- .Where(ly => !pvpFrozenLayerNames.Contains(ly.Name))
- .Select(ly => ly.Name)
- .ToList();
- //select ModelSpace Text from specific layers
- var visTxt = ms.Cast<ObjectId>()
- .Where(id => id.ObjectClass.DxfName.ToUpper() == "TEXT" || id.ObjectClass.DxfName.ToUpper() == "MTEXT")
- .Select(id => (Entity)tr.GetObject(id, OpenMode.ForRead))
- .Where(ent => visLayerNames.Contains(ent.Layer))
- .ToList();
- //select Text from specific layers within specific Blocks
- var visTxtInSpecificBlks = ms.Cast<ObjectId>()
- .Where(id => id.ObjectClass.DxfName.ToUpper() == "INSERT")
- .Select(id => (BlockReference)tr.GetObject(id, OpenMode.ForRead))
- .Where(blkRef => visLayerNames.Contains(blkRef.Layer))
- .Where(blkRef => blkRef.Name.IndexOf("-xxx-", StringComparison.CurrentCultureIgnoreCase) > 0)
- .SelectMany(blkRef => ((BlockTableRecord)tr.GetObject(bt[blkRef.Name], OpenMode.ForRead)).Cast<ObjectId>())
- .Where(id => id.ObjectClass.DxfName.ToUpper() == "TEXT" || id.ObjectClass.DxfName.ToUpper() == "MTEXT")
- .Select(id => (Entity)tr.GetObject(id, OpenMode.ForRead))
- .Where(ent => visLayerNames.Contains(ent.Layer))
- .ToList();
- //Join Modelspace and Block Specific text
- visTxt.AddRange(visTxtInSpecificBlks);
- // build regular pattern to select certain string contents
- // use regex tester to help build the search pattern.
- string searchNrs = @"(^3\(|^)(...)(.*)";
- string returnNrs = "$2";
- var matchNr = new Regex(searchNrs , RegexOptions.IgnoreCase | RegexOptions.Compiled);
- //find visible text containing a complex patter
- var textNrs = visTxt
- .Select(ent => GetType().Name == "MTEXT" ? ((MText)ent).Text : ((DBText)ent).TextString)
- .Select(txt => matchNr.Replace(txt, searchNrs))
- .Distinct().ToArray()
- .ToList();
- //List in numeric order
- kabelNrs = kabelNrs
- .OrderBy(kabelNr => kabelNr.Length)
- .ThenBy(kabelNr => kabelNr)
- .ToList();
|
|