Exemple #1
0
        protected override void AddValue(object value)
        {
            SwDmCustomInfoType type = GetPropertyType(value);

            if (!m_CutList.CutListItem.AddCustomProperty(Name, type, value?.ToString()))
            {
                throw new Exception("Failed to add custom property");
            }
        }
        protected override void AddValue(object value)
        {
            SwDmCustomInfoType type = GetPropertyType(value);

            if (!m_Conf.Configuration.AddCustomProperty(Name, type, value?.ToString()))
            {
                throw new Exception("Failed to add custom property");
            }

            m_Conf.Document.IsDirty = true;
        }
Exemple #3
0
        public static void ActualizaAllCash()
        {
            string[] notHiddenDirectories = GetNotHiddenDirectories(Furniture.Helpers.LocalAccounts.modelPathResult);
            string[] filesInCurrentDir = new string[0];

            SwDmDocumentOpenError oe = new SwDmDocumentOpenError();
            SwDMApplication swDocMgr = SwAddin.GetSwDmApp();
            SwDMSearchOption src = swDocMgr.GetSearchOptionObject(); ;
            SwDmCustomInfoType type = new SwDmCustomInfoType();

            foreach (var notHiddenDirectory in notHiddenDirectories)
            {
                string rFileName = notHiddenDirectory.Replace("_SWLIB_", "_SWLIB_BACKUP").Replace("_swlib_", "_swlib_backup");
                filesInCurrentDir = Directory.GetFiles(rFileName, "*.SLDASM");
                foreach (var file in filesInCurrentDir)
                {
                    rFileName = file;
                    string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(rFileName);
                    if (rFileName.ToLower().Contains("_swlib_backup") && (fileNameWithoutExtension.Last() == 'P' || fileNameWithoutExtension.Last() == 'p') && Path.GetExtension(rFileName) == ".SLDASM" && !rFileName.ToLower().Contains("вспомогательн"))
                    {

                        int rr;
                        if (int.TryParse(fileNameWithoutExtension.Substring(fileNameWithoutExtension.Length - 3, 2), out rr))
                        {
                            //if (rr != 1)
                            //{
                            //    string newFilePath = Path.Combine(Path.GetDirectoryName(rFileName),
                            //                                      Path.GetFileNameWithoutExtension(rFileName).Substring(
                            //                                          0,
                            //                                          Path.GetFileNameWithoutExtension(rFileName).Length - 4) +
                            //                                      "#01P.SLDASM"); // + Path.GetExtension(fileName));
                            //    if (File.Exists(newFilePath))
                            //        File.SetAttributes(newFilePath, FileAttributes.Normal);
                            //    File.SetAttributes(file, FileAttributes.Hidden);
                            //}

                            if ((File.GetAttributes(file) & FileAttributes.Hidden) == FileAttributes.Hidden)
                            {
                                DeleteIfNonAccessory(file, src, swDocMgr, oe, type);

                            }
                        }
                    }
                }

            }
        }
        protected override void AddValue(object value)
        {
            if (m_Conf == null || m_Conf.Configuration == m_Doc.Configurations.Active.Configuration)
            {
                SwDmCustomInfoType type = GetPropertyType(value);

                if (!m_CutList.CutListItem.AddCustomProperty(Name, type, value?.ToString()))
                {
                    throw new Exception("Failed to add custom property");
                }
            }
            else
            {
                throw new ConfigurationSpecificCutListPropertiesWriteNotSupportedException();
            }

            m_Conf.Document.IsDirty = true;
        }
