Esempio n. 1
0
        private void OnClickVue(object sender, EventArgs e)
        {
            if (CurrentClickVue)
            {
                return;
            }

            try
            {
                if (DessinActif.IsNull() || (MdlActif.eSelect_Nb() == 0))
                {
                    return;
                }

                var typeSel = MdlActif.eSelect_RecupererSwTypeObjet();

                if (typeSel == swSelectType_e.swSelDRAWINGVIEWS)
                {
                    CurrentClickVue = true;

                    var vue = MdlActif.eSelect_RecupererObjet <SolidWorks.Interop.sldworks.View>();

                    if (BtParent.Checked)
                    {
                        vue.UseParentScale = true;
                    }
                    else if (BtFeuille.Checked)
                    {
                        vue.UseSheetScale = 1;
                    }
                    else if (BtPersonnalise.Checked)
                    {
                        var echelle = TextBoxVue.Text.Split(':');
                        if (echelle.Length == 2)
                        {
                            var e1 = echelle[0].eToDouble();
                            var e2 = echelle[1].eToDouble();
                            if (e1 > 0 && e2 > 0)
                            {
                                vue.ScaleRatio = new Double[] { e1, e2 };
                                //vue.ScaleDecimal = e1 / e2;
                                MdlActif.ForceRebuild3(true);
                                MdlActif.EditRebuild3();
                                MdlActif.GraphicsRedraw2();
                            }
                        }
                    }

                    vue.eSelectionner(DessinActif);

                    CurrentClickVue = false;
                }
            }
            catch
            {
                ReinitialiserVue();
            }
        }
Esempio n. 2
0
        private void button1_Click(object sender, EventArgs e)
        {
            ISldWorks sldWorks  = Utility.ConnectToSolidWorks();
            ModelDoc2 modelDoc  = (ModelDoc2)sldWorks.ActiveDoc;
            ModelView modelView = (ModelView)modelDoc.ActiveView;

            // modelDoc.ViewZoomtofit2();
            modelView.Scale2 = double.Parse(txtSC.Text);

            modelDoc.GraphicsRedraw2();
        }
