[CONNECT Update 16 C#] Add new model programmaticaly starts with four views (but I need only one).

Hi

I'm trying to add new models to an existing dgn file. 

The new model must have only one view, but actually is created with 4 views.

The active Model actually has one only one view (but this not propagated to new models).

Here a snippets of my code:

var activeFile = Bentley.MstnPlatformNET.InteropServices.Utilities.ComApp.ActiveDesignFile;
var activeModel = Bentley.MstnPlatformNET.InteropServices.Utilities.ComApp.ActiveModelReference;
var model = activeFile.Models.Add(activeModel, "NAME", "DESCRIPTION", MsdModelType.Normal, true);

Same behaviour using new API:

var activeFileNet = Bentley.MstnPlatformNET.Session.Instance.GetActiveDgnFile();
var activeModelNet = Bentley.MstnPlatformNET.Session.Instance.GetActiveDgnModel();
var newModel = activeFileNet.CreateNewModel(out var err, "NET", DgnModelType.Normal, true, activeModelNet);

I'm already tried to fill the variables: MS_VIEWGROUPSEED and MS_VIEWGROUPSEEDNAME pointing to a seed file with a seed view group that contain only one view, but it doesn't work.

Thanks in advance

Patrizio Gasperi

Parents Reply Children
  • Hi Jan

    Plus, "save settings" (Ctrl+F) should be probably used to save the views configuration to the file.

    Persist settings to file seems not to work. When I activate the model 4 views are shown.

    the most straightforward solution is to explictly set on/off views in your code

    I can activate the model and iterate trought the views and set IsOpen to false to all views except view 1, but it is not what i need to achieve. I need to find only one view when I activate the new model.

    Regards

    Patrizio

  • Hi Patrizio,

    I do the same thing with VBA every time I open a DGN file, though its not the most elegant option but works perfectly well. I don't know the C# syntax but this is what I use and it sounds exactly like what Jan is suggesting (but he can confirm if he was thinking of another means):

    CadInputQueue.SendCommand "VIEW OFF 8"
    CadInputQueue.SendCommand "VIEW OFF 7"
    CadInputQueue.SendCommand "VIEW OFF 6"
    CadInputQueue.SendCommand "VIEW OFF 5"
    CadInputQueue.SendCommand "VIEW OFF 4"
    CadInputQueue.SendCommand "VIEW OFF 3"
    CadInputQueue.SendCommand "VIEW OFF 2"

  • Hi Patrizio

    I have investigated this issue and confirm this is a regression from V8i. 
    In detail the COM methods to create new models with methods .Add or .Copy should use same View settings like template has.

    I have filed bug # 870234 to address this issue.

    In CE the methods .Add and .Copy are providing different results. For new created models using the method .Copy only View 1 is on, all other views are off - so this would be a current workaround for your requirements.

    Best regards,

    Artur