Esempio n. 1
0
        private void FindNDelOldNotes(ModelDoc2 swDoc)
        {
            Note       swNote = null;
            DrawingDoc swDraw = (DrawingDoc)swDoc;

            object[] vNotes;

            IView swView = swDraw.GetFirstView() as IView;

            vNotes = (object[])swView.GetNotes();
            for (int i = 0; i < vNotes.Length; i++)
            {
                swNote = (Note)vNotes[i];
                String snm = swNote.GetName();
                if (snm.Contains(ttname))
                {
                    Annotation myAnnotation = (Annotation)swNote.GetAnnotation();
                    swDoc.ClearSelection2(true);
                    myAnnotation.Select(false);
                    swDoc.DeleteSelection(false);
                }
            }
            swDoc.WindowRedraw();
        }
Esempio n. 2
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;
        }
Esempio n. 3
0
        private bool PrepareDrawingDoc(ModelDoc2 swModel, out Dictionary<string, bool> list)
        {
            list = new Dictionary<string, bool>();
            bool ret = false;
            //LinkedList<ModelDoc2> outModels;
            // if (_swAdd.GetAllUniqueModels(_swAdd.RootModel, out outModels))
            //{
            /*
                ModelDoc2 swAsmModel = null;
                SwDmDocumentOpenError oe;
                SwDMApplication swDocMgr = SwAddin.GetSwDmApp();
                var swDoc = (SwDMDocument8)swDocMgr.GetDocument(swModel.GetPathName(),
                    SwDmDocumentType.swDmDocumentDrawing, true, out oe);
                if (swDoc != null)
                {
                    SwDMSearchOption src = swDocMgr.GetSearchOptionObject();
                    object brokenRefVar;
                    var varRef = (object[])swDoc.GetAllExternalReferences2(src, out brokenRefVar);
                    var name = (string)varRef[0];
                    swAsmModel = outModels.FirstOrDefault(modelDoc2 => modelDoc2.GetPathName() == name);
                }
            */
            ModelDoc2 swAsmModel = GetCurrentAsmModel(swModel);

            OleDbConnection oleDb;
            if (swAsmModel != null)
            {
                if (_createProgramm)
                {
                    var matName = swAsmModel.get_CustomInfo2("", "Material");
                    if (matName == "" && swAsmModel.GetConfigurationCount() > 1)
                    {
                        string val, resolvedVal;
                        if (
                            swAsmModel.Extension.get_CustomPropertyManager(swAsmModel.IGetActiveConfiguration().Name).
                                Get4(
                                    "Material", false, out val, out resolvedVal))
                            matName = val;
                    }
                    _z = ParseMaterialName(matName);
                }

                if (_swAdd.OpenModelDatabase(swAsmModel, out oleDb))
                {
                    bool isPropName, isStdSketchNum, isSheetNames;
                    if (IsNeededColumnInDbFile(oleDb, out isPropName, out isStdSketchNum, out isSheetNames))
                    {
                        var objNames = _namesOfColumnNameFromDimLimits.Where(x => x.Contains("obj"));
                        var listId = new List<int>();
                        foreach (var objName in objNames)
                        {
                            int id = FrmSetParameters.GetIdFromColumnName(objName);
                            if (!listId.Contains(id))
                                listId.Add(id);
                        }
                        var dictIdSize = new Dictionary<int, double>();
                        var cm = new OleDbCommand("SELECT * FROM objects", oleDb);
                        var rd = cm.ExecuteReader();
                        while (rd.Read())
                        {
                            if (listId.Contains((int) rd["id"]))
                            {
                                double val;
                                if (_swAdd.GetObjectValue(swAsmModel, (string) rd["name"], 14, out val) &&
                                    !dictIdSize.ContainsKey((int) rd["id"]))
                                    dictIdSize.Add((int) rd["id"], val);
                            }
                        }
                        rd.Close();
                        cm = new OleDbCommand("SELECT * FROM dimlimits", oleDb);
                        rd = cm.ExecuteReader();
                        while (rd.Read())
                        {
                            var lB = (from i in listId
                                      let mn = (int) rd["obj" + i + "min"]
                                      let mx = (int) rd["obj" + i + "max"]
                                      select (mn <= dictIdSize[i]) && (dictIdSize[i] <= mx)).ToList();
                            if (lB.Aggregate(true, (current, b) => (b && current)))
                            {
                                if (isSheetNames)
                                {
                                    var needSheetsNumb = (string) rd["sheetnames"];
                                    swModel.ClearSelection();
                                    foreach (var strNum in needSheetsNumb.Split(','))
                                    {
                                        string strNm = strNum.Trim();
                                        string num = strNm.Substring(0, strNm.Length - 1);
                                        string side = strNm.Substring(strNm.Length - 1);
                                        list.Add(num, side.ToLower() == "l");
                                    }
                                    var swDrw = (DrawingDoc) swModel;
                                    var sheetnames = (string[]) swDrw.GetSheetNames();

                                    foreach (var sheetname in sheetnames)
                                    {
                                        if (sheetname.Contains("1") ||
                                            list.Keys.Contains(sheetname.Substring(sheetname.Length - 1)))
                                            continue;
                                        swModel.Extension.SelectByID2(sheetname, "SHEET", 0, 0, 0, true, 0, null, 0);
                                    }
                                    swModel.DeleteSelection(true);
                                    ret = true;
                                }
                                break;
                            }
                        }
                        rd.Close();
                    }
                    oleDb.Close();
                }
            }
            return ret;
        }
