Esempio n. 1
0
        // to work in Visual Studio uncomment next line:
        public static void Main()
        // to use this code as Tekla macro uncomment next line:
        //public static void Run(Tekla.Technology.Akit.IScript akit)
        {
            ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            // Settings

            ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

            Model Model = new Model();

            // select object types for selector
            System.Type[] Types = new System.Type[2];
            Types.SetValue(typeof(Beam), 0);
            Types.SetValue(typeof(ContourPlate), 1);

            // instantiate model object enumerator before if clauses
            Tekla.Structures.Model.ModelObjectEnumerator SelectedObjects = Model.GetModelObjectSelector().GetAllObjectsWithType(ModelObject.ModelObjectEnum.UNKNOWN);
            // =======================================================================================
            // dialog for object selection
            DialogResult dr   = new DialogResult();
            mainForm     form = new mainForm("Set user phase for:", "All", "Selected");

            dr = form.ShowDialog();
            if (dr == DialogResult.Yes)     // 'Yes' is used for all objects
            {
                SelectedObjects = Model.GetModelObjectSelector().GetAllObjectsWithType(Types);
            }
            else if (dr == DialogResult.No) // 'No' is used to get selected objects
            {
                SelectedObjects = new Tekla.Structures.Model.UI.ModelObjectSelector().GetSelectedObjects();
            }
            else
            {
                return;
            }
            // =======================================================================================

            // list of changed objects
            ArrayList partList = new ArrayList();

            while (SelectedObjects.MoveNext())
            {
                var currentObject       = SelectedObjects.Current;
                var currObjPhaseComment = "";
                var currObjUserPhase    = "";

                Phase currObjPhase = new Phase();

                currentObject.GetPhase(out currObjPhase);
                // phase comment gets copied to user phase
                currObjPhaseComment = currObjPhase.PhaseComment;
                currentObject.GetUserProperty("USER_PHASE", ref currObjUserPhase);

                if (currObjUserPhase != currObjPhaseComment)
                {
                    //currentObject.SetUserProperty("USER_PHASE", currObjPhaseComment);
                    partList.Add(currentObject);
                }
            }

            // select objects that are in list for modification
            Tekla.Structures.Model.UI.ModelObjectSelector mos = new Tekla.Structures.Model.UI.ModelObjectSelector();
            mos.Select(partList);

            // modified object count
            var modCount = 0;
            var errCount = 0;

            // exit if there is no parts to modify
            if (partList.Count != 0)
            {
                // confirm modification
                DialogResult drConfirmation   = new DialogResult();
                mainForm     formConfirmation = new mainForm("Selected objects will be modified", "Refresh", "Ok");
                drConfirmation = formConfirmation.ShowDialog();
                if (drConfirmation == DialogResult.Yes)     // 'Yes' is used to refresh selection
                {
                    mos.Select(partList);
                }
                else if (drConfirmation == DialogResult.No) // 'No' is used to confirm
                {
                    // if OK, then go through list and modify each part
                    Tekla.Structures.Model.ModelObjectEnumerator selObjEnum = Model.GetModelObjectSelector().GetAllObjectsWithType(ModelObject.ModelObjectEnum.CONTOURPLATE);
                    selObjEnum = new Tekla.Structures.Model.UI.ModelObjectSelector().GetSelectedObjects();

                    // modify only objects that are in part list for modification and in current selection
                    while (selObjEnum.MoveNext())
                    {
                        foreach (var part in partList)
                        {
                            Beam         beam  = part as Beam;
                            ContourPlate plate = part as ContourPlate;
                            if (beam != null && selObjEnum.Current.Identifier.ToString() == beam.Identifier.ToString() || plate != null && selObjEnum.Current.Identifier.ToString() == plate.Identifier.ToString())
                            {
                                try
                                {
                                    var   currentObject       = selObjEnum.Current;
                                    var   currObjPhaseComment = "";
                                    var   currObjUserPhase    = "";
                                    Phase currObjPhase        = new Phase();

                                    currentObject.GetPhase(out currObjPhase);
                                    // phase comment gets copied to user phase
                                    currObjPhaseComment = currObjPhase.PhaseComment;
                                    currentObject.GetUserProperty("USER_PHASE", ref currObjUserPhase);

                                    if (currObjUserPhase != currObjPhaseComment)
                                    {
                                        currentObject.SetUserProperty("USER_PHASE", currObjPhaseComment);
                                    }
                                    modCount++;
                                }
                                catch
                                {
                                    errCount++;
                                }
                            }
                        }
                    }
                    if (errCount != 0)
                    {
                        MessageBox.Show("Warning\n# of objects which didn't modify:\n" + errCount + "\n\n# of changed objects:\n" + modCount, "FLPL checker");
                    }
                    else
                    {
                        MessageBox.Show("# of changed objects:\n" + modCount, "FLPL checker");
                    }
                }
                else
                {
                    return;
                }
            }
            else
            {
                MessageBox.Show("No parts to modifiy found.", Globals.appName);
            }
        }