Hi
I tried DgnFile.CreateNewModel, It seems as if that the seed model does not work.
Can anyone know what else may work?
Thanks.
Last Chance said: I tried DgnFile.CreateNewModel, It seems as if that the seed model does not work
We're developers, not mind readers! Show your code.
Regards, Jon Summers LA Solutions
Hi Jon,
Thanks for you reply.
I tried two ways, but none works.
First:
DrawComPropData drawComPropData = DrawCompPropHolder.Instance.GetDrawComPropData(); Bentley.DgnPlatformNET.IDisposableEnumerable<Bentley.Internal.MstnPlatformNET.DrawingSeedDescriptor> drawingSeedDescriptorEnum = Bentley.Internal.MstnPlatformNET.DrawingSeedDescriptorList.GetFromDgnLibs("", "", Bentley.Internal.MstnPlatformNET.DrawingSeedDim.DRAWINGSEEDDIM_All); foreach (Bentley.Internal.MstnPlatformNET.DrawingSeedDescriptor drawingSeedDescriptor in drawingSeedDescriptorEnum) { if (drawComPropData.ModelName == drawingSeedDescriptor.ViewName) { Bentley.DgnPlatformNET.DgnModel seedModel = null; Bentley.DgnPlatformNET.ModelId modelId = drawingSeedDescriptor.DrawingSeedFile.FindModelIdByName(drawComPropData.ModelName); //seedModel = drawingSeedDescriptor.DrawingSeedFile.FindLoadedModelById(modelId); Bentley.DgnPlatformNET.StatusInt status = Bentley.DgnPlatformNET.StatusInt.Error; seedModel = drawingSeedDescriptor.DrawingSeedFile.LoadRootModelById(out status, modelId); if(status == Bentley.DgnPlatformNET.StatusInt.Error) { MessageBox.Show("LoadRootModelById Seed Failed"); return false; } Bentley.DgnPlatformNET.DgnModel dgnModel = Bentley.MstnPlatformNET.Session.Instance.GetActiveDgnFile().CreateNewModel(out modelStatus, "Extract_Model" + TimeString, DgnModelType.Sheet, false, seedModel); if (modelStatus != DgnModelStatus.Success) { return false; } } }
Second:
DgnModelStatus modelStatus = DgnModelStatus.Success; Bentley.DgnPlatformNET.DgnModel seedModel = null; seedModel = GetSeedModel(); Bentley.DgnPlatformNET.DgnModel dgnModel = Bentley.MstnPlatformNET.Session.Instance.GetActiveDgnFile().CreateNewModel(out modelStatus, "Extract_Model" + TimeString, DgnModelType.Sheet, false, seedModel); private Bentley.DgnPlatformNET.DgnModel GetSeedModel() { //Seed file, C:\Program Files\Bentley\Bentley Raceway and Cable Management CONNECT Edition\BRCM\Default\Dgnlib\DrawComp\en\DrawingSeed.dgnlib if(!System.IO.File.Exists(drawComPropData.SeedFileName)) { return null; } Bentley.DgnPlatformNET.DgnFileOwner fileOwner = Bentley.DgnPlatformNET.DgnFile.Create(Bentley.DgnPlatformNET.DgnDocument.CreateForLocalFile(drawComPropData.SeedFileName), Bentley.DgnPlatformNET.DgnFileOpenMode.ReadOnly); Bentley.DgnPlatformNET.StatusInt status; Bentley.DgnPlatformNET.DgnFile dgnFile = fileOwner.DgnFile; dgnFile.LoadDgnFile(out status); if (Bentley.DgnPlatformNET.StatusInt.Success != status) { MessageBox.Show("Open File failed..." + drawComPropData.SeedFileName); return null; } string[] modelNames = drawComPropData.ModelName.Split('|'); if(modelNames.Length < 2) { return null; } uint umodelId = 0; if(!uint.TryParse(modelNames[1], out umodelId)) { return null; } Bentley.DgnPlatformNET.ModelId modelId = umodelId; Bentley.DgnPlatformNET.DgnModel dgnModel = dgnFile.LoadRootModelById(out status, modelId); if (Bentley.DgnPlatformNET.StatusInt.Success != status || dgnModel == null) { return null; } return dgnModel; }
And when the code works, I should get a new sheet model like create sheet model from seed
Last Chance said:I tried two ways
Hmm. Quite complex code. You're using undocumented internal code, about which anybody outside Bentley Systems (i.e. me) cannot comment.
Does this work (from SDK example ParametricModellingExample)?
ParametricModellingExample
defModel = activeFile.CreateNewModel(out status, modelName, DgnModelType.Normal, true, null);
The null parameter for seed model reference means 'use the default model'. If that works, you can try to obtain a seed model reference another way.
null
Thanks for your reply.
These two way is difference way to get the seed model.
And I tried thes method with seed model null, but the result is not the one I need.
Let's take the seed file
C:\Program Files\Bentley\MicroStation CONNECT Edition\MicroStation\Default\Dgnlib\DrawComp\en\DrawingSeed.dgnlib
for example
If I create sheet model from seed and the model choose metric sheet only, when click the OK button from the dialog of create model, I will see the border of the seed sheet, but when I do this with code, the border does not show.
Last Chance said: I tried thes method with seed model null, but the result is not the one I need
Yes, I appreciate that. My suggestion was to help you ensure that the method CreateNewModel produces a useful result.
CreateNewModel
If that worked, then you can go about obtaining a seed file model another way.
Last Chance said:I will see the border of the seed sheet, but when I do this with code, the border does not show.
Perhaps you need to execute whatever code is required to Show Sheet Boundary? You might like to investigate the SheetDefinition you can get using ModelInfo.GetSheetDefinition, then look at its properties, particularly SheetDefinition.BorderAttachmentId.
SheetDefinition
ModelInfo.GetSheetDefinition
SheetDefinition.BorderAttachmentId
It may be helpful, as Jan likes to remind us, to look in the C++ MicroStationAPI document. Sometimes the help available there provides some clues, that are not mentioned in the .NET documentation, into class behaviour.
Thanks Jon, DgnModel.SetModelInfo(DgnModel.GetModelInfo()) works fine for me.
Thanks anyway.