コード例 #1
0
        //                                                     DOCUMENT


        void NewPart()
        {
            sw.NewDocument(@"C:\ProgramData\SOLIDWORKS\SOLIDWORKS 2016\templates\Деталь.prtdot", 0, 0, 0);
            sw.ActivateDoc("");
            Model = sw.ActiveDoc;
            Model.SaveAs3(ApplicationPath + "temp_part" + ".SLDPRT", 0, 0);
            PlaneTop(0); name("Y");
            PlaneRight(0); name("X");
            PlaneFront(0); name("Z");
        }
コード例 #2
0
        /// <summary>
        /// 激活指定文档
        /// </summary>
        /// <returns></returns>
        public static ModelDoc2 ActiveDoc(string filename)
        {
            StartSW();
            ModelDoc2 swDoc = swApp.ActivateDoc(filename);

            return(swDoc);
        }
コード例 #3
0
                public static void Add(SldWorks swApp, ModelDoc2 parentDoc)
                {
                    swApp.ActivateDoc(parentDoc.GetTitle());
                    var configuration = ((Configuration)parentDoc.GetActiveConfiguration()).Name;
                    var swCustProp    = parentDoc.Extension.CustomPropertyManager[configuration];

                    AddProperty(swCustProp, new KeyValuePair <string, string> ("Наименование", "Новое наименование"));
                }
コード例 #4
0
                public static void AddAll(SldWorks swApp, ModelDoc2 parentDoc, List <KeyValuePair <string, string> > properties)
                {
                    swApp.ActivateDoc(parentDoc.GetTitle());
                    var configuration = ((Configuration)parentDoc.GetActiveConfiguration()).Name;
                    var swCustProp    = parentDoc.Extension.CustomPropertyManager[configuration];

                    foreach (var property in properties)
                    {
                        AddProperty(swCustProp, property);
                    }
                }
コード例 #5
0
                public static List <KeyValuePair <string, string> > GetAll(SldWorks swApp, ModelDoc2 childDoc, string configuration)
                {
                    swApp.ActivateDoc(childDoc.GetTitle());
                    var swCustProp = childDoc.Extension.CustomPropertyManager[configuration];
                    var list       = new List <KeyValuePair <string, string> >();

                    foreach (var item in Properties)
                    {
                        list.Add(new KeyValuePair <string, string>(item.Key, GetProperty(swCustProp, item.Key)));
                    }
                    swApp.CloseDoc(Path.GetFileName(childDoc.GetPathName()));
                    return(list);
                }
コード例 #6
0
                public static void AddAll(SldWorks swApp, ModelDoc2 parentDoc, List <KeyValuePair <string, string> > properties)
                {
                    swApp.ActivateDoc(parentDoc.GetTitle());
                    var configuration = ((Configuration)parentDoc.GetActiveConfiguration()).Name;

                    MessageBox.Show("configuration - " + configuration);
                    var swCustProp = parentDoc.Extension.CustomPropertyManager[configuration];

                    foreach (var property in properties)
                    {
                        MessageBox.Show(property.Key + " - " + property.Value, "Свойство для добавления");
                        AddProperty(swCustProp, property);
                    }
                }
コード例 #7
0
                public static PartProperties Get(SldWorks swApp, ModelDoc2 childDoc, string configuration)
                {
                    swApp.ActivateDoc(childDoc.GetTitle());
                    var swCustProp = childDoc.Extension.CustomPropertyManager[configuration];

                    var configProps = new PartProperties
                    {
                        Config       = configuration,
                        Наименование = GetProperty(swCustProp, "Наименование"),
                        Обозначение  = GetProperty(swCustProp, "Обозначение"),
                        Материал     = GetProperty(swCustProp, "Материал"),
                    };

                    return(configProps);
                }
コード例 #8
0
        public TabletModelInformation()
        {
            string hobNumber = ((ModelDoc2)sldWorks.ActiveDoc).GetType() == (int)swDocumentTypes_e.swDocPART ?
                               ((ModelDoc2)sldWorks.ActiveDoc).GetTitle() :
                               ((ModelDoc2)sldWorks.ActiveDoc).GetTitle().Remove(((ModelDoc2)sldWorks.ActiveDoc).GetTitle().IndexOf(' '));

            HobNumber = hobNumber;
            string    modelPath = GetTabletPath(hobNumber) + ".SLDPRT";
            ModelDoc2 tablet    = (ModelDoc2)sldWorks.OpenDoc(modelPath, (int)swDocumentTypes_e.swDocPART);

            if (tablet is null)
            {
                tablet = (ModelDoc2)sldWorks.ActivateDoc(hobNumber);
            }
            CustomPropertyManager cpmTablet = (CustomPropertyManager)tablet.Extension.CustomPropertyManager[""];

            GetDieNumber(tablet, cpmTablet);
            GetSize(tablet);
            sldWorks.CloseDoc(HobNumber);
        }
