Skip to content

Object not set to a reference when using multiple classes #1

Description

@Sennevds

I'm trying to use your extension and saving my data works perfect but when I try to retreive the data back I get Object not set to a reference.
I have the following classes:

[Schema("74b729c1-60eb-4a67-bc75-70e0b76cfbcb",
    "ViewClassSchema")]
    [ImplementPropertyChanged]
    public class ViewClass: IRevitEntity
    {
        [Field]
        public string Name { get; set; }

        [Field]
        public bool IsActive { get; set; }

        [Field]
        public ElementId Id { get; set; }
    }

    [Schema("518F465C-8E3A-49AC-BA9E-0431036968C8",
    "SetSchema")]
    [ImplementPropertyChanged]
    public class Set : IRevitEntity
    {
        [Field]
        public string Name { get; set; }

        [Field]
        public ObservableCollection<SetCondition> Rules { get; set; }

        [Field]
        public SetCondition InverseRule { get; set; }

        [Field]
        public List<ViewClass> SelectedCategories { get; set; }

        [Field]
        public ParameterClass SelectedParameter { get; set; }
        
    }

    [Schema("12286B88-454A-46CA-AF5E-C90C58AA0B31",
    "SetConditionSchema")]
    [ImplementPropertyChanged]
    public class SetCondition : IRevitEntity
    {
        [Field]
        public bool IsActive { get; set; }

        [Field]
        public string Value { get; set; }

        [Field]
        public int Type { get; set; }

        private System.Windows.Media.Color filterColor;
        public System.Windows.Media.Color FilterColor
        {
            get
            {
                return filterColor;
            }
            set
            {
                filterColor = value;
                FilterColorA = filterColor.A;
                FilterColorR = filterColor.R;
                FilterColorG = filterColor.G;
                FilterColorB = filterColor.B;
            }
        }

        [Field]
        public int FilterColorR { get; set; }

        [Field]
        public int FilterColorG { get; set; }

        [Field]
        public int FilterColorB { get; set; }

        [Field]
        public int FilterColorA { get; set; }
    }

    [Schema("94e42b1e-ce3a-48c7-926a-8fb94869b0d3",
    "ParameterClassSchema")]
    [ImplementPropertyChanged]
    public class ParameterClass : IRevitEntity
    {
        [Field]
        public string Name { get; set; }

        [Field]
        public ElementId Id { get; set; }
    }

I've debugged the code and it fails when retreiving the data for the InverseRule.
In the following method: private object GetEntityFieldValue(Entity entity, Field field, Type fieldValueType) the code tries to retrieve the entityValue but it has no Schema and no Guid. The unittype of the field is UT_Undefined

Edit:
Found why it's crashing:
If an object is null it gets a valid entityvalue but the Schema and Guid are empty.
In public TRevitEntity Convert(Entity entity) where TRevitEntity : class, IRevitEntity
you check if the entityValue is empty but not if the schema is empty if you add that extra check it works

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions