コード例 #1
0
        /// <summary>
        /// Метод построения детали
        /// </summary>
        public void BuildCandle(CandleParametrs objParametr)
        {
            /// <summary>
            /// Экземпляру присваиваем значение объекта класса
            /// </summary>
            _parametr = objParametr;

            /// <summary>
            /// Проверка построена ли деталь
            /// </summary>
            _parametr.ExistDetail = true;

            /// <summary>
            /// Путь до рабочего стола
            /// </summary>
            var pathName = System.Environment.GetFolderPath(System.Environment.SpecialFolder.DesktopDirectory);

            /// <summary>
            /// Присваивание параметров
            /// </summary>
            var carvingLength   = _parametr.CarvingLength;
            var nutLength       = _parametr.NutLength;
            var nutSize         = _parametr.NutSize;
            var isolatorLength  = _parametr.IsolatorLength;
            var chamferRadius   = _parametr.ChamferRadius;
            var plinthLength    = _parametr.PlinthLength;
            var headLength      = _parametr.HeadLength;
            var pitchSize       = _parametr.PitchSize;
            var carvingRadius   = _parametr.CarvingRadius;
            var textEtching     = _parametr.TextEtching;
            var electrodeLength = _parametr.ElectrodeLength;

            /// <summary>
            /// Методы класса CandleCreator
            /// </summary>
            if (_parametr.ExistHead == true)
            {
                CandleCreator.CreateHead(headLength, SwApp, SwModel, _detailNames, pathName);
            }
            CandleCreator.CreatePlinth(plinthLength, SwApp, SwModel, _detailNames, textEtching, pathName);
            CandleCreator.CreateNut(nutLength, nutSize, SwApp, SwModel, _detailNames, chamferRadius, pathName);
            CandleCreator.CreateIsolator(isolatorLength, SwApp, SwModel, _detailNames, pathName);
            CandleCreator.CreateCarving(carvingLength, SwApp, SwModel, _detailNames, pitchSize, carvingRadius, electrodeLength, pathName);

            /// <summary>
            /// Создание сборки
            /// </summary>
            AssemblyDoc swAssembly = SwApp.NewAssembly();

            SwModel = ((ModelDoc2)(SwApp.ActiveDoc));
            if (_parametr.ExistHead == true)
            {
                swAssembly.AddComponent2(_detailNames[0], 0, 0, headLength / 2);
                swAssembly.AddComponent2(_detailNames[1], 0, 0, plinthLength / 2 + headLength);
                swAssembly.AddComponent2(_detailNames[2], 0, 0, nutLength / 2 + headLength + plinthLength);
                swAssembly.AddComponent(_detailNames[3], 0, 0, isolatorLength / 2 + headLength + plinthLength + nutLength);
                swAssembly.AddComponent(_detailNames[4], 0, 0, carvingLength / 2 + headLength + plinthLength + isolatorLength + nutLength);
            }
            else
            {
                swAssembly.AddComponent2(_detailNames[0], 0, 0, plinthLength / 2 + headLength);
                swAssembly.AddComponent2(_detailNames[1], 0, 0, nutLength / 2 + headLength + plinthLength);
                swAssembly.AddComponent(_detailNames[2], 0, 0, isolatorLength / 2 + headLength + plinthLength + nutLength);
                swAssembly.AddComponent(_detailNames[3], 0, 0, carvingLength / 2 + headLength + plinthLength + isolatorLength + nutLength);
            }
            /// <summary>
            /// Выбор вида "Изометрия"
            /// </summary>
            SwModel.Extension.SelectByID2("", "FACE", 0, 0, 0, true, 0, null, 0);
            swAssembly.AddMate((int)swMateType_e.swMateCONCENTRIC, (int)swMateAlign_e.swAlignAGAINST, false, 1, 0);
            SwModel.ShowNamedView("*Изометрия");
            SwModel.ClearSelection();
            SwModel.EditRebuild3();

            /// <summary>
            /// Закрытие созданных документов
            /// </summary>
            SwApp.CloseDoc(_detailNames[0]);
            SwApp.CloseDoc(_detailNames[1]);
            SwApp.CloseDoc(_detailNames[2]);
            SwApp.CloseDoc(_detailNames[3]);
            if (_parametr.ExistHead == true)
            {
                SwApp.CloseDoc(_detailNames[4]);
            }

            /// <summary>
            /// Сохранение сборки
            /// </summary>
            string modelName = pathName + "Свеча.SLDASM";

            SwModel.SaveAs(modelName);
        }