Esempio n. 3
0
 private static void DrawDottedLine(ModelDoc2 swModel, Entity ent1, Entity ent2)
 {
     swModel.SetAddToDB(true);
     if (ent1 != null && ent2 != null)
     {
         swModel.SketchManager.CreateCenterLine(1, 1, 0, 1.1, 1.1, 0);
         var objPoints = (object[])swModel.SketchManager.ActiveSketch.GetSketchPoints();
         SketchPoint swPoint1 = null, swPoint2 = null;
         foreach (var objPoint in objPoints)
         {
             var swPoint = (SketchPoint)objPoint;
             double x1 = 1 - swPoint.X;
             double x2 = 1.1 - swPoint.X;
             double y1 = 1 - swPoint.Y;
             double y2 = 1.1 - swPoint.Y;
             if (x1 < 0)
                 x1 = -x1;
             if (x2 < 0)
                 x2 = -x2;
             if (y1 < 0)
                 y1 = -y1;
             if (y2 < 0)
                 y2 = -y2;
             if (x1 < 0.0001 && y1 < 0.0001)
             {
                 swPoint1 = swPoint;
             }
             if (x2 < 0.0001 && y2 < 0.0001)
             {
                 swPoint2 = swPoint;
             }
         }
         if (swPoint1 != null && swPoint2 != null)
         {
             if (swPoint1.Select(false) && ent1.Select(true))
             {
                 swModel.SketchAddConstraints("sgCONCENTRIC");
             }
             if (swPoint2.Select(false) && ent2.Select(true))
             {
                 swModel.SketchAddConstraints("sgCONCENTRIC");
             }
         }
     }
     swModel.SetAddToDB(false);
     swModel.GraphicsRedraw2();
     swModel.ClearSelection();
     //swModel.ClearUndoList();
 }
        public void CmdRevMethod(bool m)
        {
            try
            {
                if (m & string.IsNullOrEmpty(TxtBox.Text))
                {
                    MessageBox.Show("Введите номер извещения.");
                    return;
                }

                for (var i = 0; i <= _vSheetNames.GetUpperBound(0); i++)
                {
                    //TODO: _swNote

                    //ok = _swDraw.ActivateSheet(_vSheetNames[i]);
                    _swDraw.ActivateSheet(_vSheetNames[i]);
                    _swSheet            = _swDraw.GetCurrentSheet();
                    _strSheetFormatName = _swSheet.GetSheetFormatName();

                    _swModel = (ModelDoc2)_swDraw;

                    _swSelMgr = _swModel.SelectionManager;

                    //MessageBox.Show(_swSelMgr.ToString());
                    // Дата
                    StrTempData = "Revision4@" + _strSheetFormatName;
                    ok          = _swModel.Extension.SelectByID2(StrTempData, "NOTE", 0, 0, 0, false, 0, null, 0);

                    if (ok)
                    {
                        _swNote = _swSelMgr.GetSelectedObject2(1);

                        //MessageBox.Show(_swNote.ToString());
                        if (m)
                        {
                            var date = (DateTime)StrData.SelectedDate;
                            StrTempData = Convert.ToString(date.ToString("dd-MM-yy"));
                            _swNote.SetText(StrTempData);
                        }
                        else
                        {
                            //MessageBox.Show(StrTempData);
                            StrTempData = _swNote.GetText();

                            if (StrTempData == "" | StrTempData == " ")
                            {
                                StrData.SelectedDate = (DateTime.Today);
                            }
                            else
                            {
                                StrData.SelectedDate = Convert.ToDateTime(StrTempData);
                            }
                        }
                    }

                    // Номер
                    StrTempNumber = "Revision3@" + _strSheetFormatName;
                    _swModel.Extension.SelectByID2(StrTempNumber, "NOTE", 0, 0, 0, false, 0, null, 0);

                    if (ok)
                    {
                        _swNote = _swSelMgr.GetSelectedObject2(1);

                        if (m)
                        {
                            StrTempNumber = "ИКД-" + TxtBox.Text;
                            _swNote.SetText(StrTempNumber);
                        }
                        else
                        {
                            StrTempNumber = _swNote.GetText();
                            if (StrTempNumber != " ")
                            {
                                TxtBox.Text = StrTempNumber.Substring(4);
                            }
                        }
                    }

                    // Зам.
                    _strTemp = "Revision2@" + _strSheetFormatName;
                    _swModel.Extension.SelectByID2(_strTemp, "NOTE", 0, 0, 0, false, 0, null, 0);


                    if (ok)
                    {
                        _swNote = _swSelMgr.GetSelectedObject2(1);


                        if (m)
                        {
                            if (Rb1.IsChecked == true)
                            {
                                _swNote.SetText("Зам.");
                                _swModel.DeleteCustomInfo2("", "Revision");
                            }

                            if (Rb3.IsChecked == true)
                            {
                                _swNote.SetText("Нов.");
                                _swModel.DeleteCustomInfo2("", "Revision");
                            }

                            if (Rb2.IsChecked == true)
                            {
                                _swNote.SetText("Змін.");
                                _swModel.DeleteCustomInfo2("", "Revision");
                                _swModel.AddCustomInfo3("", "Revision", 30, "");
                                _swModel.CustomInfo2["", "Revision"] = Convert.ToString(SpinButton.Content);
                            }
                        }
                        else
                        {
                            _strTemp = _swNote.GetText();

                            if (_strTemp == "Зам.")
                            {
                                Rb1.IsChecked        = true;
                                Rb3.IsChecked        = false;
                                Rb2.IsChecked        = false;
                                SpinButton.IsEnabled = false;
                            }

                            if (_strTemp == "Нов.")
                            {
                                Rb1.IsChecked        = false;
                                Rb3.IsChecked        = true;
                                Rb2.IsChecked        = false;
                                SpinButton.IsEnabled = false;
                            }

                            if (_strTemp == "Змін.")
                            {
                                Rb1.IsChecked        = false;
                                Rb3.IsChecked        = false;
                                Rb2.IsChecked        = true;
                                SpinButton.IsEnabled = true;
                            }

                            int  n;
                            bool isNumeric = int.TryParse(_swModel.CustomInfo2["", "Revision"], out n);

                            if (isNumeric)
                            {
                                SpinButton.Content = _swModel.CustomInfo2["", "Revision"];
                            }
                            else
                            {
                                _swModel.DeleteCustomInfo2("", "Revision");
                            }
                        }
                    }
                }

                // Возвращение активного листа
                _swDraw.ActivateSheet(_strActiveSheetName);

                // Перестраиваем чертеж
                _swModel.ForceRebuild3(false);

                _swModel.GraphicsRedraw2();
                _swModel.ClearSelection2(true);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + "; " + ex.StackTrace);
            }
        }
