Ejemplo n.º 1
0
        private static void ProcessConfiguration(SwDMDocument doc, string confName, StreamWriter csvFileWriter)
        {
            var conf = doc.ConfigurationManager.GetConfigurationByName(confName);

            var massPrps = (double[])conf.GetMassProperties(out SwDmMassPropError massPrpsErr);

            if (massPrpsErr != SwDmMassPropError.swDmMassPropErrorNone)
            {
                throw new Exception($"Failed to extract mass properties: {massPrpsErr}");
            }

            var cogX     = massPrps[0];
            var cogY     = massPrps[1];
            var cogZ     = massPrps[2];
            var volume   = massPrps[3];
            var surfArea = massPrps[4];
            var mass     = massPrps[5];
            var momXX    = massPrps[6];
            var momYY    = massPrps[7];
            var momZZ    = massPrps[8];
            var momXY    = massPrps[9];
            var momZX    = massPrps[10];
            var momYZ    = massPrps[11];

            csvFileWriter.WriteLine($"\"{doc.FullName}\",\"{confName}\",{cogX},{cogY},{cogZ},{volume},{surfArea},{mass},{momXX},{momYY},{momZZ},{momXY},{momZX},{momYZ}");
        }
Ejemplo n.º 2
0
 public SwDmUnknownDocument(ISwDmApplication dmApp, SwDMDocument doc, bool isCreated,
                            Action <ISwDmDocument> createHandler, Action <ISwDmDocument> closeHandler, bool?isReadOnly = null)
     : base(dmApp, doc, isCreated, createHandler, closeHandler, isReadOnly)
 {
     if (isCreated)
     {
         m_CreateHandler.Invoke((ISwDmDocument)GetSpecific());
     }
 }
Ejemplo n.º 3
0
 public SwDmUnknownDocument3D(ISwDmApplication dmApp, SwDMDocument doc, bool isCreated, Action <ISwDmDocument> createHandler, Action <ISwDmDocument> closeHandler, bool?isReadOnly = null)
     : base(dmApp, doc, isCreated, createHandler, closeHandler, isReadOnly)
 {
 }
Ejemplo n.º 4
0
        public List <Tuple <string, string, string, object> > GetProperties(string FileName)
        {
            SwDMDocument         swDoc    = default(SwDMDocument);
            SwDMConfigurationMgr swCfgMgr = default(SwDMConfigurationMgr);

            // 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
            SwDmDocumentType swDocType = GetTypeFromString(FileName);

            if (swDocType == SwDmDocumentType.swDmDocumentUnknown)
            {
                return(null);
            }

            // get the document
            SwDmDocumentOpenError nRetVal = 0;

            swDoc = (SwDMDocument)swDocMgr.GetDocument(FileName, swDocType, true, out nRetVal);
            if (SwDmDocumentOpenError.swDmDocumentOpenErrorNone != nRetVal)
            {
                DialogResult dr = MessageBox.Show("Failed to open solidworks file: " + FileName,
                                                  "Loading SW File",
                                                  MessageBoxButtons.OK,
                                                  MessageBoxIcon.Exclamation,
                                                  MessageBoxDefaultButton.Button1);
            }

            // get document custom properties (file level properties)
            string[] strDocPropNames = (string[])swDoc.GetCustomPropertyNames();
            if (strDocPropNames != null)
            {
                foreach (string strPropName in strDocPropNames)
                {
                    SwDmCustomInfoType nPropType  = 0;
                    object             oPropValue = swDoc.GetCustomProperty(strPropName, out nPropType);

                    // property type
                    string strPropType = "";
                    switch (nPropType)
                    {
                    case SwDmCustomInfoType.swDmCustomInfoDate:
                        strPropType = "date";
                        oPropValue  = Convert.ToDateTime(oPropValue);
                        break;

                    case SwDmCustomInfoType.swDmCustomInfoNumber:
                        strPropType = "number";
                        oPropValue  = Convert.ToDecimal(oPropValue);
                        break;

                    case SwDmCustomInfoType.swDmCustomInfoText:
                        strPropType = "text";
                        oPropValue  = Convert.ToString(oPropValue);
                        break;

                    case SwDmCustomInfoType.swDmCustomInfoYesOrNo:
                        strPropType = "yesno";
                        oPropValue  = oPropValue.Equals("Yes");
                        break;

                    case SwDmCustomInfoType.swDmCustomInfoUnknown:
                        strPropType = "";
                        break;
                    }

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

            // drawings don't have configurations, so we can return here
            if (swDocType == SwDmDocumentType.swDmDocumentDrawing)
            {
                return(lstProps);
            }

            // parts and assemblies have configurations
            // get a list of configs
            List <string> lstConfigNames;

            swCfgMgr       = swDoc.ConfigurationManager;
            lstConfigNames = new List <string>((string[])swCfgMgr.GetConfigurationNames());

            // get properties
            foreach (string strConfigName in lstConfigNames)
            {
                SwDMConfiguration swCfg           = (SwDMConfiguration)swCfgMgr.GetConfigurationByName(strConfigName);
                string[]          strCfgPropNames = swCfg.GetCustomPropertyNames();
                if (strCfgPropNames == null)
                {
                    continue;
                }

                foreach (string strPropName in strCfgPropNames)
                {
                    SwDmCustomInfoType nPropType  = 0;
                    object             oPropValue = swCfg.GetCustomProperty(strPropName, out nPropType);

                    // property type
                    string strPropType = "";
                    switch (nPropType)
                    {
                    case SwDmCustomInfoType.swDmCustomInfoDate:
                        strPropType = "date";
                        oPropValue  = Convert.ToDateTime(oPropValue);
                        break;

                    case SwDmCustomInfoType.swDmCustomInfoNumber:
                        strPropType = "number";
                        oPropValue  = Convert.ToDecimal(oPropValue);
                        break;

                    case SwDmCustomInfoType.swDmCustomInfoText:
                        strPropType = "text";
                        oPropValue  = Convert.ToString(oPropValue);
                        break;

                    case SwDmCustomInfoType.swDmCustomInfoYesOrNo:
                        strPropType = "yesno";
                        oPropValue  = oPropValue.Equals("Yes");
                        break;

                    case SwDmCustomInfoType.swDmCustomInfoUnknown:
                        strPropType = "";
                        break;
                    }

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

            swDoc.CloseDoc();
            return(lstProps);
        }