예제 #1
0
        public void CreateCube()
        {
            //make sure we have a part open
            string partTemplate = iSwApp.GetUserPreferenceStringValue((int)swUserPreferenceStringValue_e.swDefaultTemplatePart);

            if ((partTemplate != null) && (partTemplate != ""))
            {
                IModelDoc2 modDoc = (IModelDoc2)iSwApp.NewDocument(partTemplate, (int)swDwgPaperSizes_e.swDwgPaperA2size, 0.0, 0.0);

                modDoc.InsertSketch2(true);
                modDoc.SketchRectangle(0, 0, 0, .1, .1, .1, false);
                //Extrude the sketch
                IFeatureManager featMan = modDoc.FeatureManager;
                featMan.FeatureExtrusion(true,
                                         false, false,
                                         (int)swEndConditions_e.swEndCondBlind, (int)swEndConditions_e.swEndCondBlind,
                                         0.1, 0.0,
                                         false, false,
                                         false, false,
                                         0.0, 0.0,
                                         false, false,
                                         false, false,
                                         true,
                                         false, false);
            }
            else
            {
                System.Windows.Forms.MessageBox.Show("There is no part template available. Please check your options and make sure there is a part template selected, or select a new part template.");
            }
        }
예제 #2
0
        private IPartDoc NewPartDoc(ISldWorks swApp)
        {
            Assert.NotNull(swApp);

            var partTemPath = swApp.GetUserPreferenceStringValue((int)
                                                                 swUserPreferenceStringValue_e.swDefaultTemplatePart)?.Replace("零件", "gb_part");

            Assert.IsTrue(File.Exists(partTemPath));

            return(swApp.NewDocument(partTemPath, 0, 0, 0) as IPartDoc);
        }
        /// <summary>
        /// 以默认设置的模板创建文档
        /// </summary>
        /// <param name="sldWorks"><see cref="ISldWorks"/></param>
        /// <param name="type"><see cref="swDocumentTypes_e"/></param>
        /// <returns></returns>
        public static IModelDoc2 CreateDocument(this ISldWorks sldWorks, swDocumentTypes_e type)
        {
            string templatePath = string.Empty;

            switch (type)
            {
            case swDocumentTypes_e.swDocPART:
                templatePath = sldWorks.GetUserPreferenceStringValue((int)swUserPreferenceStringValue_e.swDefaultTemplatePart);
                break;

            case swDocumentTypes_e.swDocASSEMBLY:
                templatePath = sldWorks.GetUserPreferenceStringValue((int)swUserPreferenceStringValue_e.swDefaultTemplateAssembly);
                break;

            case swDocumentTypes_e.swDocDRAWING:
                templatePath = sldWorks.GetUserPreferenceStringValue((int)swUserPreferenceStringValue_e.swDefaultTemplateDrawing);
                break;

            default:
                break;
            }

            if (!File.Exists(templatePath))
            {
                templatePath =
                    Path.GetDirectoryName(templatePath) + "\\" +
                    Path.GetFileName(templatePath).
                    Replace("零件", "gb_part").
                    Replace("装配体", "gb_assembly").Replace("工程图", "gb_a1");
            }

            if (!File.Exists(templatePath))
            {
                throw new FileNotFoundException("无法找到SolidWorks文件--" + templatePath);
            }

            return(sldWorks.CreateDocument(templatePath));
        }
예제 #4
0
        public void CreateCube()
        {
            //make sure we have a part open
            string     partTemplate = iSwApp.GetUserPreferenceStringValue((int)swUserPreferenceStringValue_e.swDefaultTemplatePart);
            IModelDoc2 modDoc       = (IModelDoc2)iSwApp.NewDocument(partTemplate, (int)swDwgPaperSizes_e.swDwgPaperA2size, 0.0, 0.0);

            modDoc.InsertSketch2(true);
            modDoc.SketchRectangle(0, 0, 0, .1, .1, .1, false);
            //Extrude the sketch
            IFeatureManager featMan = modDoc.FeatureManager;

            featMan.FeatureExtrusion(true,
                                     false, false,
                                     (int)swEndConditions_e.swEndCondBlind, (int)swEndConditions_e.swEndCondBlind,
                                     0.1, 0.0,
                                     false, false,
                                     false, false,
                                     0.0, 0.0,
                                     false, false,
                                     false, false,
                                     true,
                                     false, false);
        }
