Exemplo n.º 1
0
        /// <summary>
        /// select all parts that need to be renumbered
        /// </summary>
        /// <param name="model"></param>
        /// <returns>quantity of selected parts</returns>
        public static int SelectPartsToBeRenumbered(TSM.Model model)
        {
            ArrayList partsToBeSelected = new ArrayList();

            foreach (PartCustom part in partList)
            {
                if (part.NeedsToChange)
                {
                    partsToBeSelected.Add(model.SelectModelObject(part.Identifier));
                }
            }
            TSM.UI.ModelObjectSelector mos = new TSM.UI.ModelObjectSelector();
            mos.Select(partsToBeSelected);
            return mos.GetSelectedObjects().GetSize();
        }
Exemplo n.º 2
0
        /// <summary>
        /// Renumbers part that need renumbering.
        /// </summary>
        /// <param name="model">Tekla.Structures.Model model</param>
        public static void RenumberParts(TSM.Model model)
        {
            // check if numberinghistory.txt exists and change its name
            RenameNumberingHistory(model);

            foreach (PartCustom part in partList)
            {
                if (part.NeedsToChange)
                {
                    string partCurrentPosition;
                    partCurrentPosition = part.prefix.ToString() + part.number.ToString();

                    int newNum;
                    string oppositePrefix = ChangeCapitalization(part.Prefix);

                    // checks if a part with same position has already been assigned a new number.
                    // If so, it skips it --> tekla applies the new number from the first part to all of the same parts
                    // all changes are collected in prefixChanges dictionary.
                    if (!prefixChanges.ContainsKey(partCurrentPosition))
                    {
                        bool firstGo = true;
                        string preNumber = string.Empty;
                        string postNumber = string.Empty;

                        do
                        {
                            int maxOppositeNumber = positionsDictionary[oppositePrefix].Max();
                            int maxNumber = positionsDictionary[part.Prefix].Max();

                            newNum = Math.Max(maxNumber, maxOppositeNumber) + 1;

                            // adds new number to prefixChanges dictionary
                            Tuple<string, int> tuple = new Tuple<string, int>(part.prefix, newNum);

                            if (firstGo)
                            {
                                prefixChanges.Add(partCurrentPosition, tuple);
                            }
                            else
                            {
                                prefixChanges.Remove(partCurrentPosition);
                                prefixChanges.Add(partCurrentPosition, tuple);
                            }

                            // select part - clumsy, could it be improved?
                            ArrayList aList = new ArrayList();
                            TSM.Object tPart = model.SelectModelObject(part.Identifier);
                            TSM.UI.ModelObjectSelector selector = new TSM.UI.ModelObjectSelector();
                            aList.Add(tPart);
                            selector.Select(aList);

                            TSM.Part myPart = tPart as TSM.Part;

                            // preNumber and postNumber strings are compared in the 'while' of the do-while loop, to determine if Macrobuilder
                            // macro was succesfully run.
                            // (sometimes Tekla doesn't want to apply certain numbers - e.g.: if they were in use in previous model stages, ... )
                            preNumber = myPart.GetPartMark();

                            // use Macrobuilder dll to change numbering
                            MacroBuilder macroBuilder = new MacroBuilder();
                            macroBuilder.Callback("acmdAssignPositionNumber", "part", "main_frame");
                            macroBuilder.ValueChange("assign_part_number", "Position", newNum.ToString());
                            macroBuilder.PushButton("AssignPB", "assign_part_number");
                            macroBuilder.PushButton("CancelPB", "assign_part_number");
                            macroBuilder.Run();

                            postNumber = myPart.GetPartMark();

                            bool ismacrounning = true;
                            while (ismacrounning)
                            {
                                ismacrounning = TSM.Operations.Operation.IsMacroRunning();
                            }

                            // add newly created part mark to positionsDict
                            positionsDictionary[part.Prefix].Add(newNum);

                            firstGo = false;

                        }
                        //while (!AssignmentSuccesCheck(model));
                        while (preNumber == postNumber);
                    }
                }
            }
        }