Пример #1
0
        public View GetFirstView(SldWorks sw)
        {
            ModelDoc2  swModel = (ModelDoc2)sw.ActiveDoc;
            DrawingDoc d       = (DrawingDoc)swModel;
            View       v;

            string[] shtNames = (String[])swDraw.GetSheetNames();
            string   message  = string.Empty;

            //This should find the first page with something on it.
            IsTarget = IsTargetDrawing((sw.ActiveDoc as DrawingDoc).Sheet[shtNames[0]]);
            int x = 0;

            do
            {
                try {
                    d.ActivateSheet(shtNames[x]);
                } catch (IndexOutOfRangeException e) {
                    throw new IndexOutOfRangeException("Went beyond the number of sheets.", e);
                } catch (Exception e) {
                    throw e;
                }
                v = (View)d.GetFirstView();
                v = (View)v.GetNextView();
                x++;
            } while ((v == null) && (x < d.GetSheetCount()));

            message = (string)v.GetName2() + ":\n";

            if (v == null)
            {
                throw new Exception("I couldn't find a model anywhere in this document.");
            }
            return(v);
        }
Пример #2
0
        public static void GetSolidObject()
        {
            swApp   = (SldWorks)Marshal.GetActiveObject("SldWorks.Application");
            swModel = swApp.ActiveDoc;

            // Проверка открытого документа
            if (swModel == null)
            {
                swApp.SendMsgToUser2("Откройте модель, сборку или чертеж!", (int)swMessageBoxIcon_e.swMbStop, (int)swMessageBoxBtn_e.swMbOk);

                return;
            }

            if (string.IsNullOrEmpty(swModel.GetPathName()))
            {
                swApp.SendMsgToUser2("Сохраните файл!", (int)swMessageBoxIcon_e.swMbStop, (int)swMessageBoxBtn_e.swMbOk);

                return;
            }

            docType = (swDocumentTypes_e)swModel.GetType();


            if (docType != swDocumentTypes_e.swDocDRAWING)
            {
                configName           = swModel.GetActiveConfiguration().Name;//при первом вызове присваеваеться активная конфигурация
                EditProp.configNames = EditProp.GetAllConfigurations();
            }
            else
            {
                #region Если открыт чертеж

                lockForConf = true;//нельзя изменить конфигурацию на формочке

                drw = (DrawingDoc)swModel;
                // Получение первого листа
                Sheet swSheet = drw.GetCurrentSheet();

                Propertiy.Format = GetFormat(swSheet);
                Propertiy.Sheets = drw.GetSheetCount().ToString();
                Propertiy.Sheet  = swSheet.GetName();
                // Узнаем имя активного листа
                string[] vSheetNames = drw.GetSheetNames();
                drw.ActivateSheet(vSheetNames[0]);
                swSheet         = drw.GetCurrentSheet();
                swView          = drw.GetFirstView();
                Propertiy.Scale = swView.ScaleRatio[0].ToString() + ":" + swView.ScaleRatio[1].ToString();

                m = 0;

                if (swSheet.CustomPropertyView == "По умолчанию" | swSheet.CustomPropertyView == "Default")
                {
                    // Получаем первый вид
                    swView = swView.GetNextView();
                }
                else
                {
                    while (swView != null)
                    {
                        if (swView.GetName2() == swSheet.CustomPropertyView)
                        {
                            m = 1;
                        }
                        swView = swView.GetNextView();
                    }
                    if (m == 0)
                    {
                        swView = drw.GetFirstView();
                        swView = swView.GetNextView();
                        swApp.SendMsgToUser2("Не удалось определить вид из свойств листа. Ипользуется первый вид.", (int)swMessageBoxIcon_e.swMbStop, (int)swMessageBoxBtn_e.swMbOk);
                    }
                }

                if (swView == null)
                {
                    swApp.SendMsgToUser2("Отсутсвует модель!", (int)swMessageBoxIcon_e.swMbStop, (int)swMessageBoxBtn_e.swMbOk);
                    // Возвращение активного листа
                    drw.ActivateSheet(Propertiy.Sheet);
                    return;
                }

                if (swView.ReferencedDocument == null)
                {
                    swApp.SendMsgToUser2("Отсутсвует модель!", (int)swMessageBoxIcon_e.swMbStop, (int)swMessageBoxBtn_e.swMbOk);
                    // Возвращение активного листа
                    drw.ActivateSheet(Propertiy.Sheet);
                    return;
                }
                #endregion
            }
        }
