public static void Run(Tekla.Technology.Akit.IScript akit)
        {
            TSM.UI.ModelViewEnumerator views = TSM.UI.ViewHandler.GetSelectedViews();

            if (views.Count > 0)
            {
                while (views.MoveNext())
                {
                    TSM.UI.View activeView = views.Current;
                    TSM.UI.ModelObjectSelector selector = new Tekla.Structures.Model.UI.ModelObjectSelector();

                    ArrayList visibleParts = ItemSelector.getParts(activeView);
                    selector.Select(visibleParts);

                    akit.Callback("acmdViewTopInFormFace", "", "View_01 window_1");

                    ArrayList empty = new ArrayList();
                    selector.Select(empty);
                }
            }
            else
            {
                MessageBox.Show("Vaate aken peab olema aktiivne");
            }
        }
        public static void Run(Tekla.Technology.Akit.IScript akit)
        {
            TSM.UI.ModelViewEnumerator views = TSM.UI.ViewHandler.GetSelectedViews();

            if (views.Count > 0)
            {
                while (views.MoveNext())
                {
                    TSM.UI.View activeView = views.Current;
                    TSM.UI.ModelObjectSelector selector = new Tekla.Structures.Model.UI.ModelObjectSelector();

                    ArrayList visibleParts = ItemSelector.getParts(activeView);
                    selector.Select(visibleParts);

                    akit.Callback("acmdViewTopInFormFace", "", "View_01 window_1");

                    ArrayList empty = new ArrayList();
                    selector.Select(empty);
                }
            }
            else
            {
                MessageBox.Show("Vaate aken peab olema aktiivne");
            }
        }
Пример #3
0
        /// <summary>Selects all objects which are on the phase</summary>
        /// <param name="phaseNumber">Number of the phase</param>
        /// <exception cref="Exceptions.FilteringToolTeklaSettingsException">When macro directory not exsists</exception>
        public static void SelectObjects(int phaseNumber)
        {
            var assemblyPhase = new TemplateFilterExpressions.CustomString("ASSEMBLY.PHASE");
            var phase         = new StringConstantFilterExpression(phaseNumber.ToString());
            var expresion1    = new BinaryFilterExpression(assemblyPhase, StringOperatorType.IS_EQUAL, phase);

            var objectType = new ObjectFilterExpressions.Type();
            var partF      = new NumericConstantFilterExpression(Tekla.Structures.TeklaStructuresDatabaseTypeEnum.PART);
            var expresion2 = new BinaryFilterExpression(objectType, NumericOperatorType.IS_EQUAL, partF);

            var expresion = new BinaryFilterExpressionCollection();

            expresion.Add(new BinaryFilterExpressionItem(expresion1, BinaryFilterOperatorType.BOOLEAN_AND));
            expresion.Add(new BinaryFilterExpressionItem(expresion2, BinaryFilterOperatorType.BOOLEAN_AND));

            var filter = new Filter(expresion);

            var objects = new Tekla.Structures.Model.Model().GetModelObjectSelector().GetObjectsByFilter(expresion);

            objects.SelectInstances = false;

            var ar = new System.Collections.ArrayList();

            while (objects.MoveNext())
            {
                var part = objects.Current as Tekla.Structures.Model.Part;
                if (part != null)
                {
                    var assembly = part.GetAssembly();
                    ar.Add(assembly);
                    break;
                }
            }

            var mos = new Tekla.Structures.Model.UI.ModelObjectSelector();

            mos.Select(new System.Collections.ArrayList());
            mos.Select(ar);

            if (Tekla.Structures.TeklaStructures.Connect())
            {
                TeklaMacroDirectory.CheckIfExists();
                var akit = new Tekla.Structures.MacroBuilder();

                akit.PushButton("butCancel", "diaPhaseManager");
                akit.Callback("acmd_display_active_system_dialog", "", "main_frame");
                akit.PushButton("butSelectPhases", "diaPhaseManager");
                akit.PushButton("butSelectObjects", "diaPhaseManager");
                akit.PushButton("butCancel", "diaPhaseManager");

                akit.Run();
                akit = null;
            }
        }
Пример #4
0
        public bool ClashCheck()
        {
            bool result = false;

            _selector       = new ModelObectSelector();
            _clashes        = new ArrayList();
            _clashCheckDone = false;
            ArrayList objectsToSelect = new ArrayList();

            objectsToSelect = InsertThreeClashingParts();

            #region 전체 모델의 충돌에 대해 확인
            ModelObjectEnumerator modelObjectEnumerator = _model.GetModelObjectSelector().GetAllObjects();
            foreach (ModelObject modelObject in modelObjectEnumerator)
            {
                objectsToSelect.Add(modelObject);
            }
            #endregion

            _selector.Select(objectsToSelect);
            _model.CommitChanges();

            result = RunClashCheck();

            if (TsEvent != null)
            {
                TsEvent.UnRegister();
            }

            return(result);
        }
Пример #5
0
        void Events_SelectionChangeEvent()
        {
            /* Make sure that the inner code block is running synchronously */
            lock (_selectionEventHandlerLock)
            {
                System.Console.WriteLine("Selection changed event received.");

                var selection = new Tekla.Structures.Model.UI.ModelObjectSelector()
                                .GetSelectedObjects()
                                .ToAList <Part>();
                if (!selection.Any())
                {
                    return;
                }
                var rawRows = dataGridView1.Rows.OfType <DataGridViewRow>().ToList();

                var assemblies = selection.Select(p => p.GetAssembly());

                var rows = rawRows.AsParallel().Where(r =>
                {
                    dynamic item = r.DataBoundItem;
                    if (item.Id == null)
                    {
                        return(false);
                    }
                    var id = (int)item.Id;
                    return(assemblies.FirstOrDefault(p => p.Identifier.ID == id) != null);
                }).ToList();

                CreateBom(rows);
            }
        }
Пример #6
0
        public static void Run(Tekla.Technology.Akit.IScript akit)
        {
            try
            {
                Model          model          = new Model();
                DrawingHandler drawingHandler = new DrawingHandler();

                ArrayList ModelObjectArray = new ArrayList();

                if (drawingHandler.GetActiveDrawing() != null)
                {
                    DrawingObjectEnumerator drawingObjectEnum = drawingHandler.GetDrawingObjectSelector().GetSelected();
                    if (drawingObjectEnum.GetSize() > 0)
                    {
                        while (drawingObjectEnum.MoveNext())
                        {
                            Tekla.Structures.Drawing.ModelObject dModelObject = (Tekla.Structures.Drawing.ModelObject)drawingObjectEnum.Current;
                            ModelObjectArray.Add(model.SelectModelObject(dModelObject.ModelIdentifier));
                        }
                    }

                    Tekla.Structures.Model.UI.ModelObjectSelector modelObjectSelector = new Tekla.Structures.Model.UI.ModelObjectSelector();
                    modelObjectSelector.Select(ModelObjectArray);
                }

                akit.Callback("acmdZoomToSelected", "", "main_frame");
            }
            catch { }
        }