예제 #5
0
        //create value body
        public void CreateCube()
        {
            valueBodyPpage = new ValueBodyPMPage(this);
            ShowValueBodyPMP();
            return;

            //make sure we have a part open
            string partTemplate = iSwApp.GetUserPreferenceStringValue((int)swUserPreferenceStringValue_e.swDefaultTemplatePart);

            if ((partTemplate != null) && (partTemplate != ""))
            {
                IModelDoc2 modDoc = (IModelDoc2)iSwApp.NewDocument(partTemplate, (int)swDwgPaperSizes_e.swDwgPaperA2size, 0.0, 0.0);
            }
            else
            {
                System.Windows.Forms.MessageBox.Show("There is no part template available. Please check your options and make sure there is a part template selected, or select a new part template.");
            }
        }
예제 #6
0
        public void OnClose(int reason)
        {
            //This function must contain code, even if it does nothing, to prevent the
            //.NET runtime environment from doing garbage collection at the wrong time.
            int IndentSize;

            IndentSize = System.Diagnostics.Debug.IndentSize;
            System.Diagnostics.Debug.WriteLine(IndentSize);

            if (reason == (int)swPropertyManagerPageCloseReasons_e.swPropertyManagerPageClose_Okay)
            {
                string partTemplate = iSwApp.GetUserPreferenceStringValue((int)swUserPreferenceStringValue_e.swDefaultTemplatePart);
                if ((partTemplate != null) && (partTemplate != ""))
                {
                    swModel = (ModelDoc2)iSwApp.NewDocument(partTemplate, (int)swDwgPaperSizes_e.swDwgPaperA2size, 0.0, 0.0);
                    swModel.InsertSketch2(true);
                    double x = this.activePage.CubeLength / ValueConst.factor;
                    double y = this.activePage.CubeWidth / ValueConst.factor;
                    double z = this.activePage.CubeHeight / ValueConst.factor;
                    swModel.SketchRectangle(0, 0, 0, x, y, 0, false);
                    //Extrude the sketch
                    IFeatureManager featMan   = swModel.FeatureManager;
                    Feature         valuebody = featMan.FeatureExtrusion(true,
                                                                         false, false,
                                                                         (int)swEndConditions_e.swEndCondBlind, (int)swEndConditions_e.swEndCondBlind,
                                                                         z, 0.0,
                                                                         false, false,
                                                                         false, false,
                                                                         0.0, 0.0,
                                                                         false, false,
                                                                         false, false,
                                                                         true,
                                                                         false, false);

                    //修改特征名称为:阀块基体
                    valuebody.Name = "阀块基体";
                }
                else
                {
                    System.Windows.Forms.MessageBox.Show("There is no part template available. Please check your options and make sure there is a part template selected, or select a new part template.");
                }
            }
        }
예제 #7
0
        public double Build(double width, double height, double length, out int totalModelsBuilt)
        {
            m_TotalModelsBuilt++;

            var templatePath = m_App.GetUserPreferenceStringValue((int)swUserPreferenceStringValue_e.swDefaultTemplatePart);

            var part = m_App.NewDocument(templatePath, (int)swDwgPaperSizes_e.swDwgPapersUserDefined, 0, 0) as IPartDoc;

            var box = m_App.IGetModeler().CreateBodyFromBox(
                new double[]
            {
                0, 0, 0,
                1, 0, 0,
                width, length, height
            });

            var feat = part.CreateFeatureFromBody3(box, false, (int)swCreateFeatureBodyOpts_e.swCreateFeatureBodySimplify);

            int errs  = -1;
            int warns = -1;

            var outPath = Path.Combine(m_BuildDir, $"{DateTime.Now.ToString("yyyy-MM-dd-hh-mm-ss")}.sldprt");

            var dir = Path.GetDirectoryName(outPath);

            if (!Directory.Exists(dir))
            {
                Directory.CreateDirectory(dir);
            }

            (part as IModelDoc2).Extension.SaveAs(outPath, (int)swSaveAsVersion_e.swSaveAsCurrentVersion,
                                                  (int)swSaveAsOptions_e.swSaveAsOptions_Silent, null, ref errs, ref warns);

            totalModelsBuilt = m_TotalModelsBuilt;

            var mass = (part as IModelDoc2).Extension.CreateMassProperty().Mass;

            m_App.CloseDoc((part as IModelDoc2).GetTitle());

            return(mass);
        }
