How to update SettingsCmdCreatePoints Layer programmatically?

How to update SettingsCmdCreatePoints Layer programmatically?

varshaauti27
Advocate Advocate
1,335 Views
7 Replies
Message 1 of 8

How to update SettingsCmdCreatePoints Layer programmatically?

varshaauti27
Advocate
Advocate

Hi, 

I am looking for the way to update SettingsCmdCreatePoints layer programmatically.

 

varshaauti27_1-1685005382233.png

 

Here is my sample code : 

 

 

 using (Transaction tr = acadDocument.Database.TransactionManager.StartTransaction())
                {
                    var pointSettings = Autodesk.Civil.ApplicationServices.CivilApplication.ActiveDocument.Settings.GetSettings<Autodesk.Civil.Settings.SettingsCmdCreatePoints>() as SettingsCmdCreatePoints;
                    pointSettings.Layer.Layer.Value = "New Layer";

                    tr.Commit();
                }

 

 

Code works fine no error so far,  but does not update "Create Points" layer

0 Likes
Accepted solutions (1)
1,336 Views
7 Replies
Replies (7)
Message 2 of 8

hippe013
Advisor
Advisor

Your code appears to work for me. (My apologies, I use VB instead of C#. One of these days I'll make the switch.)

 

 Dim ps As SettingsCmdCreatePoints = Autodesk.Civil.ApplicationServices.CivilApplication.ActiveDocument.Settings.GetSettings(Of Autodesk.Civil.Settings.SettingsCmdCreatePoints)

ps.Layer.Layer.Value = "MyCreatePointsLayer"

 

The code doesn't necessarily need to be wrapped in a transaction. The layer does need to exist or it will cause an exception. However you state that you are not encountering an error. Seems odd. 

0 Likes
Message 3 of 8

varshaauti27
Advocate
Advocate
Code does work but when I open Create Points settings I don't see updated layer. (FYI, I am using existing layer)
0 Likes
Message 4 of 8

hippe013
Advisor
Advisor

How is your code being executed? Dialog or command?  The following code example works provided that the layer MyCreatePointsLayer already exists.

 

VB.Net

<CommandMethod("SetCreatePointsLayer")>
Public Sub CmdSetCreatePointsLayer()
   Dim ps As SettingsCmdCreatePoints = Autodesk.Civil.ApplicationServices.CivilApplication.ActiveDocument.Settings.GetSettings(Of Autodesk.Civil.Settings.SettingsCmdCreatePoints)
   ps.Layer.Layer.Value = "MyCreatePointsLayer"
End Sub

 

C#.Net

[CommandMethod("SetCreatePointsLayer")]
public void CmdSetCreatePointsLayer()
{
    SettingsCmdCreatePoints ps = Autodesk.Civil.ApplicationServices.CivilApplication.ActiveDocument.Settings.GetSettings<Autodesk.Civil.Settings.SettingsCmdCreatePoints>;
    ps.Layer.Layer.Value = "MyCreatePointsLayer";
}
0 Likes
Message 5 of 8

varshaauti27
Advocate
Advocate
I am using CommandMethod that opens WinForm dialog. And I am trying to swap layer on Button click.
I did try to execute code through CommandMethod , it did work as expected. Looks like there is issue with executing above snippet with WinForm Dialog. Can you help me to resolve this issue?
0 Likes
Message 6 of 8

hippe013
Advisor
Advisor
Accepted solution

If you are executing from a dialog box you should use the "SendStringToExecute" method of the document. 

 

aDoc.SendStringToExecute("SetCreatePointsLayer ", false, false, false);

 

Edit: Added a space after the command name in the first argument.

 

 

I am assuming that your dialog is modal and not modeless. If you are using a modeless dialog then, inside the CreatePointsLayer command you will need to lock the document. 

Message 7 of 8

varshaauti27
Advocate
Advocate
Thanks for your help in solving this problem!
0 Likes
Message 8 of 8

norman.yuan
Mentor
Mentor
It is not because of WinForm Dialog (or WPF, for that matter) directly. It is because of how the dialog is displayed: MODAL, or MODELESS. If it is modeless dialog (it looks this is what you are using), the best practice is to call SendStringToExecute() to execute an existing CommandMethod, rather than locking current document with your code and then do something.

Norman Yuan

Drive CAD With Code

EESignature

0 Likes