Пример #7
0
        public static void Run(Tekla.Technology.Akit.IScript akit)
        {
            try
            {
                Model          model          = new Model();
                DrawingHandler drawingHandler = new DrawingHandler();

                ArrayList ModelObjectArray = new ArrayList();

                if (drawingHandler.GetActiveDrawing() != null)
                {
                    DrawingObjectEnumerator drawingObjectEnum = drawingHandler.GetDrawingObjectSelector().GetSelected();
                    while (drawingObjectEnum.MoveNext())
                    {
                        Tekla.Structures.Drawing.ModelObject dModelObject = (Tekla.Structures.Drawing.ModelObject)drawingObjectEnum.Current;
                        ModelObjectArray.Add(model.SelectModelObject(dModelObject.ModelIdentifier));
                    }
                }
                else
                {
                    ModelObjectEnumerator modelObjectEnum = model.GetModelObjectSelector().GetSelectedObjects();
                    while (modelObjectEnum.MoveNext())
                    {
                        Tekla.Structures.Model.ModelObject modelObject = (Tekla.Structures.Model.ModelObject)modelObjectEnum.Current;
                        ModelObjectArray.Add(model.SelectModelObject(modelObject.Identifier));
                    }
                }

                Tekla.Structures.Model.UI.ModelObjectSelector modelObjectSelector = new Tekla.Structures.Model.UI.ModelObjectSelector();
                modelObjectSelector.Select(ModelObjectArray);
                akit.Callback("acmdCreateViewBySelectedObjectsExtrema", "", "main_frame");
                akit.Callback("acmd_interrupt", "", "main_frame");
            }
            catch { }
        }
Пример #8
0
        public static void Run(Tekla.Technology.Akit.IScript akit)
        {
            try
            {
                Model                   model             = new Model();
                DrawingHandler          drawingHandler    = new DrawingHandler();
                DrawingObjectEnumerator drawingObjectEnum = drawingHandler.GetDrawingObjectSelector().GetSelected();
                ArrayList               ModelObjectArray  = new ArrayList();

                if (drawingObjectEnum.GetSize() > 0)
                {
                    while (drawingObjectEnum.MoveNext())
                    {
                        if (drawingObjectEnum.Current is Tekla.Structures.Drawing.Part)
                        {
                            Tekla.Structures.Drawing.Part part = drawingObjectEnum.Current as Tekla.Structures.Drawing.Part;
                            ModelObjectArray.Add(model.SelectModelObject(new Identifier(part.ModelIdentifier.ID)));
                        }
                        if (drawingObjectEnum.Current is Tekla.Structures.Drawing.Bolt)
                        {
                            Tekla.Structures.Drawing.Bolt bolt = drawingObjectEnum.Current as Tekla.Structures.Drawing.Bolt;
                            ModelObjectArray.Add(model.SelectModelObject(new Identifier(bolt.ModelIdentifier.ID)));
                        }
                    }
                }

                Tekla.Structures.Model.UI.ModelObjectSelector modelObjectSelector = new Tekla.Structures.Model.UI.ModelObjectSelector();
                modelObjectSelector.Select(ModelObjectArray);
                akit.Callback("acmd_display_selected_object_dialog", "", "main_frame");
            }
            catch { }
        }
Пример #9
0
        public static void Run(Tekla.Technology.Akit.IScript akit)
        {
            Model             model          = new Model();
            DrawingHandler    drawingHandler = new DrawingHandler();
            DrawingEnumerator drawingEnum    = drawingHandler.GetDrawingSelector().GetSelected();

            if (drawingHandler.GetActiveDrawing() == null)
            {
                while (drawingEnum.MoveNext())
                {
                    if (drawingEnum.Current is AssemblyDrawing)
                    {
                        AssemblyDrawing assemblyDrawing = drawingEnum.Current as AssemblyDrawing;
                        drawingHandler.SetActiveDrawing(assemblyDrawing, false);
                        DrawingObjectEnumerator drawingObjectEnum = drawingHandler.GetActiveDrawing().GetSheet().GetAllObjects();
                        while (drawingObjectEnum.MoveNext())
                        {
                            if (drawingObjectEnum.Current is Tekla.Structures.Drawing.Part)
                            {
                                Tekla.Structures.Drawing.Part part = drawingObjectEnum.Current as Tekla.Structures.Drawing.Part;
                                ArrayList array = new ArrayList();
                                array.Add(model.SelectModelObject(new Tekla.Structures.Identifier(part.ModelIdentifier.ID)));
                                Tekla.Structures.Model.UI.ModelObjectSelector modelObjectSelector = new Tekla.Structures.Model.UI.ModelObjectSelector();
                                modelObjectSelector.Select(array);
                                ModelObjectEnumerator modelObjectEnum = model.GetModelObjectSelector().GetSelectedObjects();
                                while (modelObjectEnum.MoveNext())
                                {
                                    if (modelObjectEnum.Current is Tekla.Structures.Model.Part)
                                    {
                                        Tekla.Structures.Model.Part     mpart    = modelObjectEnum.Current as Tekla.Structures.Model.Part;
                                        Tekla.Structures.Model.Assembly assembly = mpart.GetAssembly();
                                        Tekla.Structures.Model.Part     mainPart = (Tekla.Structures.Model.Part)assembly.GetMainPart();
                                        assemblyDrawing.Name = mainPart.Name;
                                        assemblyDrawing.Modify();
                                        assemblyDrawing.CommitChanges();
                                    }
                                }
                                modelObjectSelector.Select(new ArrayList());
                            }
                        }
                        drawingHandler.CloseActiveDrawing();
                    }
                }
            }
        }
Пример #10
0
        public static void selectAssemblys(List <_Assembly> filtered)
        {
            ArrayList selection = new ArrayList();

            foreach (_Assembly current in filtered)
            {
                selection.Add(current._assembly);
            }

            TSM.UI.ModelObjectSelector modelSelector = new TSM.UI.ModelObjectSelector();
            modelSelector.Select(selection);
        }
