public void TestSelectComponentsList(string modelName)
        {
            ModelDoc2   doc      = OpenSWDocument(modelName);
            AssemblyDoc assyDoc  = (AssemblyDoc)doc;
            LinkNode    baseNode = Serialization.LoadBaseNodeFromModel(SwApp, doc, out bool abortProcess);

            Assert.False(abortProcess);

            Link baseLink = baseNode.GetLink();
            List <Component2> componentsToSelect      = baseLink.SWComponents;
            HashSet <string>  componentsToSelectNames =
                new HashSet <string>(componentsToSelect.Select(component => component.Name2));

            Common.SelectComponents(doc, componentsToSelect, true);
            SelectionMgr selManager = doc.SelectionManager;

            // -1 is the Mark, set to negative one if it's not being used.
            int numSelected = selManager.GetSelectedObjectCount2(-1);

            Assert.Equal(componentsToSelect.Count, numSelected);

            for (int i = 0; i < selManager.GetSelectedObjectCount2(-1); i++)
            {
                // -1 is the Mark, set to negative one if it's not being used.
                Component2 comp = selManager.GetSelectedObjectsComponent4(i, -1);
                Assert.Contains(comp.Name2, componentsToSelectNames);
            }

            SwApp.CloseAllDocuments(true);
        }
Пример #2
0
        /// <summary>
        /// Run this function after this.Document is populated. It fills two ref vars with swDocumentTypes_e.
        /// </summary>
        /// <param name="d">The document type.</param>
        /// <param name="od">The top-level document type.</param>
        private void GetTypes(ref swDocumentTypes_e d, ref swDocumentTypes_e od)
        {
            swDocumentTypes_e docT     = (swDocumentTypes_e)Document.GetType();
            ModelDoc2         overDoc  = (ModelDoc2)_swApp.ActiveDoc;
            swDocumentTypes_e overDocT = (swDocumentTypes_e)overDoc.GetType();

            if ((docT != swDocumentTypes_e.swDocDRAWING && swSelMgr != null) && swSelMgr.GetSelectedObjectCount2(-1) > 0)
            {
                Component2 comp = (Component2)swSelMgr.GetSelectedObjectsComponent4(1, -1);
                if (comp != null)
                {
                    ModelDoc2 cmd = (ModelDoc2)comp.GetModelDoc2();
                    docT = (swDocumentTypes_e)cmd.GetType();
                    prop.GetPropertyData(comp);
                    comp = null;
                }
                else
                {
                    prop.GetPropertyData(Document);
                }
            }
            else
            {
                swSelMgr = null;
                prop.GetPropertyData(Document);
            }
            d  = docT;
            od = overDocT;
        }
        public void TestSelectComponentsLink(string modelName)
        {
            ModelDoc2   doc      = OpenSWDocument(modelName);
            AssemblyDoc assyDoc  = (AssemblyDoc)doc;
            LinkNode    baseNode = ConfigurationSerialization.LoadBaseNodeFromModel(doc, out bool abortProcess);

            Assert.False(abortProcess);

            Link baseLink = baseNode.RebuildLink();
            List <Component2> componentsToSelect = new List <Component2>();

            AddLinkComponents(baseLink, componentsToSelect);
            HashSet <string> componentsToSelectNames =
                new HashSet <string>(componentsToSelect.Select(component => component.Name2));

            CommonSwOperations.SelectComponents(doc, baseLink, true);
            SelectionMgr selManager  = doc.SelectionManager;
            int          numSelected = selManager.GetSelectedObjectCount2(-1);

            Assert.Equal(componentsToSelect.Count, numSelected);

            for (int i = 0; i < selManager.GetSelectedObjectCount2(-1); i++)
            {
                Component2 comp = selManager.GetSelectedObjectsComponent4(i, -1);
                Assert.Contains(comp.Name2, componentsToSelectNames);
            }

            SwApp.CloseAllDocuments(true);
        }
Пример #4
0
        public void OpenDrawing()
        {
            ModelDoc2 swModel = iSwApp.ActiveDoc;
            //SelectionMgr selMgr = new SelectionMgr();
            int        iErrors   = 0;
            int        iWarnings = 0;
            Component2 swComponent;
            String     swComponentPath;

            SelectionMgr selMgr = default(SelectionMgr);

            selMgr      = (SelectionMgr)swModel.SelectionManager;
            swComponent = selMgr.GetSelectedObjectsComponent4(1, -1);

            try
            {
                swComponentPath = swComponent.GetPathName();
            }
            catch (NullReferenceException)
            {
                swComponentPath = swModel.GetPathName();
                //swComponentPath = swComponent.GetPathName();
            }
            var    swDrawingArr = swComponentPath.Split('.');
            String swDrawPath   = swDrawingArr[0] + ".SLDDRW";

            iSwApp.OpenDoc6(swDrawPath, 3, 1, "", iErrors, iWarnings);

            //MessageBox.Show(swComponentPath.ToString());
        }