Esempio n. 4
0
        private bool GetCutComponents(ModelDoc2 swModel,
            out LinkedList<Component2> outCutComponents, out LinkedList<Component2> outShelfComponents, out bool delete)
        {
            delete = false;
            var swComponents = new LinkedList<Component2>();
            ModelDoc2 swCompModel;

            outCutComponents = new LinkedList<Component2>();
            outCutComponents.Clear();

            outShelfComponents = new LinkedList<Component2>();
            outShelfComponents.Clear();

            var swConfig = (Configuration)swModel.GetActiveConfiguration();
            if (swConfig != null)
            {
                var swRootComponent = (Component2)swConfig.GetRootComponent();

                if (GetComponents(swRootComponent, swComponents, true, false))
                {
                    foreach (Component2 comp in swComponents)
                    {
                        swCompModel = (ModelDoc2)comp.GetModelDoc();
                        if (swCompModel != null)
                        {
                            if (swCompModel.get_CustomInfo2("", "swrfIsCut") == "Yes")
                            {
                                outCutComponents.AddLast(comp);
                            }
                            if (swCompModel.get_CustomInfo2("", "swrfIsShelf") == "Yes")
                            {
                                if (swCompModel.GetType() == (int)swDocumentTypes_e.swDocASSEMBLY)
                                    swCompModel.DeleteCustomInfo2("", "swrfIsShelf");
                                else
                                {
                                    if (comp.GetTexture("") != null)
                                        swCompModel.Save();
                                    outShelfComponents.AddLast(comp);
                                }

                                #region �������� ������ �������� ���������
                                var swFeat = comp.FirstFeature();
                                while (swFeat != null)
                                {
                                    if (swFeat.GetTypeName2() == "Cavity")
                                    {
                                        if (swFeat.Name.Contains("#swrf"))
                                        {
                                            swFeat.Select(true);
                                            delete = true;
                                        }
                                    }
                                    swFeat = swFeat.IGetNextFeature();
                                }
                                if (delete)
                                {
                                    swModel.DeleteSelection(true);
                                    swModel.ClearSelection2(true);
                                    GC.Collect();
                                }
                                #endregion
                            }
                        }
                    }
                }
            }
            return true;
        }
Esempio n. 5
0
        public void PreCalcNote(ModelDoc2 swDoc, String[] listt)
        {
            DrawingDoc swDraw       = (DrawingDoc)swDoc;
            TextFormat swTextFormat = null;

            // Находим и удаляем старые ТТ
            FindNDelOldNotes(swDoc);
            if (listt.Length == 0)
            {
                return;
            }

            // Создадим времменный блок. Туда будем вставлять строки и определять высоту блока.
            Note       swNoteTemp = (Note)swDoc.InsertNote("");
            Annotation myAnnot    = (Annotation)swNoteTemp.GetAnnotation();

            swTextFormat            = myAnnot.GetTextFormat(0) as TextFormat;
            swTextFormat.LineLength = c_width - 0.005;
            myAnnot.SetTextFormat(0, false, swTextFormat);
            swNoteTemp.SetTextJustification((int)swTextJustification_e.swTextJustificationLeft);

            // Определим доступное поле для ТТ
            Sheet swSheet = (Sheet)swDraw.GetCurrentSheet();

            swSheet.GetSize(ref sh_width, ref sh_height);
            double fheight = sh_height - c_topmargin - c_height - 1 * 0.005;

            notes.Add(new NoteTT());
            NoteTT ntt = notes[0];

            ntt.NoteText  = "<PARA indent=5 findent=-5 number=on ntype=1 nformat=$$. nstartNum = 1>";
            ntt.curheight = 0;

            const string notefmt = "<PARA indent=5 findent=-5 number=on ntype=1 nformat=$$.>";
            int          curind  = 0;

            for (int i = 0; i < listt.Length; i++)
            {
                ntt = notes[curind];
                string onestring = notefmt + listt[i];
                // Вставляем одну ТТ во временный блок
                swNoteTemp.SetText(onestring);
                double tempnoteheight = GetTempNoteHeight(swNoteTemp);
                // Проверяем получающуюся высоту примечания
                if (ntt.curheight + tempnoteheight <= fheight)
                {
                    // Если помещается, дописываем текст и увеличиваем высоту проверки
                    ntt.NoteText  += listt[i] + System.Environment.NewLine;
                    ntt.curheight += tempnoteheight;
                }
                else
                {
                    // Иначе создаём новое примечание
                    notes.Add(new NoteTT());
                    curind++;
                    ntt           = notes[curind];
                    ntt.NoteText  = "<PARA indent=5 findent=-5 number=on ntype=1 nformat=$$. nstartNum = " + (i + 1).ToString() + ">";
                    ntt.curheight = 0;
                }
            }

            swDoc.ClearSelection2(true);
            myAnnot.Select(false);
            swDoc.DeleteSelection(false);
            swDoc.WindowRedraw();
        }