Пример #11
0
        private void GetIdNumbers_Click(object sender, EventArgs e)
        {
            Model model = new Model();

            Tekla.Structures.Model.UI.ModelObjectSelector modelObjectSelector = new Tekla.Structures.Model.UI.ModelObjectSelector();
            Drawing drawing = drawingHandler.GetActiveDrawing();
            DrawingObjectEnumerator drawingObjectEnumerator = drawingHandler.GetDrawingObjectSelector().GetSelected();
            ArrayList SelectedObjectArray = new ArrayList();
            ArrayList MarkArray           = new ArrayList();

            while (drawingObjectEnumerator.MoveNext())
            {
                if (drawingObjectEnumerator.Current is Tekla.Structures.Drawing.Part)
                {
                    Tekla.Structures.Drawing.Part part = drawingObjectEnumerator.Current as Tekla.Structures.Drawing.Part;
                    SelectedObjectArray.Add(model.SelectModelObject(new Identifier(part.ModelIdentifier.ID)));
                    DrawingObjectArray.Add(part);
                }
                if (drawingObjectEnumerator.Current is Tekla.Structures.Drawing.Bolt)
                {
                    Tekla.Structures.Drawing.Bolt bolt = drawingObjectEnumerator.Current as Tekla.Structures.Drawing.Bolt;
                    SelectedObjectArray.Add(model.SelectModelObject(new Identifier(bolt.ModelIdentifier.ID)));
                    DrawingObjectArray.Add(bolt);
                }
            }
            modelObjectSelector.Select(SelectedObjectArray);
            Tekla.Structures.Model.ModelObjectEnumerator modelObjectEnumerator = model.GetModelObjectSelector().GetSelectedObjects();
            while (modelObjectEnumerator.MoveNext())
            {
                if (modelObjectEnumerator.Current is Tekla.Structures.Model.Part)
                {
                    Tekla.Structures.Model.Part modelPart = modelObjectEnumerator.Current as Tekla.Structures.Model.Part;
                    MarkArray.Add(modelPart.Identifier.ID.ToString());
                }
                if (modelObjectEnumerator.Current is Tekla.Structures.Model.BoltGroup)
                {
                    Tekla.Structures.Model.BoltGroup modelBolt = modelObjectEnumerator.Current as Tekla.Structures.Model.BoltGroup;
                    MarkArray.Add(modelBolt.Identifier.ID.ToString());
                }
            }
            MarkArray.Sort();
            string MarkList = "";

            foreach (string strMark in MarkArray)
            {
                MarkList = strMark + " " + MarkList;
            }
            Clipboard.SetDataObject(MarkList); richTextBox1.Text = MarkList;
            drawingHandler.GetDrawingObjectSelector().SelectObjects(DrawingObjectArray, false);
        }
Пример #12
0
        private void GetMarks(string MarkType)
        {
            Model model = new Model();

            Tekla.Structures.Model.UI.ModelObjectSelector modelObjectSelector = new Tekla.Structures.Model.UI.ModelObjectSelector();
            Drawing drawing = drawingHandler.GetActiveDrawing();
            DrawingObjectEnumerator drawingObjectEnumerator = drawingHandler.GetDrawingObjectSelector().GetSelected();
            ArrayList SelectedObjectArray = new ArrayList();
            ArrayList MarkArray           = new ArrayList();

            while (drawingObjectEnumerator.MoveNext())
            {
                if (drawingObjectEnumerator.Current is Tekla.Structures.Drawing.Part)
                {
                    Tekla.Structures.Drawing.Part part = drawingObjectEnumerator.Current as Tekla.Structures.Drawing.Part;
                    SelectedObjectArray.Add(model.SelectModelObject(new Identifier(part.ModelIdentifier.ID)));
                    DrawingObjectArray.Add(part);
                }
            }
            modelObjectSelector.Select(SelectedObjectArray);
            Tekla.Structures.Model.ModelObjectEnumerator modelObjectEnumerator = model.GetModelObjectSelector().GetSelectedObjects();
            while (modelObjectEnumerator.MoveNext())
            {
                if (modelObjectEnumerator.Current is Tekla.Structures.Model.Part)
                {
                    Tekla.Structures.Model.Part modelPart = modelObjectEnumerator.Current as Tekla.Structures.Model.Part;
                    string mark = "";
                    try
                    {
                        modelPart.GetReportProperty(MarkType, ref mark);
                        if (!MarkArray.Contains(mark))
                        {
                            MarkArray.Add(mark);
                        }
                    }
                    catch { }
                }
            }
            MarkArray.Sort();
            string MarkList = "";

            foreach (string strMark in MarkArray)
            {
                MarkList = strMark + " " + MarkList;
            }
            Clipboard.SetDataObject(MarkList); richTextBox1.Text = MarkList;
            drawingHandler.GetDrawingObjectSelector().SelectObjects(DrawingObjectArray, false);
        }
Пример #13
0
        public static void selectFoundObject(ArrayList selectId)
        {
            ArrayList select = new ArrayList();

            Model myModel = new Model();

            foreach (Identifier id in selectId)
            {
                ModelObject foundPart = myModel.SelectModelObject(id) as ModelObject;
                select.Add(foundPart);
            }

            var ModelSelector = new TSM.UI.ModelObjectSelector();

            ModelSelector.Select(select);
        }
Пример #14
0
        private void SelectModelObjectsInUi(List <int> ids)
        {
            var modelObjects = new ArrayList();

            ids.ForEach(id =>
            {
                var modelObject = _model.SelectModelObject(new Identifier(id));
                if (modelObject == null)
                {
                    return;
                }
                modelObjects.Add(modelObject);
            });

            var selector = new Tekla.Structures.Model.UI.ModelObjectSelector();

            selector.Select(modelObjects);
        }
        private static void changePartToSubAssembly(TSM.Assembly assembly, ArrayList wrongParts, Tekla.Technology.Akit.IScript akit)
        {
            TSM.UI.ModelObjectSelector selector = new TSM.UI.ModelObjectSelector();

            selector.Select(wrongParts);
            akit.Callback("acmdRemoveFromAssemblyActionCB", "", "View_01 window_1");

            //assembly.Modify();

            selector = new TSM.UI.ModelObjectSelector();
            TSM.ModelObjectEnumerator selectionEnum = selector.GetSelectedObjects();

            while (selectionEnum.MoveNext())
            {
                if (selectionEnum.Current is TSM.Part)
                {
                    TSM.Part newPart = selectionEnum.Current as TSM.Part;
                    TSM.Assembly partNewAssembly = newPart.GetAssembly() as TSM.Assembly;

                    ArrayList currentSelection = new ArrayList();
                    currentSelection.Add(assembly);
                    selector.Select(currentSelection);
                    TSM.ModelObjectEnumerator selectionEnum2 = selector.GetSelectedObjects();

                    while (selectionEnum2.MoveNext())
                    {
                        if (selectionEnum2.Current is TSM.Assembly)
                        {
                            TSM.Assembly newAssembly = selectionEnum2.Current as TSM.Assembly;
                            newAssembly.Add(partNewAssembly);
                            newAssembly.Modify();
                        }
                    }
                }
            }

            foreach (TSM.Part part in wrongParts)
            {
                TSM.Assembly newAssembly = part.GetAssembly() as TSM.Assembly;
                removeAssemblyPropertys(newAssembly, akit);
            }
        }
        private static void changePartToSubAssembly(TSM.Assembly assembly, ArrayList wrongParts, Tekla.Technology.Akit.IScript akit)
        {
            TSM.UI.ModelObjectSelector selector = new TSM.UI.ModelObjectSelector();

            selector.Select(wrongParts);
            akit.Callback("acmdRemoveFromAssemblyActionCB", "", "View_01 window_1");

            //assembly.Modify();

            selector = new TSM.UI.ModelObjectSelector();
            TSM.ModelObjectEnumerator selectionEnum = selector.GetSelectedObjects();

            while (selectionEnum.MoveNext())
            {
                if (selectionEnum.Current is TSM.Part)
                {
                    TSM.Part     newPart         = selectionEnum.Current as TSM.Part;
                    TSM.Assembly partNewAssembly = newPart.GetAssembly() as TSM.Assembly;

                    ArrayList currentSelection = new ArrayList();
                    currentSelection.Add(assembly);
                    selector.Select(currentSelection);
                    TSM.ModelObjectEnumerator selectionEnum2 = selector.GetSelectedObjects();

                    while (selectionEnum2.MoveNext())
                    {
                        if (selectionEnum2.Current is TSM.Assembly)
                        {
                            TSM.Assembly newAssembly = selectionEnum2.Current as TSM.Assembly;
                            newAssembly.Add(partNewAssembly);
                            newAssembly.Modify();
                        }
                    }
                }
            }

            foreach (TSM.Part part in wrongParts)
            {
                TSM.Assembly newAssembly = part.GetAssembly() as TSM.Assembly;
                removeAssemblyPropertys(newAssembly, akit);
            }
        }
