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
please follow the best practices, and instead of plenty of tags (not very useful in my opinion), specify used product and its exact version (preferably using standardized subject format).
Patrizio Gasperi said:The new model must have only one view, but actually is created with 4 views.
Can you clarify what do you want to achieve? Model has not views, it's MicroStation feature that it allows to open up to 8 views.
Do you want to create model and to open one view (e.g. View 1) after the model is created, or you want to interact somehow with View Groups tool?
Bentley Accredited Developer: iTwin Platform - AssociateLabyrinth Technology | dev.notes() | cad.point
Hi Jan, thanks for the hint. I have edited the post using your suggestions.
Exatcly, I would like to create a model with only View 1 open.
I don't need to interact with view groups (unless it's required to achieve the purpose).
Patrizio Gasperi said:Exatcly, I would like to create a model with only View 1 open.
In such case I think the most straightforward solution is to explictly set on/off views in your code, after the model is created. Plus, "save settings" (Ctrl+F) should be probably used to save the views configuration to the file.
Jan Šlegr said: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.
Jan Šlegr said: 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.
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"
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.