コード例 #1
0
 public static Dictionary <string, object> OpenDoc6(string FileName, swDocTemplateTypes_e Type, swOpenDocOptions_e Options, string Configuration)
 {
     return(OpenDoc6(SolidWorksInstance.SwApp, FileName, Type, Options, Configuration));
 }
コード例 #2
0
        private static Dictionary <string, object> OpenDoc6(ISldWorks SwApp, string FileName, swDocTemplateTypes_e Type, swOpenDocOptions_e Options, string Configuration)
        {
            int error = -1, warning = -1;
            Dictionary <string, object> result = new Dictionary <string, object>();

            var doc = SolidWorksInstance.SwApp.OpenDoc6(FileName, Type.SWToInt(), Options.SWToInt(), Configuration, ref error, ref warning);

            var error_E  = error.CastObj <swFileLoadError_e>();
            var waring_E = error.CastObj <swFileLoadWarning_e>();

            if (doc == null)
            {
                throw new Exception($"Opendoc Failed - Error: {error_E.ToString()} ,Waring:{waring_E.ToString()}");
            }

            result.Add(IModelDoc2Const, doc);
            result.Add(ErrorConst, error_E);
            result.Add(WaringConst, waring_E);

            return(result);
        }
コード例 #3
0
        public List <Tuple <string, string, string, object> > GetProperties(string FileName)
        {
            // check for solidworks instance
            if (swApp == null)
            {
                return(null);
            }
            if (!File.Exists(FileName))
            {
                return(null);
            }

            // config name
            // property name
            // property type
            // resolved value (boxed object)
            List <Tuple <string, string, string, object> > lstProps = new List <Tuple <string, string, string, object> >();

            // get doc type
            swDocumentTypes_e swDocType = GetTypeFromString(FileName);

            if (swDocType == swDocumentTypes_e.swDocNONE)
            {
                return(null);
            }

            // document open options
            // swOpenDocOptions_e is a bitmask enumerator
            // use bitwise "and" to select multiple options
            swOpenDocOptions_e swOpenDocOptions = swOpenDocOptions_e.swOpenDocOptions_Silent &
                                                  swOpenDocOptions_e.swOpenDocOptions_DontLoadHiddenComponents &
                                                  swOpenDocOptions_e.swOpenDocOptions_LoadLightweight &
                                                  swOpenDocOptions_e.swOpenDocOptions_Silent &
                                                  swOpenDocOptions_e.swOpenDocOptions_ReadOnly;

            // try to load the model file
            int       intWarnings = 0;
            int       intErrors   = 0;
            ModelDoc2 swModelDoc;

            try
            {
                swModelDoc = swApp.OpenDoc6(FileName, (int)swDocType, (int)swOpenDocOptions, "", ref intErrors, ref intWarnings);
            }
            catch
            {
                return(null);
            }
            ModelDocExtension swDocExt = swModelDoc.Extension;

            // get list of configs
            //string[] strConfgNames = (string[])swModelDoc.GetConfigurationNames();
            List <string> lstConfigNames = new List <string>();

            if (swDocType != swDocumentTypes_e.swDocDRAWING)
            {
                lstConfigNames = new List <string>((string[])swModelDoc.GetConfigurationNames());
            }
            lstConfigNames.Add("");
            foreach (string strConfigName in lstConfigNames)
            {
                CustomPropertyManager swCustPropMgr = swDocExt.get_CustomPropertyManager(strConfigName);

                object oPropNames  = null;
                object oPropTypes  = null;
                object oPropValues = null;
                //object oResolved = null;

                //swCustPropMgr.GetAll2(ref oPropNames, ref oPropTypes, ref oPropValues, ref oResolved);
                swCustPropMgr.GetAll(ref oPropNames, ref oPropTypes, ref oPropValues);

                if (oPropNames == null)
                {
                    continue;
                }

                // get list of properties for this config
                int intPropCount = ((string[])oPropNames).Length;
                for (int i = 0; i < intPropCount; i++)
                {
                    // property name
                    string strPropName = ((string[])oPropNames)[i]; // property name

                    // property type
                    string             strPropType   = "";
                    swCustomInfoType_e eCustInfoType = ((swCustomInfoType_e[])oPropTypes)[i]; // property type
                    switch (eCustInfoType)
                    {
                    case swCustomInfoType_e.swCustomInfoDate:
                        strPropType = "date";
                        break;

                    case swCustomInfoType_e.swCustomInfoDouble:
                        strPropType = "number";
                        break;

                    case swCustomInfoType_e.swCustomInfoNumber:
                        strPropType = "number";
                        break;

                    case swCustomInfoType_e.swCustomInfoText:
                        strPropType = "text";
                        break;

                    case swCustomInfoType_e.swCustomInfoUnknown:
                        strPropType = "";
                        break;

                    case swCustomInfoType_e.swCustomInfoYesOrNo:
                        strPropType = "yesno";
                        break;
                    }

                    // property value
                    //object oPropValue = ((object[])oResolved)[i]; // resolved value, with GetAll2()
                    object oPropValue = ((object[])oPropValues)[i]; // resolved value, with GetAll()
                    oPropValue.GetType();
                    if (oPropValue.GetType() == typeof(System.Double))
                    {
                        oPropValue = (Decimal)oPropValue;
                    }

                    // add to list
                    lstProps.Add(Tuple.Create <string, string, string, object>(strConfigName, strPropName, strPropType, oPropValue));
                }
            }

            swModelDoc = null;
            swApp.CloseDoc(FileName);
            return(lstProps);
        }