Пример #17
0
        public static void selectInModel(string cur)
        {
            Model _myModel = new Model();

            ArrayList selected = new ArrayList();

            try
            {
                Guid       GUID = new Guid(cur);
                Identifier id   = new Identifier(GUID);
                object     mo   = _myModel.SelectModelObject(id);
                selected.Add(mo);
            }
            catch
            {
            }

            TSM.UI.ModelObjectSelector selector = new TSM.UI.ModelObjectSelector();
            selector.Select(selected);
        }
        private static void removeAssemblyPropertys(TSM.Assembly currentAssembly, Tekla.Technology.Akit.IScript akit)
        {
            ArrayList currentSelection = new ArrayList();

            currentSelection.Add(currentAssembly);

            TSM.UI.ModelObjectSelector selector = new TSM.UI.ModelObjectSelector();
            selector.Select(currentSelection);

            akit.Callback("acmd_display_selected_object_dialog", "", "View_01 window_1");
            TSM.Part currentMainPart = currentAssembly.GetMainPart() as TSM.Part;

            if (!currentMainPart.Material.MaterialString.StartsWith("C"))
            {
                akit.ValueChange("steelassembly_1", "AssemblyPrefix", "");
                akit.ValueChange("steelassembly_1", "AssemblyStartNumber", "");
                akit.ValueChange("steelassembly_1", "AssemblyName", "");
                akit.PushButton("modify_button", "steelassembly_1");
                akit.PushButton("OK_button", "steelassembly_1");
            }
            else
            {
                if (currentMainPart.CastUnitType == 0)
                {
                    akit.ValueChange("precastassembly_1", "AssemblyPrefix", "");
                    akit.ValueChange("precastassembly_1", "AssemblyStartNumber", "");
                    akit.ValueChange("precastassembly_1", "AssemblyName", "");
                    akit.PushButton("modify_button", "precastassembly_1");
                    akit.PushButton("OK_button", "precastassembly_1");
                }
                else
                {
                    akit.ValueChange("insituassembly_1", "AssemblyPrefix", "");
                    akit.ValueChange("insituassembly_1", "AssemblyStartNumber", "");
                    akit.ValueChange("insituassembly_1", "AssemblyName", "");
                    akit.PushButton("modify_button", "insituassembly_1");
                    akit.PushButton("OK_button", "insituassembly_1");
                }
            }
        }
Пример #19
0
        private void comboBox1_SelectedValueChanged(object sender, EventArgs e)
        {
            Drawing drawing = drawingHandler.GetActiveDrawing();

            if (drawing == null)
            {
                Tekla.Structures.Model.UI.ModelObjectSelector modelObjectSelector = new Tekla.Structures.Model.UI.ModelObjectSelector();
                ArrayList arrayObjectsSelected = GetModelObjectsByType(comboBox1.Text);
                if (arrayObjectsSelected.Count > 0)
                {
                    modelObjectSelector.Select(arrayObjectsSelected);
                }
            }
            if (drawing != null)
            {
                ArrayList arrayObjectsSelected = GetDrawingObjectsByType(comboBox1.Text);
                if (arrayObjectsSelected.Count > 0)
                {
                    drawingHandler.GetDrawingObjectSelector().SelectObjects(arrayObjectsSelected, false);
                }
            }
        }
