Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.
rjay75
in reply to: adam.nagy

This is the way I access the Type property for the com objects using reflection so I don't have to embed types or add more dependencies.

                Type objType = obj.GetType();
                ObjectTypeEnum ote;
                try
                {
                    ote = (ObjectTypeEnum)objType.InvokeMember("Type", BindingFlags.InvokeMethod, null, obj, null);

                }
                catch (Exception castExp)
                {

                    throw new InvalidCastException("Object is not an Inventor Type:/n" + castExp.Message);
                }

I also took this one step further and passed the ote variable to a giant switch statement to return the actual Inventor type. You can also have it only contain the types you're interested in.

        public Type GetInventorType(object obj)
        {
            Type rVal = null;
            if (obj != null)
            {
                Type objType = obj.GetType();
                ObjectTypeEnum ote;
                try
                {
                    ote = (ObjectTypeEnum)objType.InvokeMember("Type", BindingFlags.InvokeMethod, null, obj, null);

                }
                catch (Exception castExp)
                {

                    throw new InvalidCastException("Object is not an Inventor Type:/n" + castExp.Message);
                }
                switch (ote)
                {
                    case ObjectTypeEnum.kAngularGeneralDimensionObject:
                        rVal = typeof(AngularGeneralDimension);
                        break;
                    case ObjectTypeEnum.kApplicationAddInObject:
                        rVal = typeof(ApplicationAddIn);
                        break;
                    case ObjectTypeEnum.kApplicationAddInSiteObject:
                        rVal = typeof(ApplicationAddInSite);
                        break;
                    case ObjectTypeEnum.kApplicationAddInsObject:
                        rVal = typeof(ApplicationAddIns);
                        break;
                    case ObjectTypeEnum.kApplicationEventsObject:
                        rVal = typeof(ApplicationEvents);
                        break;
                    case ObjectTypeEnum.kApplicationObject:
                        rVal = typeof(Application);
                        break;
                    case ObjectTypeEnum.kDiameterGeneralDimensionObject:
                        rVal = typeof(DiameterGeneralDimension);
                        break;
                    default:
                        break;
                }
            }
                return rVal;
        }