Move cell to desired level

I've scoured these forums and google and cannot seem to figure this one out on my own.

With VBA I'm able to place a cell into my design file.  It does not come in on the desired level, however (not necessarily the active level) and I don't know how to change the cell's level.  Some things I've noticed are

1) if, when the cell was drawn,  the level that the cell was drawn on does not exist in my design file, that level is created in my design file

2) in my code, immediately after "ActiveModelReference.AddElement myNewCell", the command "MsgBox(myNewCell.Level)" throws a "variable not set" error so I tried "Set myNewCell.Level = someLevel" but I get the same error on this line of code

What am I missing here?

Thanks

  • Regarding placing cells on the active level, you may already know that, but if the cells you are placing are graphic/normal-type, then what it sounds like you are describing is expected behavior. Only point-type cells will be placed on the active level (with the active color, weight, etc.) There is a good explanation of this in Help > Contents, Getting Started > Cells > Creating and Editing Cells (expand the Cell Types subsection).

    If that is not what you are encountering, or if that is not the issue, then could you provide some more details (and possibly a scenario that might help better understand what it is that you are after)?

      

  • alternate_exterior:

    I don't know how to change a cell's level. I tried "Set myNewCell.Level = someLevel" but I get the same error on this line of code

    Normal Cells

    If you use the Analyze Element tool to examine a normal cell, you will see that the type 2 cell header level is greyed out. In fact, the cell header doesn't have any level, since it's not a graphic element but a container for one or more other elements, some of which may be graphic. Those component graphic elements will each have a level. It's necessary to iterate the components of a cell instance (i.e. after you have added it to a DGN model) and rewrite the cell if you want to change their levels.

    Point Cells

    Point cells behave differently. Useful methods are CellElement.IsPoint and CellElement.SetLevelRelative.

    Regards, Jon Summers
    LA Solutions

     
    Regards, Jon Summers
    LA Solutions

  • All it took was two lines of code after the cell had been added to the ActiveModelReference:

    ActiveModelReference.AddElement oNewCell

    oNewCell.Level =  ActiveDesignFile.Levels.Find(oLevel)

    oNewCell.Rewrite

    Most of what was driving me crazy about this was due to my own bad coding elsewhere in my VBA (ie - not setting the newly created level where I was trying to put the new cell).

    Jon, I understand what you mean by iterating the components of the cell and changing their levels in the iteration but in the end I found that to be unnecssary since all it took was to set the level of the entire cell and rewrite it as my code above shows.  Now that the cell is on the correct level, when I right click the cell and choose properties and look at each element of the cell, they are all on the correct level.

     Thank you both for your help!

  • CellElement.Level: Undocumented Method (almost)

    alternate_exterior:

    oNewCell.Level =  ActiveDesignFile.Levels.Find(oLevel)

    If that works as you describe, what you have found is an undocumented assignment procedure of CellElement. As documented, CellElement inherits the Level property from the base class Element. However, as a property, you should have to use the Set keyword:

    Set oNewCell.Level = ActiveDesignFile.Levels.Find(oLevel)

    The syntax you've used is that of a Property Let rather than Property Set:

    oNewCell.Level = ActiveDesignFile.Levels.Find(oLevel)

    That the level is applied to all components of the CellElement is  a method-like behaviour: it lets you assign a level by (internally) iterating the components of the cell. Of course, some people may not want that behaviour, and would prefer the cell's components to remain on discrete levels.

    It's as if the internal workings of CellElement.Level are like this:

    
    Public Property Let Level (ByVal oLevel As Level)
    ' pseudo-code
    For Each oComponent In oCell
        Set oComponent.oLevel = oLevel
    Next oComponent
    End Property
    
    

    Regards, Jon Summers
    LA Solutions

     
    Regards, Jon Summers
    LA Solutions

  • hi how r u hope u r doing well. Plz i need your help im trying to write a vba code to move  cell to desired level for example i have some cells in the level 1 and the same cells in the level 2. i want to move all this same cells in the level 3 for example. how can i do it? plz if u know send me the all program cause im very bad in vba. thank you so much.

  • millenium:

    If u know send me the all program cause im very bad in VBA …

    These Forums are here to provide help, not a free development service.

    If you are a newcomer to MicroStation VBA, why not take a training course? I believe that the Bentley Institute provides class-based and on-line training.

    Regards, Jon Summers
    LA Solutions

     
    Regards, Jon Summers
    LA Solutions