Пример #20
0
        public static void Run(Tekla.Technology.Akit.IScript akit)
        {
            Model                 model           = new Model();
            ArrayList             array           = new ArrayList();
            ModelObjectEnumerator modelObjectEnum = model.GetModelObjectSelector().GetSelectedObjects();

            while (modelObjectEnum.MoveNext())
            {
                if (modelObjectEnum.Current is Tekla.Structures.Model.Part)
                {
                    Tekla.Structures.Model.Part part = modelObjectEnum.Current as Tekla.Structures.Model.Part;
                    //array.Add(model.SelectModelObject(new Tekla.Structures.Identifier(part.Identifier.ID)));
                    ModelObjectEnumerator CutEnum = part.GetBooleans();
                    while (CutEnum.MoveNext())
                    {
                        Tekla.Structures.Model.Boolean cut = CutEnum.Current as Tekla.Structures.Model.Boolean;
                        array.Add(model.SelectModelObject(new Tekla.Structures.Identifier(cut.Identifier.ID)));
                    }
                }
            }
            Tekla.Structures.Model.UI.ModelObjectSelector modelObjectSelector = new Tekla.Structures.Model.UI.ModelObjectSelector();
            modelObjectSelector.Select(array);
        }
        private void CreateExtraSheets_Click(object sender, EventArgs e)
        {
            akit.Callback("acmd_display_attr_dialog", "adraw_dial", "main_frame"); // open drawing settings dialog
            akit.ValueChange("adraw_dial", "gr_adraw_get_menu", "KWP-blank");      // select blank attributes
            akit.PushButton("gr_adraw_get", "adraw_dial");                         // load attributes

            Model model = new Model();

            Tekla.Structures.Model.UI.ModelObjectSelector mObjSelector = new Tekla.Structures.Model.UI.ModelObjectSelector();
            DrawingHandler    drawingHandler = new DrawingHandler();
            DrawingEnumerator drawingEnum    = drawingHandler.GetDrawingSelector().GetSelected();

            if (drawingEnum.GetSize() > 0)
            {
                while (drawingEnum.MoveNext())
                {
                    if (drawingEnum.Current is AssemblyDrawing)
                    {
                        AssemblyDrawing assemblyDrawing = drawingEnum.Current as AssemblyDrawing;
                        akit.ValueChange("adraw_dial", "gr_adraw_description", assemblyDrawing.Name); // change name
                        akit.PushButton("dia_draw_select_parts", "Drawing_selection");                // select parts in drawing
                        int  count  = 0;
                        bool result = int.TryParse(RequiredSheets.Text, out count);
                        for (int i = 2; i <= count; i++)
                        {
                            akit.ValueChange("adraw_dial", "txtFldSheetNumber", i.ToString());    // change sheet number
                            akit.PushButton("gr_adraw_apply", "adraw_dial");                      // apply settings
                            akit.Callback("acmd_create_dim_assembly_drawings", "", "main_frame"); // create assembly drawing for selected part
                        }

                        mObjSelector.Select(new ArrayList());
                    }
                }
            }
            PickExtraSheets.Enabled = true;
        }
        private static void removeAssemblyPropertys(TSM.Assembly currentAssembly, Tekla.Technology.Akit.IScript akit)
        {
            ArrayList currentSelection = new ArrayList();
            currentSelection.Add(currentAssembly);

            TSM.UI.ModelObjectSelector selector = new TSM.UI.ModelObjectSelector();
            selector.Select(currentSelection);

            akit.Callback("acmd_display_selected_object_dialog", "", "View_01 window_1");
            TSM.Part currentMainPart = currentAssembly.GetMainPart() as TSM.Part;

            if (!currentMainPart.Material.MaterialString.StartsWith("C"))
            {
                akit.ValueChange("steelassembly_1", "AssemblyPrefix", "");
                akit.ValueChange("steelassembly_1", "AssemblyStartNumber", "");
                akit.ValueChange("steelassembly_1", "AssemblyName", "");
                akit.PushButton("modify_button", "steelassembly_1");
                akit.PushButton("OK_button", "steelassembly_1");
            }
            else
            {
                if (currentMainPart.CastUnitType == 0)
                {
                    akit.ValueChange("precastassembly_1", "AssemblyPrefix", "");
                    akit.ValueChange("precastassembly_1", "AssemblyStartNumber", "");
                    akit.ValueChange("precastassembly_1", "AssemblyName", "");
                    akit.PushButton("modify_button", "precastassembly_1");
                    akit.PushButton("OK_button", "precastassembly_1");
                }
                else
                {
                    akit.ValueChange("insituassembly_1", "AssemblyPrefix", "");
                    akit.ValueChange("insituassembly_1", "AssemblyStartNumber", "");
                    akit.ValueChange("insituassembly_1", "AssemblyName", "");
                    akit.PushButton("modify_button", "insituassembly_1");
                    akit.PushButton("OK_button", "insituassembly_1");
                }
            }
        }
Пример #23
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();
        }
Пример #24
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);
                    }
                }
            }
        }
        // This application assumes that users have already opened a drawing - an assembly drawing.
        // The goal is for the user to see that particular assembly
        // in the model, and to see ONLY that assembly in the model.
        // Therefore all parts which are not associated with this assembly need to be hidden.
        // All the clutter needs to be removed from view.
        // And all parts associated with this assembly need to be visible.
        // Summary: our goals is for users to see, given the particular assembly drawing that they are in,
        // just that ONE assembly within the model, and to have all other parts hidden.
        // Methodology:
        // 1. We obtain the assembly drawing and go through all the drawing objects within the assembly drawing. We get the identifiers of these
        ////  drawing objects and place them in a list (assemblyPartIdentifierList)
        // 2. We obtain the identifiers of all the objects in the model and place them on this list too.
        ///3. We want to hide all objects which are not associated with the assembly drawing which is currently open.
        ///4. Consequently, we obtain a List of identifiers which contains all the objects in the model APART from the assembly parts of the current assembly
        ///// we are working on.
        ///5. We convert this list of identifiers into a TSM.Model Object list, and then again convert this list into an ArrayList.
        ///6. The array list should contain all the objects we need to hide.
        ///7. We use the array list to select all the objects which need to be hidden, in the model.
        ///8. We want to call a macro which hides all the objects currently selected.
        // Two questions, (1) is the above approach a good and efficient wa to solve the above problem>
        // Given a drawing is open, how can one call a macro which hides all selected objects?
        // Your comemnts and criticism would be very much apprieciated.
        private void GetAssembly()
        {
            try
            {
            // creates model and drawing handle

                TSM.Model myModel = new TSM.Model();

                TSD.DrawingHandler dh = new TSD.DrawingHandler();

                if (dh.GetConnectionStatus() == false)
                {
                     System.Windows.Forms.MessageBox.Show("Could not connect drawing handler.");
                     return;
                }

            // users must have an Assembly drawing open. We want to see the assembly contained in the assembly drawing in the
            // UI. Hence we first obtain the identifiers of the drawing objects.

                TSD.Drawing currentDrawing = dh.GetActiveDrawing();

                if (currentDrawing == null)
                {
                    System.Windows.Forms.MessageBox.Show("Please ensure that an assembly drawing is open");
                    return;
                }

                TSD.AssemblyDrawing currentAssemblyDrawing = currentDrawing as TSD.AssemblyDrawing;

                if (currentAssemblyDrawing == null)
                {
                    System.Windows.Forms.MessageBox.Show("Please ensure that an assembly drawing is open");
                    return;
                }

                if (currentAssemblyDrawing != null)
                {
                    // in order to select in the model space we need to create an array list

                    ArrayList assemblyObjectToBeViewed = new ArrayList();

                    // we need to add a model object to the array list. We are adding the assembly as the model object for the model object selector to select
                    assemblyObjectToBeViewed.Add( myModel.SelectModelObject(currentAssemblyDrawing.AssemblyIdentifier) );

                    TSM.UI.ModelObjectSelector selector = new TSM.UI.ModelObjectSelector();
                    selector.Select(assemblyObjectToBeViewed);

                    TSM.Operations.Operation.RunMacro("ShowOnlySelected.cs");
                    TSM.Operations.Operation.RunMacro("FitToView.cs");
                }
                else
                {
                    System.Windows.Forms.MessageBox.Show("Please ensure you have an Assembly drawing open");
                }

            }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show(ex.Message);
            }
        }
