Пример #1
0
        public Tekla() { } // конструктор класса Tekla - пока пустой 6.4.17

        public List<Elm> Read(string dir = "", string name = "")
        {
            Log.set("TS_OpenAPI.Read");
            List<Elm> elements = new List<Elm>();
            // 6.4.17 //TSM.Model model = new TSM.Model();
            ////////////List<Part> parts = new List<Part>();
            ModInfo = model.GetInfo();
            if (dir != "" && ModInfo.ModelPath != dir
                || name != "" && ModInfo.ModelName != String.Concat(name, ".db1")) Msg.F("Tekla.Read: Another model loaded, not", name);
            ModInfo.ModelName = ModInfo.ModelName.Replace(".db1", "");
            TSM.ModelObjectSelector selector = model.GetModelObjectSelector();
            System.Type[] Types = new System.Type[1];
            Types.SetValue(typeof(Part), 0);

            TSM.ModelObjectEnumerator objectList = selector.GetAllObjectsWithType(Types);
            int totalCnt = objectList.GetSize();
            var progress = new TSM.Operations.Operation.ProgressBar();
            bool displayResult = progress.Display(100, "TSmatch", "Reading model. Pass component records:", "Cancel", " ");
            int ii = 0;
            while (objectList.MoveNext())
            {
                TSM.Part myPart = objectList.Current as TSM.Part;
                if (myPart != null)
                {
                    ii++;
                    double lng = 0.0;
                    double weight = 0.0;
                    double vol = 0.0;
                    string guid = "";
                    string mat_type = "";
                    double price = 0.0;

                    myPart.GetReportProperty("GUID", ref guid);
                    myPart.GetReportProperty("LENGTH", ref lng);
                    myPart.GetReportProperty("WEIGHT", ref weight);
                    myPart.GetReportProperty("VOLUME", ref vol);
                    myPart.GetReportProperty("MATERIAL_TYPE", ref mat_type);

                    lng = Math.Round(lng, 0);
                    //string cut = "";
                    //myPart.GetReportProperty("CAST_UNIT_TYPE", ref cut);
                    //ModAtr.Add(new AttSet(myPart.Material.MaterialString,
                    //                      profile, lng, weight, vol));
                    //21/6/2016 в отладке                    Elm.Elements.Add(new Elm());
                    elements.Add(new Elm(guid, myPart.Material.MaterialString,
                        mat_type,
                        myPart.Profile.ProfileString,
                        lng, weight, vol, price));
 // !!                  if (ii % 500 == 0) // progress update every 500th items
                    {
                        if (progress.Canceled())
                        {
//                            new Log("\n\n======= TSmatch pass model CANCEL!! =======  ii=" + ii);
//                            TSD.Show()
                            break;
                        }
                        progress.SetProgress(ii.ToString(), 100 * ii / totalCnt);
                    }
                }
            } //while
            progress.Close();
            Scale(elements);
            elements.Sort();
            Log.exit();
            return elements;
        } // Read
        public override bool Run(List <InputDefinition> Input)
        {
            GetValuesFromDialog();
            int succesfulModified = 0;

            var selectedDrawings = new Tekla.Structures.Drawing.DrawingHandler().GetDrawingSelector().GetSelected();
            var drawingsCount    = selectedDrawings.GetSize();

            if (drawingsCount == 0)
            {
                MessageBox.Show("No drawings selected", "No drawings", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(false);
            }

            DialogResult result = MessageBox.Show(
                "Are you sure do you want to change attributes in " + selectedDrawings.GetSize() + " drawings?",
                "Are you sure ?",
                MessageBoxButtons.YesNo,
                MessageBoxIcon.Question,
                MessageBoxDefaultButton.Button2
                );

            if (result == DialogResult.Yes)
            {
                var progress = new Tekla.Structures.Model.Operations.Operation.ProgressBar();

                var stopwatch = new System.Diagnostics.Stopwatch();
                try
                {
                    progress.Display(10, "Task is in progress", "Task is in progress", "Cancel", " ");
                    stopwatch.Start();
                    int    checkedDrawings = 0;
                    double medTimeForOne   = 0;

                    while (selectedDrawings.MoveNext())
                    {
                        if (progress.Canceled())
                        {
                            break;
                        }

                        var  currentDrawing = selectedDrawings.Current as Tekla.Structures.Drawing.Drawing;
                        bool modified       = false;

                        switch (_Title)
                        {
                        case (0):
                            if (currentDrawing.Name != currentDrawing.Name.Replace(_Find, _Replace))
                            {
                                currentDrawing.Name = currentDrawing.Name.Replace(_Find, _Replace);
                                modified            = true;
                            }
                            break;

                        case (1):
                            if (currentDrawing.Title1 != currentDrawing.Title1.Replace(_Find, _Replace))
                            {
                                currentDrawing.Title1 = currentDrawing.Title1.Replace(_Find, _Replace);
                                modified = true;
                            }
                            break;

                        case (2):
                            if (currentDrawing.Title2 != currentDrawing.Title2.Replace(_Find, _Replace))
                            {
                                currentDrawing.Title2 = currentDrawing.Title2.Replace(_Find, _Replace);
                                modified = true;
                            }
                            break;

                        case (3):
                            if (currentDrawing.Title3 != currentDrawing.Title3.Replace(_Find, _Replace))
                            {
                                currentDrawing.Title3 = currentDrawing.Title3.Replace(_Find, _Replace);
                                modified = true;
                            }
                            break;

                        default:
                            try
                            {
                                var udaHandler = new UDAHandler();
                                var udaName    = udaHandler.GetUDAByIndex(_Title - 4);

                                if (udaName != "")
                                {
                                    //I dont want to change other types than string because it might be wrong
                                    string udaStringValue = "";
                                    if (currentDrawing.GetUserProperty(udaName, ref udaStringValue))
                                    {
                                        if (udaStringValue != udaStringValue.Replace(_Find, _Replace))
                                        {
                                            modified = currentDrawing.SetUserProperty(udaName, udaStringValue.Replace(_Find, _Replace));
                                        }
                                    }
                                }
                            }
                            catch (Exception) { }
                            break;
                        }

                        if (modified)
                        {
                            currentDrawing.Modify();
                            succesfulModified++;
                        }
                        checkedDrawings++;
                        medTimeForOne = stopwatch.Elapsed.TotalMinutes / checkedDrawings;
                        progress.SetProgress(checkedDrawings + "/" + drawingsCount + "\t" + Math.Round(medTimeForOne * (drawingsCount - checkedDrawings)) + " minutes left", 100 * checkedDrawings / drawingsCount);
                    }
                }
                catch (Exception e)
                {
                    MessageBox.Show(e.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                finally
                {
                    progress.Close();
                    stopwatch.Stop();
                    MessageBox.Show("Task has been completed.\nModified drawings: " + succesfulModified.ToString() + ".\nTime elapsed: " + Math.Round(stopwatch.Elapsed.TotalSeconds).ToString() + " seconds");
                }
            }
            return(true);
        }