C# - COM – Can not change Level.Name

I would like to change the name of a level, but it don't work.

I use the „Text.dgn“ Example for testing.

Here is a part of the code.

I use: bentley.interop.microstationdgn

using MicroStationDGN;

private MicroStationDGN.Application msApp;

private MicroStationDGN.DesignFile msDGN;

msApp = new MicroStationDGN.Application();

// Works

String DGNLevelName = "ClipShape";

MicroStationDGN.Level dgnLevel = msApp.ActiveDesignFile.Levels.Find(DGNLevelName);

// Works

MessageBox.Show(dgnLevel.ID.ToString());

MessageBox.Show(dgnLevel.Name.ToString());

MessageBox.Show(dgnLevel.Description.ToString());

// Works (Focus in Levenmanager switch to ClipShape)

dgnLevel.IsActive = true;

// Problem part

String newName = "Clip";

dgnLevel.Name = newName;

// Works (Levelmanager reloads)

msApp.ActiveDesignFile.Levels.Rewrite();

........................................

At this - dgnLevel.Name = newName;

i alway got a „Level-ID is invalid“.

Same is if i try - dgnLevel.Description = newName;

Debugger gives me a „Level-ID is invalid“.

I have tried some other tests, like:

msApp.ActiveDesignFile.AddNewLevel("Demo_1");

or

msApp.ActiveDesignFile.DeleteLevel("Demo_1");

All works fine.

Whats wrong with my code or the „ string Name { get; set; } “

Thank you

Harry

Parents
  • After adding a new Level you have to rewrite the level table (class/object: Levels)

    from the mvba help:

    Changing Level Display for an Attachment example

    Sub ToggleLevelDisplay(att As Attachment, strLevelPattern As String)
    Dim lvls As Levels
     Dim lvl As Level
     Set lvls = att.Levels
     For Each lvl In att.Levels
      If lvl.Name Like strLevelPattern Then
    lvl.IsDisplayed = Not lvl.IsDisplayed
    End If
     Next
    lvls.Rewrite
     RedrawAllViews
    End Sub

    Remarks from the vba help for AddNewLevel Method

    This method returns the newly-created Level object.

    Subsequently, you should call Levels.Rewrite to make the change permanent.

    Version

    08.00.00

    Ohhh i see, Yogan was already saying this!

    Regards

    Frank

    since 1985: GIS, CAD, Engineering (Civil)  Senior Consultant : [Autodesk Civil 3D , Esri ArcGIS, VertiGIS: in previous days : Bentley MS V4 - V8i, GeoGraphics, Bentley Map V8i, InRoads,  HHK Geograf, IBr DAVID] :  Dev: [C, C++, .NET, Java, SQL, FORTRAN, UML]
    [direct quote by: http://en.wikipedia.org/wiki/Helmut_Schmidt]: "Wer Kritik übel nimmt, hat etwas zu verbergen"
    Wer Grammatik- und/oder Rechtschreibfehler findet, der darf sie behalten :-)

  • @Frank

    Frank i read your entry in this forum about "rewrite()".

    If you look above, my code, you can see:

    msApp.ActiveDesignFile.Levels.Rewrite();

    As i wrote:

    // Works (Levelmanager reloads)

    msApp.ActiveDesignFile.Levels.Rewrite();

  • Unknown said:

    @Frank

    Frank i read your entry in this forum about "rewrite()".

    If you look above, my code, you can see:

    msApp.ActiveDesignFile.Levels.Rewrite();

    As i wrote:

    // Works (Levelmanager reloads)

    msApp.ActiveDesignFile.Levels.Rewrite();

    Sorry, for overlooking that in fact :-)

    Have fun, now as we are knowing the reason!

    Regards

    Frank

    since 1985: GIS, CAD, Engineering (Civil)  Senior Consultant : [Autodesk Civil 3D , Esri ArcGIS, VertiGIS: in previous days : Bentley MS V4 - V8i, GeoGraphics, Bentley Map V8i, InRoads,  HHK Geograf, IBr DAVID] :  Dev: [C, C++, .NET, Java, SQL, FORTRAN, UML]
    [direct quote by: http://en.wikipedia.org/wiki/Helmut_Schmidt]: "Wer Kritik übel nimmt, hat etwas zu verbergen"
    Wer Grammatik- und/oder Rechtschreibfehler findet, der darf sie behalten :-)

Reply
  • Unknown said:

    @Frank

    Frank i read your entry in this forum about "rewrite()".

    If you look above, my code, you can see:

    msApp.ActiveDesignFile.Levels.Rewrite();

    As i wrote:

    // Works (Levelmanager reloads)

    msApp.ActiveDesignFile.Levels.Rewrite();

    Sorry, for overlooking that in fact :-)

    Have fun, now as we are knowing the reason!

    Regards

    Frank

    since 1985: GIS, CAD, Engineering (Civil)  Senior Consultant : [Autodesk Civil 3D , Esri ArcGIS, VertiGIS: in previous days : Bentley MS V4 - V8i, GeoGraphics, Bentley Map V8i, InRoads,  HHK Geograf, IBr DAVID] :  Dev: [C, C++, .NET, Java, SQL, FORTRAN, UML]
    [direct quote by: http://en.wikipedia.org/wiki/Helmut_Schmidt]: "Wer Kritik übel nimmt, hat etwas zu verbergen"
    Wer Grammatik- und/oder Rechtschreibfehler findet, der darf sie behalten :-)

Children
No Data