- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
For a long time I am looking for a simple solution fot this problem.
The temporary current layer is shown in the Layer dropdown box when placing simple tools from a ToolPalette, figure "1".
But this not the case for MText, which confuses novice users, figure "2".
The Mtext is placed on the activated layer but this must be checked after the placement of the MText.
The only solution found so far is using the function ShowActivateMTextLayer, figure "3".
This involves a GetPoint and SendStringToExecute whom i would rather avoid.
And it changes the active layer permanently, although this is acceptable.
I've tried al sorts of Refresh functions, like UpdateScreen, Regen, EnableGraphicsFlush, QueueForGraphicsFlush, FlushGraphics.
Any other suggestions?
Thanks for any help.
[CommandMethod("ShActMtLy")] public void ShowActivateMTextLayer() { Document doc = null; Database db = null; Editor ed = null; try { doc = AcadApp.DocumentManager.MdiActiveDocument; db = doc.Database; ed = doc.Editor; var curLayerName = GetLayerName(db.Clayer); // The call to ed.GetPoint update's the LayerSelector according to the Actual Current Layer PromptPointResult ppr = ed.GetPoint("\n First Corner: "); if (ppr.Status != PromptStatus.OK) return; // But this get's changed after the point is returned. // Send CLAYER command solved that issue. doc.SendStringToExecute("CLAYER " + curLayerName + "\n" + "Mtext " + ppr.Value.X + "," + ppr.Value.Y + " ", true, false, false); } catch (System.Exception ex) { if (ed != null) ed.WriteMessage("\n Error: " + ex.Message); else MessageBox.Show("Error: " + ex.Message, "ShowActivateMTextLayer", MessageBoxButtons.OK,MessageBoxIcon.Error); } }
public static ObjectId SetLayer(Database db, string layerName) { if (db==null) throw new System.Exception("GetLayerName: db IS NULL"); if (string.IsNullOrWhiteSpace(layerName)) throw new System.Exception("SetLayer: layerName IS NULL"); ObjectId layerId = ObjectId.Null; using (Transaction tr = db.TransactionManager.StartTransaction()) { LayerTable layerTable = (LayerTable)tr.GetObject(db.LayerTableId, OpenMode.ForRead); if (layerTable.Has(layerName)) layerId = layerTable[layerName]; else { LayerTableRecord newLayer = new LayerTableRecord(); newLayer.Name = layerName; layerTable.UpgradeOpen(); layerTable.Add(newLayer); tr.AddNewlyCreatedDBObject(newLayer, true); layerId = newLayer.ObjectId; } db.Clayer = layerId; tr.Commit(); } return layerId; }
Solved! Go to Solution.