コード例 #9
0
        /// <summary>
        /// The entry point of the program.
        /// </summary>
        public void Main()
        {
            /* Acquiring current document (with solid) */
            ModelDoc2 swModel = (ModelDoc2)swApp.ActivateDoc("Cone.SLDPRT");

            /* Tessetalion (getting all solid's triangles) */
            TessellationHelper tesselation = new TessellationHelper(swApp, swModel);
            List <Segment>     segments    = tesselation.Tessellate();

            /* Creating levels */
            LevelManager levelManager = new LevelManager();

            levelManager.CreateLevels(segments);

            /* Calculating gradient curve */
            GradientCurve gradientCurve = new GradientCurve();

            gradientCurve.Make(levelManager.GetLevels(), swModel);

            /* Drawing calculated curve and levels */
            gradientCurve.Draw(swModel);
            gradientCurve.DrawLevels(swModel, levelManager.GetLevels());
        }
コード例 #10
0
 private PartService()
 {
     sldApp         = new SldWorks();
     sldApp.Visible = true;
     ModelDoc model = sldApp.ActivateDoc("") as ModelDoc;
 }
コード例 #11
0
        // Set Materials
        public void ApplyMaterial(string partPath, string confName, int levelId, SldWorks swapp)
        {
            try
            {
                if (swapp == null)
                {
                    if (partPath == "")
                    {
                        swapp    = (SldWorks)Marshal.GetActiveObject("SldWorks.Application");
                        _swmodel = swapp.ActiveDoc;
                    }
                    else
                    {
                        swapp = new SldWorks {
                            Visible = true
                        };
                        swapp.OpenDoc6(partPath, (int)swDocumentTypes_e.swDocASSEMBLY, (int)swOpenDocOptions_e.swOpenDocOptions_LoadModel, confName, 0, 0);
                        _swmodel = swapp.ActivateDoc(partPath);
                        _swmodel = swapp.ActiveDoc;
                    }
                }
                else
                {
                    if (partPath == "")
                    {
                        _swmodel = swapp.ActiveDoc;
                    }
                    else
                    {
                        //swapp = new SldWorks { Visible = true };
                        swapp.OpenDoc6(partPath, (int)swDocumentTypes_e.swDocASSEMBLY, (int)swOpenDocOptions_e.swOpenDocOptions_LoadModel, confName, 0, 0);
                        _swmodel = swapp.ActivateDoc(partPath);
                        _swmodel = swapp.ActiveDoc;
                    }
                }


                // Путь к APPDATA
                var userAppData = System.Environment.GetFolderPath(System.Environment.SpecialFolder.ApplicationData);
                // Создаем папку SW-Complex
                var folderAppData = userAppData + "\\" + "SW-Complex";

                //if (File.Exists(folderAppData) == false)
                //{
                Directory.CreateDirectory(folderAppData);
                //}

                swapp.SetUserPreferenceStringValue((int)swUserPreferenceStringValue_e.swFileLocationsMaterialDatabases, folderAppData);     // задаем базы данных материалов
                //swapp.SetUserPreferenceStringValue((int)swUserPreferenceStringValue_e.swFileLocationsMaterialDatabases, "C:\\Program Files\\SW-Complex"); // задаем базы данных материалов

                _swPartDoc = ((PartDoc)(_swmodel));

                var dbMatName = "vents-materials.sldmat";

                var addMatXml = new ToSQL();

                if (_swmodel.GetType() == (int)swDocumentTypes_e.swDocASSEMBLY)
                {
                    _swmodel.ForceRebuild3(false);
                    Component2 comp        = _swmodel.ISelectionManager.GetSelectedObject3(1);
                    PartDoc    swPartAssem = comp.GetModelDoc();

                    //// удаляем материал
                    //swPartAssem.SetMaterialPropertyName("", "");

                    // применяем материал
                    swPartAssem.SetMaterialPropertyName2(confName, dbMatName, addMatXml.AddMaterialtoXml(levelId));
                    _swmodel.ClearSelection2(true);
                    _swmodel.ForceRebuild3(false);
                }
                else if (_swmodel.GetType() == (int)swDocumentTypes_e.swDocPART)
                {
                    // Если имя не пустое
                    if (partPath != "")
                    {
                        //// удаляем материал
                        //swPartDoc.SetMaterialPropertyName("", "");

                        // применяем материал
                        _swPartDoc.SetMaterialPropertyName2(confName, dbMatName, addMatXml.AddMaterialtoXml(levelId));

                        _swmodel.ForceRebuild3(false);
                        _swmodel.Save3((int)swSaveAsOptions_e.swSaveAsOptions_Silent, 0, 0);
                        swapp.CloseDoc(partPath);
                        swapp.ExitApp();
                        swapp = null;
                    }
                    else
                    {
                        //// удаляем материал
                        //swPartDoc.SetMaterialPropertyName(confName, "");

                        // применяем материал
                        _swPartDoc.SetMaterialPropertyName2(confName, dbMatName, addMatXml.AddMaterialtoXml(levelId));
                    }
                }
            }
            catch (Exception ex)
            {
                //swapp.SendMsgToUser(ex.Message);
                MessageBox.Show(ex.Message + ";" + ex.StackTrace);
                Error = ex.Message;
            }
        }