Esempio n. 5
0
        private void buttonAuto_Click(object sender, EventArgs e)
        {
            //新建一个零件  ,画一条150长度的直线,然后最大化.

            ISldWorks iswApp = Utility.ConnectToSolidWorks();

            string partDefaultPath = iswApp.GetDocumentTemplate(1, "", 0, 0, 0);

            var part = iswApp.NewDocument(partDefaultPath, 0, 0, 0);

            ModelDoc2 modelDoc = (ModelDoc2)iswApp.ActiveDoc;

            modelDoc.Extension.SelectByID2("Plane1", "PLANE", 0, 0, 0, false, 0, null, 0);

            modelDoc.SketchManager.InsertSketch(true);

            modelDoc.SketchManager.CreateLine(0, 0.1, 0, 0, 0, 0);

            modelDoc.SketchManager.InsertSketch(true);

            modelDoc.ClearSelection2(true);

            modelDoc.Extension.SelectByID2("Sketch1", "SKETCH", 0, 0, 0, false, 1, null, 0);

            var b = modelDoc.InsertCompositeCurve();

            modelDoc.ClearSelection2(true);

            modelDoc.FeatureManager.ViewFeatures = false;

            modelDoc.ViewZoomtofit2();

            ModelView modelView = (ModelView)modelDoc.ActiveView;

            iswApp.FrameState = 1; //最大化solidworks
            modelDoc.ViewZoomtofit2();
            modelView.Scale2 = 0.5;

            //

            modelDoc.ClearSelection2(true);

            string ImagePath = @"D:\temp.JPG";

            modelDoc.SaveAs3(ImagePath, 0, 0);

            int LineInImage = img2color(ImagePath);

            try
            {
                System.IO.File.Delete(ImagePath);
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception);
            }

            if (LineInImage > 0)
            {
                double ActionScreenHeight = double.Parse(txtSCHeight.Text); //GetScreenRealWeight(double.Parse( textScreenSize.Text));

                //当前视图的比例
                double ActionScale = modelView.Scale2;

                //solidworks中的直线占比
                double defaultSolidworksP = LineInImage / 1200.0;//double.Parse(txtScreenY.Text);

                //当前比例下 1像素  等于多少mm
                double thisSc = 100 / LineInImage;

                //实际屏幕 1 像素尺寸

                double oneP = (ActionScreenHeight) / 1200.0;

                //当比例设置为 1时 1像素能表示的长度:
                double onePshowLength = thisSc / ActionScale;

                //959  1370

                GetWindowsSize getWindowSize = new GetWindowsSize();

                GetWindowsSize.windsize solidworksize = getWindowSize.GetSize("SLDWORKS");

                double getSC = 50.0 / (LineInImage * oneP);

                txtSC.Text = getSC.ToString();// getSC.ToString();

                modelView.Scale2 = getSC;

                modelDoc.GraphicsRedraw2();

                Debug.Print(getSC.ToString());
                // modelView.Scale2 = double.Parse(txtSC.Text);
                // sldWorks.scen
            }

            iswApp.CloseDoc(modelDoc.GetPathName());
        }