Message 1 of 6
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I have been trying to figure out how to make sure a specific layer is thawed in the current viewport. My program makes sure a layer is thawed when in the model tab. But, I cannot seem to get it to work when in a viewport. I did figure out how to test if my layer is frozen in the viewport but cannot seem to get the layer thawed.
The goal is to take a given layer and create a sibling layer if the sibling layer does not exist. My code is below:
//*************************************************************************************************************************** /// <summary> /// Takes selected block layer and creates required sibling layer if it does /// not exist and makes it the current layer. /// </summary> /// <param name="blkLyrName"></param> /// <returns></returns> public string MakeSiblingLayer(string blkLyrName) { // Intialize the sibling layer namve variable. string sibLyrName; try { // Creates new layer name string for sibling layer. if (blkLyrName.EndsWith("_CONV")) { int cnt = blkLyrName.Length - 5; sibLyrName = blkLyrName.Remove(cnt, 5) + "_DIM_EL"; } else { sibLyrName = blkLyrName + "_DIM_EL"; } } catch (Autodesk.AutoCAD.Runtime.Exception a6) { System.Windows.Forms.MessageBox.Show("ERROR:\n" + a6.ToString()); return null; } catch { System.Windows.Forms.MessageBox.Show("ERROR:\n PROGRAM WILL EXIT!"); return null; } // Checks for the existence of the sibling layer and creates the new sibling layer if it does not exist. using (Transaction mklyrTrans = db.TransactionManager.StartTransaction()) { LayerTable sibLyrTable = mklyrTrans.GetObject(db.LayerTableId, OpenMode.ForWrite) as LayerTable; LayerTableRecord sibLTRec = mklyrTrans.GetObject(db.Clayer, OpenMode.ForWrite) as LayerTableRecord; try { // Thaws the existing sibling layer if it is frozen and it already exists. if (sibLyrTable.Has(sibLyrName) == true) { using (Transaction frznTrans = db.TransactionManager.StartTransaction()) { try { LayerTableRecord frznRec; frznRec = frznTrans.GetObject(sibLyrTable[sibLyrName], OpenMode.ForRead) as LayerTableRecord; if (db.TileMode) { if (frznRec.IsFrozen == true) { frznRec.UpgradeOpen(); frznRec.IsFrozen = false; frznTrans.Commit(); } else { frznTrans.Dispose(); } } else { Viewport vp = (Viewport)ed.ActiveViewportId.GetObject(OpenMode.ForRead); if (vp.IsLayerFrozenInViewport(frznRec.Id)) { frznRec.UpgradeOpen(); vp.; } } } catch (Autodesk.AutoCAD.Runtime.Exception fl) { System.Windows.Forms.MessageBox.Show("FROZEN LAYER ERROR:\n" + fl.ToString()); return null; } catch { System.Windows.Forms.MessageBox.Show("ERROR:\n PROGRAM WILL EXIT!"); return null; } } db.Clayer = sibLyrTable[sibLyrName]; }// end if sibLyrTable exists make it current layer // Creates the sibling layer if it does not exist already. else { sibLTRec = mklyrTrans.GetObject(sibLyrTable[blkLyrName], OpenMode.ForWrite).Clone() as LayerTableRecord; sibLTRec.Name = sibLyrName; sibLTRec.Color = Color.FromColorIndex(ColorMethod.ByAci, 7); sibLyrTable.Add(sibLTRec); mklyrTrans.AddNewlyCreatedDBObject(sibLTRec, true); db.Clayer = sibLyrTable[sibLyrName]; }// end clone layer if sibling layer does not exist and make new sibling layer the current layer } catch (Autodesk.AutoCAD.Runtime.Exception a7) { System.Windows.Forms.MessageBox.Show("ERROR:\n" + a7.ToString()); return null; } catch { System.Windows.Forms.MessageBox.Show("ERROR:\n PROGRAM WILL EXIT!"); return null; } // Commits the transaction to add the sibling layer. mklyrTrans.Commit(); }// end the mklyrTrans transaction // Returns the new sibling layer name to the calling program. return sibLyrName; } //***************************************************************************************************************************
Scott G. Sawdy
scott.sawdy@bluecoyotecad.com
scott.sawdy@bluecoyotecad.com
Solved! Go to Solution.