Пример #26
0
        public static void Run(Tekla.Technology.Akit.IScript akit)
        {
            try
            {
                Model                   model            = new Model();
                DrawingHandler          drawingHandler   = new DrawingHandler();
                DrawingObjectEnumerator MyDrawingObjEnum = drawingHandler.GetDrawingObjectSelector().GetSelected();
                Tekla.Structures.Model.UI.ModelObjectSelector SelectObjects = new Tekla.Structures.Model.UI.ModelObjectSelector();
                Tekla.Structures.Drawing.Weld SelectedWeld = null;
                if (MyDrawingObjEnum.GetSize() == 1)
                {
                    while (MyDrawingObjEnum.MoveNext())
                    {
                        if (MyDrawingObjEnum.Current is Tekla.Structures.Drawing.Weld)
                        {
                            SelectedWeld = MyDrawingObjEnum.Current as Tekla.Structures.Drawing.Weld;
                            ArrayList temp = new ArrayList();
                            temp.Add(model.SelectModelObject(new Identifier(SelectedWeld.ModelIdentifier.ID)));
                            SelectObjects.Select(temp);
                            BaseWeld SelectedModelWeld = temp[0] as BaseWeld;

                            string strSizeAbove = SelectedModelWeld.SizeAbove.ToString();
                            string strTypeAbove = SelectedModelWeld.TypeAbove.ToString();
                            if (strTypeAbove == "WELD_TYPE_FILLET")
                            {
                                strTypeAbove = "10";                                     // Fillet weld
                            }
                            if (strTypeAbove == "WELD_TYPE_SINGLE_BEVEL_BUTT_WITH_BROAD_ROOT_FACE")
                            {
                                strTypeAbove = "6";                                                                     // W1 weld
                            }
                            if (strTypeAbove == "WELD_TYPE_NONE")
                            {
                                strTypeAbove = "0";                                   // No weld
                            }
                            if (strTypeAbove == "WELD_TYPE_BEVEL_GROOVE_SINGLE_BEVEL_BUTT")
                            {
                                strTypeAbove = "4";                                                             // W6 weld
                            }
                            if (strTypeAbove == "WELD_TYPE_SQUARE_GROOVE_SQUARE_BUTT")
                            {
                                strTypeAbove = "2";                                                        // W3 weld
                            }
                            if (strTypeAbove == "WELD_TYPE_PLUG")
                            {
                                strTypeAbove = "11";                                   // Plug weld
                            }
                            if (strTypeAbove == "WELD_TYPE_BEVEL_BACKING")
                            {
                                strTypeAbove = "9";                                            // Seal weld
                            }
                            if (strTypeAbove == "WELD_TYPE_PARTIAL_PENETRATION_SINGLE_BEVEL_BUTT_PLUS_FILLET")
                            {
                                strTypeAbove = "18";                                                                                // W1 weld + reinforced
                            }
                            string strContourAbove = SelectedModelWeld.ContourAbove.ToString();
                            if (strContourAbove == "WELD_CONTOUR_NONE")
                            {
                                strContourAbove = "0";
                            }
                            if (strContourAbove == "WELD_CONTOUR_FLUSH")
                            {
                                strContourAbove = "1";
                            }

                            string strSizeBelow = SelectedModelWeld.SizeBelow.ToString();
                            string strTypeBelow = SelectedModelWeld.TypeBelow.ToString();
                            if (strTypeBelow == "WELD_TYPE_FILLET")
                            {
                                strTypeBelow = "10";
                            }
                            if (strTypeBelow == "WELD_TYPE_SINGLE_BEVEL_BUTT_WITH_BROAD_ROOT_FACE")
                            {
                                strTypeBelow = "6";
                            }
                            if (strTypeBelow == "WELD_TYPE_NONE")
                            {
                                strTypeBelow = "0";                                   // No weld
                            }
                            if (strTypeBelow == "WELD_TYPE_BEVEL_GROOVE_SINGLE_BEVEL_BUTT")
                            {
                                strTypeBelow = "4";                                                             // W6 weld
                            }
                            if (strTypeBelow == "WELD_TYPE_SQUARE_GROOVE_SQUARE_BUTT")
                            {
                                strTypeBelow = "2";                                                        // W3 weld
                            }
                            if (strTypeBelow == "WELD_TYPE_PLUG")
                            {
                                strTypeBelow = "11";                                   // Plug weld
                            }
                            if (strTypeBelow == "WELD_TYPE_BEVEL_BACKING")
                            {
                                strTypeBelow = "9";                                            // Seal weld
                            }
                            if (strTypeBelow == "WELD_TYPE_PARTIAL_PENETRATION_SINGLE_BEVEL_BUTT_PLUS_FILLET")
                            {
                                strTypeBelow = "18";                                                                                // W1 weld + reinforced
                            }
                            string strContourBelow = SelectedModelWeld.ContourBelow.ToString();
                            if (strContourBelow == "WELD_CONTOUR_NONE")
                            {
                                strContourBelow = "0";
                            }
                            if (strContourBelow == "WELD_CONTOUR_FLUSH")
                            {
                                strContourBelow = "1";
                            }

                            string strAroundWeld = SelectedModelWeld.AroundWeld.ToString();
                            if (strAroundWeld == "False")
                            {
                                strAroundWeld = "0";
                            }
                            if (strAroundWeld == "True")
                            {
                                strAroundWeld = "1";
                            }

                            string strRefText = SelectedModelWeld.ReferenceText;

                            akit.PushButton("wld_cancel", "Weld Mark Properties");
                            akit.Callback("acmd_display_attr_dialog", "wld_dial", "main_frame");
                            akit.ValueChange("wld_dial", "gr_wld_get_menu", "standard");
                            akit.ValueChange("wld_dial", "w_size", strSizeAbove);
                            akit.ValueChange("wld_dial", "w_size2", strSizeBelow);
                            akit.ValueChange("wld_dial", "w_type", strTypeAbove);
                            akit.ValueChange("wld_dial", "w_type2", strTypeBelow);
                            akit.ValueChange("wld_dial", "w_ftype", strContourAbove);
                            akit.ValueChange("wld_dial", "w_ftype2", strContourBelow);
                            akit.ValueChange("wld_dial", "w_around", strAroundWeld);
                            akit.ValueChange("wld_dial", "w_wld", strRefText);
                            akit.PushButton("wld_apply", "wld_dial");
                            akit.CommandStart("ail_create_wld", "", "main_frame");
                        }
                    }
                    Tekla.Structures.Drawing.UI.DrawingObjectSelector drawingObjectSelector = drawingHandler.GetDrawingObjectSelector();
                    drawingObjectSelector.SelectObject(SelectedWeld);
                }
            }
            catch { }
        }
