ToolPalette Show Active Layer

ToolPalette Show Active Layer

SENL1362
Advisor Advisor
1,082 Views
7 Replies
Message 1 of 8

ToolPalette Show Active Layer

SENL1362
Advisor
Advisor

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.

 

Screenshot_1.png

 

 

 

 

 

        [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;
        }
0 Likes
Accepted solutions (1)
1,083 Views
7 Replies
Replies (7)
Message 2 of 8

Balaji_Ram
Alumni
Alumni

Hi,

 

I do not see this problem in AutoCAD 2016. In which version are you trying this ?

 

In the tool properties of an MText if i set the layer as "MText", the created MText was assigned to it already when the command was active.

To test if this is the case, i had modified the layer color and the MText was displayed in that color.

 

Here is a recording :

http://autode.sk/1NpFqTW

 

Regards,

Balaji



Balaji
Developer Technical Services
Autodesk Developer Network

0 Likes
Message 3 of 8

SENL1362
Advisor
Advisor

 

Hello Balaji,

 

Thank you for you're time spend on helping to solve this issue.

The samples are from AutoCAD MAP 2012 and 2014.

So you might be right that this is solved in new versions of AutoCAD.

I'll have a look as soon as possible.

 

I was looking for somesort of a refresh command, but it's oke when this is solved in 2016.

 

Again, thanks for you're help.

 

0 Likes
Message 4 of 8

SENL1362
Advisor
Advisor

 

 

Just tested AutoCAD MAP 2016 and the same result as for 2012 and 2014.

At the end both the Pline and the MText are placed on the layer's defined by the ToolPalette however for the MTEXT command this is only visible for the user AFTER it is finished.

When using the Pline command it is immediately visible on what layer it will be placed right after the command is activated.

See the differences below.

 

Screenshot_1.png

0 Likes
Message 5 of 8

Balaji_Ram
Alumni
Alumni

yes, i am getting your point now.

 

After you select the extents for the MText, the layer name gets updated.

 

Are you expecting the layer name change just after the MText tool from the palette is clicked ?

 

I only have vanilla AutoCAD 2016 installed in my system.

Can you confirm the behavior in AutoCAD Map 2016 ?

 

Regards,

Balaji

 

 



Balaji
Developer Technical Services
Autodesk Developer Network

0 Likes
Message 6 of 8

SENL1362
Advisor
Advisor

 

After you select the extents for the MText, the layer name gets updated.

But this is after the MText is created. It needs an additional action from the user to confirm the proper placement.

 

Are you expecting the layer name change just after the MText tool from the palette is clicked ?

Yes that's what our customers like to see, click the command and then the Layer Dropdown box should show the name of the Temporary Current Layer defined in the ToolPalette.

 

Can you confirm the behavior in AutoCAD Map 2016 ?

The behavior for 2012, 2014 and 2016 is the same -- thus wrong form MTEXT compared to PLINE.

Also note that both the MTEXT and MLEADER commmand's are wrong.

 

 

As mentioned in my previous posts i can "repair" it wit the SHACTMTLY command but it will change the active layer permanently.

 

 

0 Likes
Message 7 of 8

Balaji_Ram
Alumni
Alumni
Accepted solution

Hi,

 

I have logged this behavior in our internal database for our engineering team to analyze it.

 

I do not see a better workaround than what you already found.

 

You may need to reset the CLAYER after the MText command ends.

 

Using ArxDbg, a look at the series of reactor calls indicate a similar reset of the CLAYER after the MText command ends.

I have attached a screenshot of it and it should be possible to do that manually from your code too.

 

Regards,

Balaji

 

 

 



Balaji
Developer Technical Services
Autodesk Developer Network

0 Likes
Message 8 of 8

SENL1362
Advisor
Advisor

Balaji,

Ok, thanks for the tip.

 

 

0 Likes