Пример #3
0
        public void CheckAndUpdateGaugeNotes2()
        {
            String currPage = swDraw.GetCurrentSheet().ToString();
            Int32  shtCount = swDraw.GetSheetCount();

            String[] shtName = (String[])swDraw.GetSheetNames();

            for (int page = 0; page < shtCount; page++)
            {
                swFrame.SetStatusBarText(String.Format("Activating page {0}...", shtName[page]));
                swDraw.ActivateSheet(shtName[page]);
                swView = (View)swDraw.GetFirstView();

                while (swView != null)
                {
                    swDispDim = swView.GetFirstDisplayDimension5();

                    while (swDispDim != null)
                    {
                        swDim = (Dimension)swDispDim.GetDimension2(0);
                        swFrame.SetStatusBarText(String.Format("Processing '{0}' => '{1}'...", swDim.Name, swDim.Value.ToString()));
                        string dimtext = swDispDim.GetText((Int32)swDimensionTextParts_e.swDimensionTextCalloutBelow);
                        dimtext = dimtext.Replace(@"(", string.Empty).Replace(@")", string.Empty).Trim();
                        if (gaugeRegex.IsMatch(dimtext))
                        {
                            string[] texts_ = dimtext.Split(' ');
                            gaugeNote = Regex.Replace(texts_[texts_.Length - 1], "[0-9]", string.Empty);
                            Double og;
                            if (!Double.TryParse(swDim.GetSystemValue2("").ToString(), out og))
                            {
                                throw new GaugeSetterException("Couldn't parse dimension value.");
                            }
                            ourGauge = og / 0.0254;

                            for (int i = 0; i < Gauges.Gauge.Length; i++)
                            {
                                Double dCellVal;

                                if (!Double.TryParse(Gauges.Gauge[i].Thickness, out dCellVal))
                                {
                                    throw new GaugeSetterException("Couldn't parse gauge thickness.");
                                }
                                else

                                if (Math.Abs(ourGauge - dCellVal) < 0.00003)
                                {
                                    String gaugeCell   = String.Empty;
                                    String gaugeString = String.Empty;
                                    gaugeNotFound = false;

                                    swDispDim.ShowParenthesis = true;
                                    gaugeString = String.Format("{0} {1}", Gauges.Gauge[i].GaugeNumber, gaugeNote.ToUpper());
                                    swDispDim.SetText((int)swDimensionTextParts_e.swDimensionTextCalloutBelow, gaugeString);
                                }
                            }
                            if (gaugeNotFound)
                            {
                                if (!APathSet.SilenceGaugeErrors)
                                {
                                    StringBuilder sb = new StringBuilder("Non-standard gauge thickness detected:\n");
                                    sb.AppendFormat(get_format_txt(), swDim.Name, swView.Name, ourGauge);
                                    swApp.SendMsgToUser2(sb.ToString()
                                                         , (int)swMessageBoxIcon_e.swMbWarning
                                                         , (int)swMessageBoxBtn_e.swMbOk);
                                }
                                gaugeNotFound = false;
                            }
                        }
                        swDispDim = swDispDim.GetNext5();
                    }
                    swView = (View)swView.GetNextView();
                }
            }
            swDraw.ActivateSheet(currPage);

            if (gaugeNotFound)               // Why waste time rebuilding?
            {
                swFrame.SetStatusBarText("Rebuilding");
                swDraw.ForceRebuild();
            }
            swFrame.SetStatusBarText(String.Empty);
        }