Exemple #5
0
        private void AutoDimensionDrawing2(ModelDoc2 swModel, bool many )
        {
            bool del3List = false;
            var thrdList = new List<string>();
            int shi = 0;
            isValidXml = true;

            var swDrawing = (DrawingDoc)swModel;
            if (swModel.GetCustomInfoValue("", "AutoDim") == "No")
            {
                if (many)
                {
                    MessageBox.Show(@"Если хотите образмерить чертеж, смените No на Yes в поле 'AutoDim' свойств данного чертежа",
                        @"MrDoors", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }
                isValidXml = false;
            }
            if (swModel.GetCustomInfoValue("", "MakeCNCprog") == "Yes")
            {
                _createProgramm = true;
            }
            if (!isValidXml && !_createProgramm) // если не надо создавать программу и авто дим = но, то образмеривать просто не нужно.
                return;
            swModel.Extension.SetUserPreferenceDouble((int)swUserPreferenceDoubleValue_e.swDetailingDimToDimOffset,
                                                      (int)swUserPreferenceOption_e.swDetailingNoOptionSpecified, 0.006);
            swModel.Extension.SetUserPreferenceDouble((int)swUserPreferenceDoubleValue_e.swDetailingObjectToDimOffset,
                                                      (int)swUserPreferenceOption_e.swDetailingNoOptionSpecified, 0.010);

            Dictionary<string, bool> listSide;
            string targetModelPath = null;
            if (!File.Exists(Path.Combine(Path.GetDirectoryName(_swAdd.RootModel.GetPathName()), "fpTime.txt")))
            {
                //MessageBox.Show("Образмеривание детали может пройти некорректно! Для корректного образмеривания детали необходимо произвести Окончательную обработку заказа.");
                throw new Exception("Образмеривание детали может пройти некорректно! Для корректного образмеривания детали необходимо произвести Окончательную обработку заказа.");
            }
            else
            {
                //просто взять Sketch Number

               string fnameWithoutExt = Path.GetFileNameWithoutExtension(swModel.GetPathName());
                fnameWithoutExt = fnameWithoutExt.Substring(fnameWithoutExt.Length - 4, 4);
                SwDMDocument8 swDoc = null;
                SwDMApplication swDocMgr = SwAddin.GetSwDmApp();
                SwDmDocumentOpenError oe;
                SwDmCustomInfoType type;
                if (!(fnameWithoutExt[0] == '#' && (fnameWithoutExt[3] == 'P' || fnameWithoutExt[3] == 'p')))
                {

                    swDoc = (SwDMDocument8) swDocMgr.GetDocument(Path.ChangeExtension(swModel.GetPathName(), "SLDASM"),SwDmDocumentType.swDmDocumentAssembly, true, out oe);

                }
                else
                {
                    object brokenRefVar;
                    SwDMSearchOption src = swDocMgr.GetSearchOptionObject();

                    var swDocDraw = (SwDMDocument8)swDocMgr.GetDocument(swModel.GetPathName(), SwDmDocumentType.swDmDocumentDrawing, true, out oe);
                    var varRef = (object[])swDocDraw.GetAllExternalReferences2(src, out brokenRefVar);
                    swDocDraw.CloseDoc();
                    targetModelPath = (string)varRef[0];
                    swDoc = (SwDMDocument8)swDocMgr.GetDocument(targetModelPath, SwDmDocumentType.swDmDocumentAssembly, true, out oe);
                }
                if (swDoc != null)
                {
                    var prop = swDoc.GetCustomProperty("Sketch Number", out type);
                    if (string.IsNullOrEmpty(prop) || prop == "0")
                        throw new Exception("Образмеривание детали прервано, т.к. может пройти некорректно ! Для корректного образмеривания детали необходимо произвести Окончательную обработку заказа.");
                    swDoc.CloseDoc();
                }
                _swAdd.SetModelProperty(swModel, "WasMesure", string.Empty, swCustomInfoType_e.swCustomInfoYesOrNo, "Yes", true);
            }
            string pathXml = WriteXmlFile(swModel, isValidXml, targetModelPath);

            bool isNeededSheetNumber = PrepareDrawingDoc(swModel, out listSide);
            bool dimOnlyNew = false;
            if (swModel.GetCustomInfoValue("", "DimOnlyNew") == "Yes")
                dimOnlyNew = true;
            var vSheetNames = (string[])swDrawing.GetSheetNames();
            var rootNode = _node;
            bool atLeastOneF1View = false;

            foreach (var vSheetName in vSheetNames)
            {
                bool iftherewasAhole = false;
                XmlElement element = null;
                XmlElement sheetNode = null;
                KeyValuePair<string,string> tableNameAttribute = new KeyValuePair<string, string>();
                if (_createProgramm && !string.IsNullOrEmpty(pathXml))
                {
                    element = _cxml.CreateElement("Sheet");
                    element.SetAttribute("Name", vSheetName);
                    _node = rootNode.AppendChild(element);
                    sheetNode = element;
                }

                double vScale = 0;
                var type = new List<string>();
                var listSize = new List<SizeForDim>();
                swDrawing.ActivateSheet(vSheetName);
                swModel.Extension.SelectByID2(vSheetName, "SHEET", 0, 0, 0, true,
                                              (int)swSelectionMarkAction_e.swSelectionMarkAppend, null, 0);
                swModel.ViewZoomToSelection();
                swModel.ClearSelection();
                var swSheet = (Sheet)swDrawing.GetCurrentSheet();
                var swViews = (object[])swSheet.GetViews();
                bool side = shi == 1;
                if (isNeededSheetNumber && listSide.ContainsKey(vSheetName.Substring(vSheetName.Length - 1)))
                    side = listSide[vSheetName.Substring(vSheetName.Length - 1)];
                if (vSheetName.ToUpper().Contains("FACE"))
                    side = true;
                if (vSheetName.ToUpper().Contains("BACK"))
                    side = false;

                if (swViews != null)
                {
                    var rootViewElement = _node;
                    if (Properties.Settings.Default.ViewsBeforeDimen)
                        ReplaceViews(swViews, swDrawing);
                    foreach (var t in swViews)
                    {
                        #region Образмеривание вида
                        var swView = (View) t;
                        swModel.ClearSelection2(true);

                        const string expr = "^F[1-6]$";

                        Match isMatch = Regex.Match(swView.Name, expr, RegexOptions.IgnoreCase);

                        if (_createProgramm && swView.Name.ToLower().Contains("const"))
                        {

                            //Logging.Log.Instance.Fatal(@"На данный чертеж программа не будет создана! " + swModel.GetPathName() + "swView.Name = " + swView.Name);
                            //MessageBox.Show(@"На данный чертеж программа не будет создана!", @"MrDoors",MessageBoxButtons.OK,MessageBoxIcon.Exclamation);
                        }

                        if (!(isMatch.Success || swView.Name.Contains("Чертежный вид")) ||
                            swView.Name.ToLower().Contains("const") ||
                            swView.Type == (int)swDrawingViewTypes_e.swDrawingDetailView) continue;

                        if (_createProgramm && !isMatch.Success)
                        {
                            _createProgramm = false;
                            //Logging.Log.Instance.Fatal(@"На данный чертеж программа не будет создана! " + swModel.GetPathName() + "swView.Name = " + swView.Name);
                            //MessageBox.Show(@"На данный чертеж программа не будет создана!", @"MrDoors",
                            //                MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        }

                        swDrawing.ActivateView(swView.GetName2());
                        swView.UseSheetScale = 0;

                        var list = HideUnusedComponents(swView, dimOnlyNew);

                        try
                        {
                            vScale = ((double[]) swView.ScaleRatio)[1];
                            swView.SetDisplayMode3(false, (int) swDisplayMode_e.swFACETED_HIDDEN, true, true);

                            #region Процесс образмеривания

                            using (var d = new DimensionView(_swApp, BlockPositionExtension.FromBool(side), dimOnlyNew))
                            {

                                d.DimView(side);
                                if (!iftherewasAhole)
                                    iftherewasAhole = d.IsHole;
                                if (!isNeededSheetNumber && !side && !iftherewasAhole)
                                    del3List = true;
                                else
                                {
                                    if (isNeededSheetNumber && !iftherewasAhole)
                                    {
                                        del3List = true;
                                        thrdList.Add(vSheetName);
                                    }
                                }
                                foreach (var tp in d.List)
                                {
                                    if (!type.Contains(tp))
                                        type.Add(tp);
                                }
                                listSize.Add(d.AddSize);

                                #region Запись данных в xml файл

                                if (element != null)
                                {
                                    element = _cxml.CreateElement("View");
                                    element.SetAttribute("Name", swView.Name);
                                    if (swView.Name == "F1")
                                    {
                                        atLeastOneF1View = true;

                                            SwDmDocumentOpenError oe;
                                            SwDMApplication swDocMgr = SwAddin.GetSwDmApp();
                                            var swDoc = (SwDMDocument8)swDocMgr.GetDocument(Path.ChangeExtension(swModel.GetPathName(), "SLDASM"),
                                                                                             SwDmDocumentType.swDmDocumentAssembly, true, out oe);
                                            if (swDoc != null)
                                            {
                                                var cit = new SwDmCustomInfoType();
                                                string[] names = swDoc.GetCustomPropertyNames();
                                                string extFeats = null,faner11 = null,faner12 = null,faner21 = null,faner22 = null;

                                                if (names.Contains("ExtFanerFeats"))
                                                    extFeats = swDoc.GetCustomProperty("ExtFanerFeats", out cit);
                                                double angle = 57.29577951308232*swView.Angle; //(180/П)
                                                if (Math.Abs(angle) < 0.000001 || Math.Abs(angle + 90) < 0.000001 || Math.Abs(angle - 270) < 0.000001 || Math.Abs(angle - 180) < 0.000001 || Math.Abs(angle - 90) < 0.000001) //!string.IsNullOrEmpty(extFeats) && extFeats == "Yes" &&
                                                {
                                                    if (names.Contains("Faner11"))
                                                        faner11 = swDoc.GetCustomProperty("Faner11", out cit);
                                                    if (names.Contains("Faner12"))
                                                        faner12 = swDoc.GetCustomProperty("Faner12", out cit);
                                                    if (names.Contains("Faner21"))
                                                        faner21 = swDoc.GetCustomProperty("Faner21", out cit);
                                                    if (names.Contains("Faner22"))
                                                        faner22 = swDoc.GetCustomProperty("Faner22", out cit);

                                                    var tmpElem = _cxml.CreateElement("Comment");
                                                    string comment = FrmEdge.GetCommentFromProperties(faner11,faner12,faner21,faner22, angle, _swAdd,swModel);
                                                    double angle2 = angle + 90;
                                                    double angle4 = angle + 180;
                                                    double angle3 = angle + 270;
                                                    if (angle2 > 270)
                                                        angle2 = angle2%360;
                                                    if (angle3 > 270)
                                                        angle3 = angle3 % 360;
                                                    if (angle4 > 270)
                                                        angle4 = angle4 % 360;
                                                    string comment2 = FrmEdge.GetCommentFromProperties(faner11, faner12, faner21, faner22, angle2, _swAdd, swModel);
                                                    string comment3 = FrmEdge.GetCommentFromProperties(faner11, faner12, faner21, faner22, angle3, _swAdd, swModel);
                                                    string comment4 = FrmEdge.GetCommentFromProperties(faner11, faner12, faner21, faner22, angle4, _swAdd, swModel);
                                                    tmpElem.SetAttribute("Rot270",comment3);
                                                    tmpElem.SetAttribute("Rot180",comment4);
                                                    tmpElem.SetAttribute("Rot90", comment2);
                                                    tmpElem.SetAttribute("Rot0", comment);
                                                    rootNode.PrependChild(tmpElem);
                                                }

                                            }

                                        //swDoc.CloseDoc();

                                        //int warnings = 0;
                                        //int errors = 0;
                                        //var swModelDoc = _swApp.OpenDoc6(Path.ChangeExtension(swModel.GetPathName(), "SLDASM"), (int)swDocumentTypes_e.swDocASSEMBLY,
                                        //                  (int)swOpenDocOptions_e.swOpenDocOptions_Silent, "", errors,
                                        //                  warnings);
                                        //if (!string.IsNullOrEmpty(swModelDoc.CustomInfo2["", "ExtFanerFeats"]) && swModelDoc.CustomInfo2["", "ExtFanerFeats"] == "Yes")
                                        //{
                                        //    var tmpElem = _cxml.CreateElement("Comment");
                                        //    string comment = FrmEdge.GetComment(swModelDoc, swView.Angle, _swAdd);
                                        //    tmpElem.SetAttribute("Rot270", string.Empty);
                                        //    tmpElem.SetAttribute("Rot90", string.Empty);
                                        //    tmpElem.SetAttribute("Rot0", comment);
                                        //    rootNode.PrependChild(tmpElem);
                                        //}

                                    }
                                    if (_node != null)
                                    {
                                        _node = rootViewElement.AppendChild(element);
                                        switch (d.Side)
                                        {
                                            case BlockPosition.LeftTopToRightBottom:

                                                if (swView.Name == "F1")
                                                    tableNameAttribute = new KeyValuePair<string, string>("F1","J");
                                                if (swView.Name == "F6")
                                                {
                                                    if (tableNameAttribute.Key!="F1") // F1 -  приоритетнее
                                                        tableNameAttribute = new KeyValuePair<string, string>("F6", "B");
                                                }
                                                if (string.IsNullOrEmpty(tableNameAttribute.Key))
                                                {
                                                    tableNameAttribute = new KeyValuePair<string, string>("none","J");
                                                }
                                                break;
                                            case BlockPosition.RightTopToLeftBottom:
                                                if (swView.Name == "F1")
                                                    tableNameAttribute = new KeyValuePair<string, string>("F1","B");
                                                if (swView.Name == "F6")
                                                {
                                                    if (tableNameAttribute.Key!="F1") // F1 -  приоритетнее
                                                        tableNameAttribute = new KeyValuePair<string, string>("F6", "J");
                                                }
                                                if (string.IsNullOrEmpty(tableNameAttribute.Key))
                                                {
                                                    tableNameAttribute = new KeyValuePair<string, string>("none", "B");
                                                }
                                                break;
                                            case BlockPosition.LeftBottomToRightTop:
                                            case BlockPosition.RigthBottomToLeftTop:
                                                //MessageBox.Show(
                                                //    "В этом чертеже начало координат находится внизу. Программа может быть создана некорректно!",
                                                //    @"MrDoors", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                                                // element = _cxml.CreateElement("Table");
                                                // element.SetAttribute("Name", "Не удалось определить наименование стола!");
                                                //_node=_node.AppendChild(element);
                                                break;

                                        }
                                    }

                                    int i = 0;
                                    string id = "id" + i;
                                    element = _cxml.CreateElement(id);

                                    element.SetAttribute("X", Math.Round(d.X).ToString(CultureInfo.CreateSpecificCulture("ru-RU")));
                                    element.SetAttribute("Y", Math.Round(d.Y).ToString(CultureInfo.CreateSpecificCulture("ru-RU")));
                                    if (swView.Name == "F1" || swView.Name == "F6")
                                        element.SetAttribute("Z", _z.ToString(CultureInfo.CreateSpecificCulture("ru-RU")));
                                    if (_node != null)
                                        _node.AppendChild(element);

                                    foreach (var ls in d.ListSize)
                                    {
                                        i++;
                                        id = "id" + i;
                                        element = _cxml.CreateElement(id);

                                        element.SetAttribute("X", ls.X.ToString(CultureInfo.CreateSpecificCulture("ru-RU")));
                                        element.SetAttribute("Y",  ls.Y.ToString(CultureInfo.CreateSpecificCulture("ru-RU")));
                                        element.SetAttribute("Diameter",  ls.Diameter.ToString(CultureInfo.CreateSpecificCulture("ru-RU")));
                                        element.SetAttribute("Depth",ls.Depth.ToString(CultureInfo.CreateSpecificCulture("ru-RU")));

                                        if (_node != null)
                                            _node.AppendChild(element);
                                    }
                                    _node = _node.ParentNode;
                                }

                                #endregion
                            }

                            #endregion

                            swView.SetDisplayMode3(false, (int) swDisplayMode_e.swFACETED_HIDDEN_GREYED, true, true);

                            swDrawing.ActivateSheet(vSheetName);
                        }
                        catch (Exception e)
                        {
                            MessageBox.Show(@"Ошибка при образмеривании! " + e.Message, @"MrDoors",
                                            MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                        finally
                        {
                            if (dimOnlyNew)
                                ShowHiddenComponents(list);
                        }

                        #endregion
                    }
                }
                if (type.Count != 0)
                    LegendMaker(swModel, swDrawing, type, vScale);
                if (!string.IsNullOrEmpty(tableNameAttribute.Value))
                    sheetNode.SetAttribute("TableName", tableNameAttribute.Value);
                if (Properties.Settings.Default.ScaleWhenDimen && !del3List && shi != 0)
                    AutoScaleSheet(listSize, swSheet, vScale, side);
                shi++;
                if(_node!=null)
                    _node = _node.ParentNode;
                AutoArrangeDimentions(vSheetName,dimOnlyNew);
            }
            swModel.EditRebuild3();
            if (shi == 3)
            {
                if (del3List)
                {
                    if (isNeededSheetNumber && thrdList.Count > 0)
                        foreach (var sh in thrdList)
                            swModel.Extension.SelectByID2(sh, "SHEET", 0, 0, 0, true, 0, null, 0);
                    else
                    {
                     if (!swModel.Extension.SelectByID2("Лист3", "SHEET", 0, 0, 0, false, 0, null, 0))
                     {
                         swModel.Extension.SelectByID2("Back3", "SHEET", 0, 0, 0, false, 0, null, 0);
                     }
                    }
                    swModel.DeleteSelection(true);
                }
                else
                    SheetNumering(swModel, swDrawing);
            }
            swModel.ForceRebuild3(false);
            bool writeXml = true;
            if (atLeastOneF1View)
            {
                try
                {
                    writeXml=SomeLogicChanges(swModel);
                }
                catch(Exception e)
                {
                    if (swModel.GetPathName() != null)
                        Logging.Log.Instance.Fatal(e, "Ошибка при применении логики к XML. " + swModel.GetPathName());
                    else
                        Logging.Log.Instance.Fatal(e, "Ошибка при применении логики к XML. ");

                }
                if (writeXml)
                    StopWriteXml(pathXml);
            }

            return;
        }
Exemple #6
0
        private static void DeleteIfNonAccessory(string file, SwDMSearchOption src, SwDMApplication swDocMgr, SwDmDocumentOpenError oe, SwDmCustomInfoType type)
        {
            //удалить все связанные, кроме аксесуаров..
            if (!File.Exists(file))
                return;
            if (!file.ToLower().Contains("_swlib_backup") || Path.GetFileNameWithoutExtension(file).First() == '~')
                return;
            var swDoc = swDocMgr.GetDocument(file, SwDmDocumentType.swDmDocumentAssembly, true, out oe);
            if (swDoc == null)
            {
                Logging.Log.Instance.Debug("Не удалось сделать GetDocument в " + file);
                return;
            }
            bool isAccessory;
            try
            {
                string[] tmp = swDoc.GetCustomPropertyNames();
                if (tmp != null && tmp.Contains("Accessories"))
                    isAccessory = swDoc.GetCustomProperty("Accessories", out type) == "Yes";
                else
                    isAccessory = false;
            }
            catch (Exception)
            {
                Logging.Log.Instance.Debug("Ошибка при попытке обратится к св-ву Accessories. Деталь: " +
                                            swDoc.FullName);
                swDoc.CloseDoc();
                return;
            }
            if (isAccessory) // если это аксесуар, то ничего не делаем.
            {
                swDoc.CloseDoc();
                return;
            }
            if (Path.GetExtension(file) == ".SLDASM")
            {
                string[] extReferences = swDoc.GetAllExternalReferences(src);
                swDoc.CloseDoc();
                foreach (var extReference in extReferences)
                {
                    DeleteIfNonAccessory(extReference, src, swDocMgr, oe, type);
                }
            }
            else
                swDoc.CloseDoc();

            if (Path.GetExtension(file) == ".SLDASM" || Path.GetExtension(file) == ".SLDPRT")
                File.Delete(file);
        }
Exemple #7
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);
        }
 public bool ConfigAddProperty(string AttributeName, SwDmCustomInfoType Type, string Value, SwDMConfiguration14 swCfg)
 {
     ConfigDeleteProperty(AttributeName, swCfg);
     return swCfg.AddCustomProperty(AttributeName, Type, Value);
 }
 public bool DocumentAddProperty(string AttributeName, SwDmCustomInfoType Type, string Value)
 {
     try
     {
         if (DocumentPropertyExists(AttributeName))
         {
             DocumentDeleteProperty(AttributeName);
         }
         return Doc.AddCustomProperty(AttributeName, Type, Value);
     }
     catch
     {
         return false;
     }
 }