[MSCE update 13 C++/C#] How can I create sheet from seed

Hi

    I tried DgnFile.CreateNewModel, It seems as if that the seed model does not work.

    Can anyone know what else may work?

Thanks.

Parents
  • 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

    Thanks.

  • 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)?

    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.

     
    Regards, Jon Summers
    LA Solutions

Reply
  • 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)?

    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.

     
    Regards, Jon Summers
    LA Solutions

Children
  • Hi Jon,

    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.

  • 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.

    If that worked, then you can go about obtaining a seed file model another way.

    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.

    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.

     
    Regards, Jon Summers
    LA Solutions

  • Thanks Jon, DgnModel.SetModelInfo(DgnModel.GetModelInfo()) works fine for me.

    Thanks anyway.

  • 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
    1. Create a sheet model from seed using your code. 
    2. Open the Model Properties dialog. 
    3. Is the option Show Sheet Boundary enabled for your new sheet model? 
      • Is the boundary visible/invisible when that option is checked/cleared?

    What you're testing is whether your new sheet model has a boundary (0 != SheetDefinition.BorderAttachmentId) but is invisible, or if you need to do something else when defining your sheet seed model.

     
    Regards, Jon Summers
    LA Solutions

  • but when I do this with code, the border does not show.

    I tried CreateNewModel method and it seems working partially:

    • Everything is created correctly in terms of the sheet parameters, that are taken from the seed file.
    • The problem is that references are lost, so when I use the same seed manually, some content is displayed, whereas using the code, empty seed (borders only, but not references) is created.

    To investigate it further probably requires to try the same in C++.

    With regards,

      Jan