Пример #27
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);
            }
        }
        // This application assumes that users have already opened a drawing - an assembly drawing.
        // The goal is for the user to see that particular assembly
        // in the model, and to see ONLY that assembly in the model.
        // Therefore all parts which are not associated with this assembly need to be hidden.
        // All the clutter needs to be removed from view.
        // And all parts associated with this assembly need to be visible.

        // Summary: our goals is for users to see, given the particular assembly drawing that they are in,
        // just that ONE assembly within the model, and to have all other parts hidden.

        // Methodology:
        // 1. We obtain the assembly drawing and go through all the drawing objects within the assembly drawing. We get the identifiers of these
        ////  drawing objects and place them in a list (assemblyPartIdentifierList)
        // 2. We obtain the identifiers of all the objects in the model and place them on this list too.
        ///3. We want to hide all objects which are not associated with the assembly drawing which is currently open.
        ///4. Consequently, we obtain a List of identifiers which contains all the objects in the model APART from the assembly parts of the current assembly
        ///// we are working on.
        ///5. We convert this list of identifiers into a TSM.Model Object list, and then again convert this list into an ArrayList.
        ///6. The array list should contain all the objects we need to hide.
        ///7. We use the array list to select all the objects which need to be hidden, in the model.
        ///8. We want to call a macro which hides all the objects currently selected.

        // Two questions, (1) is the above approach a good and efficient wa to solve the above problem>
        // Given a drawing is open, how can one call a macro which hides all selected objects?
        // Your comemnts and criticism would be very much apprieciated.


        private static void GetAssembly()
        {
            try
            {
                // creates model and drawing handle

                TSM.Model myModel = new TSM.Model();

                TSD.DrawingHandler dh = new TSD.DrawingHandler();

                if (dh.GetConnectionStatus() == false)
                {
                    System.Windows.Forms.MessageBox.Show("Could not connect drawing handler.");
                    return;
                }

                // users must have an Assembly drawing open. We want to see the assembly contained in the assembly drawing in the
                // UI. Hence we first obtain the identifiers of the drawing objects.

                TSD.Drawing currentDrawing = dh.GetActiveDrawing();

                if (currentDrawing == null)
                {
                    System.Windows.Forms.MessageBox.Show("Please ensure that an assembly drawing is open");
                    return;
                }

                TSD.AssemblyDrawing currentAssemblyDrawing = currentDrawing as TSD.AssemblyDrawing;

                if (currentAssemblyDrawing == null)
                {
                    System.Windows.Forms.MessageBox.Show("Please ensure that an assembly drawing is open");
                    return;
                }

                if (currentAssemblyDrawing != null)
                {
                    // in order to select in the model space we need to create an array list

                    ArrayList assemblyObjectToBeViewed = new ArrayList();

                    // we need to add a model object to the array list. We are adding the assembly as the model object for the model object selector to select

                    assemblyObjectToBeViewed.Add(myModel.SelectModelObject(currentAssemblyDrawing.AssemblyIdentifier));

                    TSM.UI.ModelObjectSelector selector = new TSM.UI.ModelObjectSelector();
                    selector.Select(assemblyObjectToBeViewed);

                    TSM.Operations.Operation.RunMacro("ShowOnlySelected.cs");
                    TSM.Operations.Operation.RunMacro("FitToView.cs");
                }
                else
                {
                    System.Windows.Forms.MessageBox.Show("Please ensure you have an Assembly drawing open");
                }
            }

            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show(ex.Message);
            }
        }
