[CONNECT C# .NET] How to associate an ItemType to a parametric model and then create a variation associated with the ItemType?

Hello,

I am using OpenBuildings CONNECT Update 5, I think the version is 10.00.14.18. 10.05.00.49 (Corrected).  I am using the MicroStation Update 12 SDK.

I am trying to create a variation (parameter set) in a model but I want to associate the variables with an Item Type as shown in the attached dialog box rather than using local variables.

From what I can piece together from the SDK documentation and the parametric modelling examples provided in the SDK, the general steps are:

  1. Get a reference to the parameter definitions for the model
  2. Create an instance of the ItemType
  3. Call SetDomainParameters to associate the item type instance to the parameter definitions
  4. Get the DefinitionModelHandler for the model
  5. Create a parameter set using the DefinitionModelHandler
  6. Get the property values as IDgnECInstance
  7. Get each parameter definition and set its value

So I tried this code:

EditParameterDefinitions defs = EditParameterDefinitions.GetForModel(dgnModel);
ItemTypeLibrary itemTypeLibrary = ItemTypeLibrary.FindByName(LIB_NAME, dgnModel.GetDgnFile());
ItemType itemType = itemTypeLibrary.GetItemTypeByName(ITEMTYPE_NAME);
Bentley.ECObjects.Instance.IECInstance ecProperties = itemType.CreateTemplateInstance();
defs.SetDomainParameters(ecProperties);
// **** stuck here ****
// --> always returns ParameterStatus.InvalidParameterValues

// in a separate method after the domain class has been attached to the model
var handler = DgnComponentDefinitionHandler.GetForModel(dgnModel).DefinitionModelHandler;
EditParameterDefinitions defs = EditParameterDefinitions.GetForModel(dgnModel);
ParameterSet paramSet = handler.CreateParameterSet("variationName", null, null);
IDgnECInstance propertyValues = paramSet.Properties as IDgnECInstance;
// for each relevant parameter value (e.g. "SectionDepth")
ParameterDefinition paramDef = defs.FindByLabel(parameterName);
if (paramDef != null)
{
    IECPropertyValue propertyValue = propertyValues.FindPropertyValue(paramDef.AccessString, false, false, false, true);
    propertyValue.NativeValue = itemValue;  // 
}

When I run the debugger and test the variables in the immediate window, I obtain the following results:

defs
{Bentley.DgnPlatformNET.EditParameterDefinitions}
    DependencyRoot: {Bentley.DgnPlatformNET.Elements.ExtendedNonGraphicsElement}
    DomainClass: null
    HostModel: {Bentley.DgnPlatformNET.DgnModel}
    LocalParameterCount: 0
    Properties: {{DgnActiveParameters(:ECDA00000001:1595170100)}}

itemType
{Bentley.DgnPlatformNET.ItemType}
    ECClass: ECClass: "Structure__x0020__Attachment", Schema="DgnCustomItemTypes_Railway__x0020__Overhead__x0020__Wiring.01.00", IsDomainClass=true, IsCustomAttribute=false, IsStruct=false, BaseClasses[0]={System.NullReferenceException: Object reference not set to an instance of an object.
   at <>x.<>m0(ECClass <>4__this)}
    Guid: 2
    Id: 2
    InternalName: "Structure__x0020__Attachment"
    IsCustomType: false
    IsIdentifyingItem: false
    LabelProperty: null
    Library: {Bentley.DgnPlatformNET.ItemTypeLibrary}
    Name: "Structure Attachment"
    PropertyCount: 6
    Results View: Expanding the Results View will enumerate the IEnumerable

itemType.ToArray()
{Bentley.DgnPlatformNET.CustomProperty[6]}
    [0]: {Bentley.DgnPlatformNET.CustomProperty}
    [1]: {Bentley.DgnPlatformNET.CustomProperty}
    [2]: {Bentley.DgnPlatformNET.CustomProperty}
    [3]: {Bentley.DgnPlatformNET.CustomProperty}
    [4]: {Bentley.DgnPlatformNET.CustomProperty}
    [5]: {Bentley.DgnPlatformNET.CustomProperty}

itemType.ToArray()[2]
{Bentley.DgnPlatformNET.CustomProperty}
    Container: {Bentley.DgnPlatformNET.ItemType}
    CustomType: null
    DefaultValue: 0
    DefaultValueExpression: "0.0"
    Guid: 3145730
    Id: 3145728
    InternalName: "SectionDepth"
    IsArray: false
    Library: {Bentley.DgnPlatformNET.ItemTypeLibrary}
    Name: "SectionDepth"
    PickListName: null
    Priority: 2147418107
    SupportsCustomType: true
    SupportsUnits: true
    Type: Double
    TypeId: 2
    Units: {Bentley.DgnPlatformNET.DgnECUnit}

ecProperties
{{Structure__x0020__Attachment()}}
    ClassDefinition: ECClass: "Structure__x0020__Attachment", Schema="DgnCustomItemTypes_Railway__x0020__Overhead__x0020__Wiring.01.00", IsDomainClass=true, IsCustomAttribute=false, IsStruct=false, BaseClasses[0]={System.NullReferenceException: Object reference not set to an instance of an object.
   at <>x.<>m0(ECClass <>4__this)}
    ClassLayoutChecksum: 1243618337
    ContainsValues: true
    ECDValueContainer: {Bentley.ECObjects.Instance.ECDMemoryBuffer}
    Enabler: null
    ExtendedData: {Bentley.Collections.EmptyReadOnlyDictionary<object>}
    ExtendedDataValueSetter: {Bentley.Collections.OptimizedDictionary<object>}
    Instance: {{Structure__x0020__Attachment()}}
    InstanceId: ""
    IsHiddenInstance: false
    IsPartiallyLoaded: false
    IsReadOnly: false
    MemoryBuffer: {Bentley.ECObjects.Instance.ECDMemoryBuffer}
    NumBitsPerProperty: 2
    PerPropertyFlags: {Bentley.ECObjects.Instance.PerPropertyFlagsHolder}
    PerPropertyFlagsCount: 1
    ReferenceObject: null
    UsageBitmask: 0
    _ECArrayCountChanged: null
    _ECPropertyValueChanged: null
    _ECReferenceObjectChanged: null
    m_instanceId: ""
    Results View: Expanding the Results View will enumerate the IEnumerable

ecProperties.ToArray()
{Bentley.ECObjects.Instance.IECPropertyValue[6]}
    [0]: {Bentley.ECObjects.Instance.ECDCalculatedDoubleValue}
    [1]: {Bentley.ECObjects.Instance.ECDCalculatedIntegerValue}
    [2]: {Bentley.ECObjects.Instance.ECDCalculatedDoubleValue}
    [3]: {Bentley.ECObjects.Instance.ECDCalculatedStringValue}
    [4]: {Bentley.ECObjects.Instance.ECDCalculatedStringValue}
    [5]: {Bentley.ECObjects.Instance.ECDCalculatedStringValue}

ecProperties.ToArray()[2]
{Bentley.ECObjects.Instance.ECDCalculatedDoubleValue}
    AccessString: "SectionWidth"
    ArrayIndex: -1
    BaseECDInstance: {{Structure__x0020__Attachment()}}
    ContainedValues: null
    Container: {{Structure__x0020__Attachment()}}
    DoubleValue: 0
    ECDValueContainer: {Bentley.ECObjects.Instance.ECDMemoryBuffer}
    Evaluator: {Bentley.ECObjects.Schema.CalculatedECPropertyEvaluator}
    GeometryValue: null
    Instance: {{Structure__x0020__Attachment()}}
    IntValue: 0
    InternalValue: 0
    IsAlwaysNull: false
    IsArray: false
    IsNull: false
    IsPrimitive: true
    IsReadOnly: false
    IsStruct: false
    Layout: {SectionWidth double offset=16 nullflagsOffset=0, nullflagsBitmask=00000004}
    LongValue: 0
    NativeAccessString: "SectionWidth"
    NativeValue: 0
    ParentPropertyValue: null
    Property: ECProperty: "SectionWidth", Type="double", IsReadOnly=false
    State: Calculated
    StringValue: "0"
    Type: {Bentley.ECObjects.Schema.ECDoubleType}
    XmlStringValue: "0"

As I am not very familiar with the ECObjects namespace and parametric modelling objects, I am not sure if I have called the correct method or there is another step missing.

Can someone advise:

  1. How I can attach the item type to the parameter set and then
  2. (Pre-empting my next question) how I can create a variation and set the item type parameter values for the new variation?

Any help would be greatly appreciated.

Regards,

Trevor

Parents Reply Children
No Data