예제 #8
0
        public static ModelDoc2 CreateHiddenDocument
            (this ISldWorks sldWorks, bool hidden = true, swDocumentTypes_e type = swDocumentTypes_e.swDocPART)
        {
            try
            {
                if (hidden)
                {
                    sldWorks.DocumentVisible(false, (int)type);
                }

                var partTemplateName = sldWorks.GetUserPreferenceStringValue((int)swUserPreferenceStringValue_e.swDefaultTemplatePart);
                var doc = (ModelDoc2)sldWorks.NewDocument(partTemplateName, (int)swDwgPaperSizes_e.swDwgPaperA4size, 1, 1);
                doc.Visible = false;

                /*
                 * ModelView myModelView = null;
                 * myModelView = ((ModelView)(doc.ActiveView));
                 * myModelView.FrameLeft = 0;
                 * myModelView.FrameTop = 0;
                 * myModelView = ((ModelView)(doc.ActiveView));
                 *
                 * myModelView.FrameState = ((int)(swWindowState_e.swWindowMinimized));
                 */
                return(doc);
            }
            finally
            {
                if (hidden)
                {
                    sldWorks.DocumentVisible
                        (true,
                        (int)
                        type);
                }
            }
        }
예제 #9
0
        public static void Create(ISldWorks app, ModelDoc2 mainModel)
        {
            string drawingTemplate = app.GetUserPreferenceStringValue((int)swUserPreferenceStringValue_e.swDefaultTemplateDrawing);
            ModelDoc2 designProject = app.NewDocument(drawingTemplate, (int)swDwgPaperSizes_e.swDwgPaperBsize, 0, 0);
            DrawingDoc designProjectDrawing = (DrawingDoc)designProject;
            int errors = 0;
            app.ActivateDoc2(designProject.GetTitle(), false, ref errors);
            designProjectDrawing.SetupSheet5("", (int)swDwgPaperSizes_e.swDwgPapersUserDefined, (int)swDwgTemplates_e.swDwgTemplateCustom, 1, 100, false, "a4 - iso.slddrt", 0.297, 0.21, "", true);
            var h = designProjectDrawing.CreateDrawViewFromModelView3(mainModel.GetPathName(), "*Изометрия", 0.1, 0.2, 0);

            List<OrderComponentData> orderData = new List<OrderComponentData>();

            object[] allComponents = ((AssemblyDoc)mainModel).GetComponents(true);
            foreach (Component2 component in allComponents)
            {
                ModelDoc2 currentModel = component.GetModelDoc2();
                string ip = GetCustomPropertyValue(currentModel, "IsProduct");
                if (ip == "Yes")
                {
                    orderData.Add(
                        new OrderComponentData()
                        {
                            Article = GetCustomPropertyValue(currentModel, "Articul"),
                            Name = GetCustomPropertyValue(currentModel, "Part_Name_spec"),
                            Width = GetCustomPropertyValue(currentModel, "Size1_spec"),
                            Depth = GetCustomPropertyValue(currentModel, "Size2_spec"),
                            Height = GetCustomPropertyValue(currentModel, "Size3_spec"),
                            Color1 = GetCustomPropertyValue(currentModel, "Color1"),
                            Color2 = GetCustomPropertyValue(currentModel, "Color2"),
                            Color3 = GetCustomPropertyValue(currentModel, "Color3"),
                            Color4 = GetCustomPropertyValue(currentModel, "Color4"),
                            Color5 = GetCustomPropertyValue(currentModel, "Color5"),
                            Color6 = GetCustomPropertyValue(currentModel, "Color6"),
                            Color7 = GetCustomPropertyValue(currentModel, "Color7")
                        });
                }
            }

            TableAnnotation table = designProjectDrawing.InsertTableAnnotation(0.01, 0.15, (int)swBOMConfigurationAnchorType_e.swBOMConfigurationAnchor_TopLeft, orderData.Count + 1, 14);
            table.BorderLineWeight = 0;
            table.GridLineWeight = 0;

            #region Заполнение заголовков колонок таблицы

            table.set_Text(0, 0, "Поз.");
            table.set_Text(0, 1, "Артикул");
            table.set_Text(0, 2, "Наименование изделия");
            table.set_Text(0, 3, "Ширина");
            table.set_Text(0, 4, "Глубина");
            table.set_Text(0, 5, "Высота");
            table.set_Text(0, 6, "Цвет 1");
            table.set_Text(0, 7, "Цвет 2");
            table.set_Text(0, 8, "Цвет 3");
            table.set_Text(0, 9, "Цвет 4");
            table.set_Text(0, 10, "Цвет 5");
            table.set_Text(0, 11, "Цвет 6");
            table.set_Text(0, 12, "Цвет 7");
            table.set_Text(0, 13, "Кол-во");

            #endregion

            int i = 1;
            foreach (OrderComponentData productData in orderData)
            {
                table.set_Text(i, 0, i.ToString());
                table.set_Text(i, 1, productData.Article);
                table.set_Text(i, 2, productData.Name);
                table.set_Text(i, 3, productData.Width);
                table.set_Text(i, 4, productData.Depth);
                table.set_Text(i, 5, productData.Height);
                table.set_Text(i, 6, productData.Color1);
                table.set_Text(i, 7, productData.Color2);
                table.set_Text(i, 8, productData.Color3);
                table.set_Text(i, 9, productData.Color4);
                table.set_Text(i, 10, productData.Color5);
                table.set_Text(i, 11, productData.Color6);
                table.set_Text(i, 12, productData.Color7);
                i++;
            }

            table.SetColumnWidth(0, 0.013, (int)swTableRowColSizeChangeBehavior_e.swTableRowColChange_TableSizeCanChange);
            table.SetColumnWidth(1, 0.025, (int)swTableRowColSizeChangeBehavior_e.swTableRowColChange_TableSizeCanChange);
            table.SetColumnWidth(2, 0.07, (int)swTableRowColSizeChangeBehavior_e.swTableRowColChange_TableSizeCanChange);

            for (int j = 3; j < 14; j++)
            {
                table.SetColumnWidth(j, 0.02, (int)swTableRowColSizeChangeBehavior_e.swTableRowColChange_TableSizeCanChange);
            }

            designProject.ViewZoomtofit2();
        }
        /// <summary>
        /// 后台创建文档
        /// </summary>
        /// <param name="sldWorks"></param>
        /// <param name="hidden"></param>
        /// <param name="type"></param>
        /// <returns></returns>
        public static ModelDoc2 CreateDocument
            (this ISldWorks sldWorks, bool hidden = true, swDocumentTypes_e type = swDocumentTypes_e.swDocPART)
        {
            try
            {
                if (hidden)
                {
                    sldWorks.DocumentVisible(false, (int)type);
                }

                string templatePath = string.Empty;

                switch (type)
                {
                case swDocumentTypes_e.swDocPART:
                    templatePath = sldWorks.GetUserPreferenceStringValue((int)swUserPreferenceStringValue_e.swDefaultTemplatePart);
                    break;

                case swDocumentTypes_e.swDocASSEMBLY:
                    templatePath = sldWorks.GetUserPreferenceStringValue((int)swUserPreferenceStringValue_e.swDefaultTemplateAssembly);
                    break;

                case swDocumentTypes_e.swDocDRAWING:
                    templatePath = sldWorks.GetUserPreferenceStringValue((int)swUserPreferenceStringValue_e.swDefaultTemplateDrawing);
                    break;

                default:
                    break;
                }

                if (string.IsNullOrEmpty(templatePath))
                {
                    throw new FileNotFoundException(string.Format("未找到此种类型的模板文件:{0}", type.ToString()));
                }

                if (!File.Exists(templatePath))
                {
                    templatePath =
                        Path.GetDirectoryName(templatePath) + "\\" +
                        Path.GetFileName(templatePath).
                        Replace("零件", "gb_part").
                        Replace("装配体", "gb_assembly").Replace("工程图", "gb_a1");
                }

                if (!File.Exists(templatePath))
                {
                    throw new FileNotFoundException("无法找到SolidWorks文件--" + templatePath);
                }

                //TODO:设置替换字符串
                var doc = (ModelDoc2)sldWorks.NewDocument(templatePath, (int)swDwgPaperSizes_e.swDwgPaperA4size, 1, 1);
                if (hidden)
                {
                    doc.Visible = false;
                    sldWorks.DocumentVisible(false, (int)type);
                }

                /*
                 * ModelView myModelView = null;
                 * myModelView = ((ModelView)(doc.ActiveView));
                 * myModelView.FrameLeft = 0;
                 * myModelView.FrameTop = 0;
                 * myModelView = ((ModelView)(doc.ActiveView));
                 *
                 * myModelView.FrameState = ((int)(swWindowState_e.swWindowMinimized));
                 */
                return(doc);
            }
            finally
            {
                if (hidden)
                {
                    sldWorks.DocumentVisible
                        (true,
                        (int)
                        type);
                }
            }
        }