Пример #29
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

            // <profile list>.csv - file location and name
            string csvLocation = "J:/Tekla/SKA_Macro files/stock list.csv";

            // <profile list>.csv - delimeter
            string delimiterString = ";";

            // list of part names for FL-PL profile check
            string[] partNamesToCheckArray = { "Afstivning", "Vind-X-Plade", "Løsdele", "Plade", "Fladstål", "Flange", };

            // list of part names to include in name AND prefix swaping (should be Plade and Fladstal)
            string[] partNamesToSwapArray = { "Plade", "Fladstål" };

            ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            // stock list.csv
            //
            // Instructions for preparation:
            // 1. you need original DS stock list,
            // 2. in excel delete all columns but 'Dimension', 'Reserveret' and 'Kvalitet'. This columns should be placed in A, B and C column positions,
            // 3. go through the rows and:
            //       - delete the rows with missing material,
            //       - repair the rows with corrupt material ('275' -> 'S275')
            //       - delete or repair rows with corrupt profile values (look for stuff like: '12x150', '100*5', '15'). Correct formatting is: 'width thickness'.
            // 4. save the file as 'stock list.csv' (default delimeter is semicolon. You can change the delimiter in 'delimiterString' variable)
            // 5. save the file in the location set with 'csvLocation' variable.
            ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            // Ideas for improvements
            // - add refresh selection button to message box 'Selected objects will be modified
            // - add 'working' icon to mouse
            ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            // v1.2, 30.1.2016
            // - more elaborate errors: added error catching for FileNotFoundException and DirectoryNotFoundException,
            // - now works also with files, that are currently open (have to check if this is tru also for in multiuser environments),
            ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

            // preparation of variables
            char delimeter = delimiterString[0];

            List <string> partNamesToCheck = new List <string>();

            partNamesToCheck.AddRange(partNamesToCheckArray);

            List <string> partNamesToSwap = new List <string>();

            partNamesToSwap.AddRange(partNamesToSwapArray);

            // Profile list - profiles with attributes (width, thickness, material)
            // if profile is reserved it does not go in this list
            List <List <string> > profileList = new List <List <string> >();

            profileList = csvReader(csvLocation, delimeter);

            // if clause to exit if csvReader didn't succeed
            if (profileList.Count == 0)
            {
                return;
            }

            Model Model = new Model();

            if (!Model.GetConnectionStatus())
            {
                MessageBox.Show("Tekla is not open.", Variables.caption);
                Environment.Exit(1);
            }

            // 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();

            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  nameOfObject           = "";
                var  profileOfObject        = "";
                var  prefixAssemblyOfObject = "";
                var  prefixPartOfObject     = "";
                bool isFlatProfile          = false;

                // get name of the object
                currentObject.GetReportProperty("NAME", ref nameOfObject);
                // strip the name of brackets
                nameOfObject = nameOfObject.Replace("(", "").Replace(")", "");

                // get the profile of the object
                currentObject.GetReportProperty("PROFILE", ref profileOfObject);

                // get the prefix of the object
                currentObject.GetReportProperty("ASSEMBLY_DEFAULT_PREFIX", ref prefixAssemblyOfObject);
                currentObject.GetReportProperty("PART_PREFIX", ref prefixPartOfObject);

                // check if profile is flat profile
                if (profileOfObject.StartsWith("FL") || profileOfObject.StartsWith("PL"))
                {
                    isFlatProfile = true;
                }

                // if name is contained in the list of parts to check and profile is a flat profile go in
                if (partNamesToCheck.Contains(nameOfObject) && isFlatProfile)
                {
                    // variables
                    string objectMaterial = "";
                    double objectWidth    = -1.0;
                    double objectHeight   = -1.0;
                    double objectLength   = -1.0;

                    currentObject.GetReportProperty("MATERIAL", ref objectMaterial);
                    currentObject.GetReportProperty("WIDTH", ref objectWidth);
                    currentObject.GetReportProperty("HEIGHT", ref objectHeight);
                    currentObject.GetReportProperty("LENGTH", ref objectLength);

                    // check if profile is in stock list
                    bool inStock = false;
                    inStock = FLCheck(profileList, objectMaterial, objectWidth, objectHeight, objectLength);

                    // check how profile should be changed
                    bool changeToFL = false;
                    bool changeToPL = false;
                    if (inStock && profileOfObject.StartsWith("PL"))
                    {
                        changeToFL = true;
                    }
                    if (!inStock && profileOfObject.StartsWith("FL"))
                    {
                        changeToPL = true;
                    }


                    // check how name should be changed
                    bool changeToFladstal = false;
                    bool changeToPlade    = false;

                    // this is used to change prefixes
                    bool changeToF = false;
                    bool changeToC = false;
                    if (partNamesToSwap.Contains(nameOfObject))
                    {
                        if (inStock && nameOfObject.Replace("(", "").Replace(")", "") == "Plade")
                        {
                            changeToFladstal = true;
                        }
                        if (!inStock && nameOfObject.Replace("(", "").Replace(")", "") == "Fladstål")
                        {
                            changeToPlade = true;
                        }
                        if (inStock && (prefixPartOfObject != "F" || prefixAssemblyOfObject != "f"))
                        {
                            changeToF = true;
                        }
                        if (!inStock && (prefixPartOfObject != "C" || prefixAssemblyOfObject != "c"))
                        {
                            changeToC = true;
                        }
                    }

                    // Functionality for changing the atributes is doubled for beams and plates.
                    // Could this be done in one clause?
                    Beam beam = SelectedObjects.Current as Beam;
                    if (beam != null)
                    {
                        if (changeToFL)
                        {
                            beam.Profile.ProfileString = "FL" + beam.Profile.ProfileString.ToString().Remove(0, 2);
                        }
                        if (changeToPL)
                        {
                            beam.Profile.ProfileString = "PL" + beam.Profile.ProfileString.ToString().Remove(0, 2);
                        }
                        if (changeToFladstal)
                        {
                            beam.Name = "Fladstål";
                        }
                        if (changeToF)
                        {
                            beam.AssemblyNumber.Prefix = "f";
                            beam.PartNumber.Prefix     = "F";
                        }
                        if (changeToPlade)
                        {
                            beam.Name = "Plade";
                        }
                        if (changeToC)
                        {
                            beam.AssemblyNumber.Prefix = "c";
                            beam.PartNumber.Prefix     = "C";
                        }

                        // add parts to the list of modified parts
                        if (changeToFL || changeToPL || changeToFladstal || changeToPlade || changeToC || changeToF)
                        {
                            partList.Add(beam);
                        }
                    }

                    ContourPlate plate = SelectedObjects.Current as ContourPlate;
                    if (plate != null)
                    {
                        if (changeToFL)
                        {
                            plate.Profile.ProfileString = "FL" + plate.Profile.ProfileString.ToString().Remove(0, 2);
                        }
                        if (changeToPL)
                        {
                            plate.Profile.ProfileString = "PL" + plate.Profile.ProfileString.ToString().Remove(0, 2);
                        }
                        if (changeToFladstal)
                        {
                            plate.Name = "Fladstål";
                        }
                        if (changeToF)
                        {
                            plate.AssemblyNumber.Prefix = "f";
                            plate.PartNumber.Prefix     = "F";
                        }
                        if (changeToPlade)
                        {
                            plate.Name = "Plade";
                        }
                        if (changeToC)
                        {
                            plate.AssemblyNumber.Prefix = "c";
                            plate.PartNumber.Prefix     = "C";
                        }

                        // add parts to the list of modified parts
                        if (changeToFL || changeToPL || changeToFladstal || changeToPlade)
                        {
                            partList.Add(plate);
                        }
                    }
                }
            }

            // 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 dialogResult = MessageBox.Show(new Form {
                    TopMost = true
                }, "Selected objects will be modified.", Variables.caption, MessageBoxButtons.OKCancel);
                if (dialogResult == DialogResult.OK)
                {
                    // 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;
                            if (beam != null && selObjEnum.Current.Identifier.ToString() == beam.Identifier.ToString())
                            {
                                if (!beam.Modify())
                                {
                                    errCount++;
                                }
                                else
                                {
                                    modCount++;
                                }
                            }

                            ContourPlate plate = part as ContourPlate;
                            if (plate != null && selObjEnum.Current.Identifier.ToString() == plate.Identifier.ToString())
                            {
                                if (!plate.Modify())
                                {
                                    errCount++;
                                }
                                else
                                {
                                    modCount++;
                                }
                            }
                        }
                    }
                    if (errCount != 0)
                    {
                        MessageBox.Show("Warning\n# of objects which didn't modify:\n" + errCount + "\n\n# of changed objects:\n" + modCount, Variables.caption);
                    }
                    else
                    {
                        MessageBox.Show("# of changed objects:\n" + modCount, Variables.caption);
                    }
                }
                else if (dialogResult == DialogResult.Cancel)
                {
                    return;
                }
            }
            else
            {
                MessageBox.Show("No parts to modifiy found.", Variables.caption);
            }
        }
Пример #30
0
 private void comboBox1_SelectedValueChanged(object sender, EventArgs e)
 {
     Drawing drawing = drawingHandler.GetActiveDrawing();
     if (drawing == null)
     {
         Tekla.Structures.Model.UI.ModelObjectSelector modelObjectSelector = new Tekla.Structures.Model.UI.ModelObjectSelector();
         ArrayList arrayObjectsSelected = GetModelObjectsByType(comboBox1.Text);
         if (arrayObjectsSelected.Count > 0)
             modelObjectSelector.Select(arrayObjectsSelected);
     }
     if (drawing != null)
     {
         ArrayList arrayObjectsSelected = GetDrawingObjectsByType(comboBox1.Text);
         if (arrayObjectsSelected.Count > 0)
             drawingHandler.GetDrawingObjectSelector().SelectObjects(arrayObjectsSelected, false);
     }
 }