Пример #1
0
                public static ExternalFileReferences Get(SldWorks swApp)
                {
                    try
                    {
                        var               obj                = new ExternalFileReferences();
                        ModelDoc2         swModel            = default(ModelDoc2);
                        ModelDocExtension swModDocExt        = default(ModelDocExtension);
                        SelectionMgr      swSelMgr           = default(SelectionMgr);
                        Feature           swFeat             = default(Feature);
                        Component2        swComp             = default(Component2);
                        object            vModelPathName     = null;
                        object            vComponentPathName = null;
                        object            vFeature           = null;
                        object            vDataType          = null;
                        object            vStatus            = null;
                        object            vRefEntity         = null;
                        object            vFeatComp          = null;
                        int               nConfigOpt         = 0;
                        string            sConfigName        = null;
                        int               nRefCount          = 0;
                        int               nSelType           = 0;
                        int               i = 0;

                        swModel  = (ModelDoc2)swApp.ActiveDoc;
                        swSelMgr = (SelectionMgr)swModel.SelectionManager;

                        swModDocExt = (ModelDocExtension)swModel.Extension;
                        nSelType    = swSelMgr.GetSelectedObjectType3(1, -1);

                        switch (nSelType)
                        {
                        // Selected component in an assembly document
                        case (int)swSelectType_e.swSelCOMPONENTS:
                            swComp    = (Component2)swSelMgr.GetSelectedObjectsComponent3(1, -1);
                            nRefCount = swComp.ListExternalFileReferencesCount();
                            swComp.ListExternalFileReferences2(out vModelPathName, out vComponentPathName, out vFeature, out vDataType, out vStatus, out vRefEntity, out vFeatComp, out nConfigOpt, out sConfigName);

                            swModel = (ModelDoc2)swComp.GetModelDoc2();

                            break;

                        // Selected feature in a part or assembly document
                        case (int)swSelectType_e.swSelBODYFEATURES:
                        case (int)swSelectType_e.swSelSKETCHES:
                            swFeat    = (Feature)swSelMgr.GetSelectedObject6(1, -1);
                            nRefCount = swFeat.ListExternalFileReferencesCount();
                            swFeat.ListExternalFileReferences2(out vModelPathName, out vComponentPathName, out vFeature, out vDataType, out vStatus, out vRefEntity, out vFeatComp, out nConfigOpt, out sConfigName);

                            break;

                        // Part document only
                        default:
                            nRefCount = swModDocExt.ListExternalFileReferencesCount();
                            swModDocExt.ListExternalFileReferences(out vModelPathName, out vComponentPathName, out vFeature, out vDataType, out vStatus, out vRefEntity, out vFeatComp, out nConfigOpt, out sConfigName);

                            break;
                        }

                        //Debug.Print("Model name = " + swModel.GetPathName());

                        if (nRefCount >= 1)
                        {
                            object[] ModelPathName     = new object[nRefCount - 1];
                            object[] ComponentPathName = new object[nRefCount - 1];
                            object[] Feature           = new object[nRefCount - 1];
                            object[] DataType          = new object[nRefCount - 1];
                            int[]    Status            = new int[nRefCount - 1];
                            object[] RefEntity         = new object[nRefCount - 1];
                            object[] FeatComp          = new object[nRefCount - 1];

                            ModelPathName     = (object[])vModelPathName;
                            ComponentPathName = (object[])vComponentPathName;
                            Feature           = (object[])vFeature;
                            DataType          = (object[])vDataType;
                            Status            = (int[])vStatus;
                            RefEntity         = (object[])vRefEntity;
                            FeatComp          = (object[])vFeatComp;

                            for (i = 0; i <= nRefCount - 1; i++)
                            {
                                obj.ModelPathName     = ModelPathName[i].ToString();
                                obj.ComponentPathName = ComponentPathName[i].ToString();
                                obj.Feature           = Feature[i].ToString();
                                obj.DataType          = DataType[i].ToString();
                                obj.Status            = Status[i].ToString();
                                obj.ReferenceEntity   = RefEntity[i].ToString();
                                obj.FeatureComponent  = FeatComp[i].ToString();
                                obj.ConfigOption      = nConfigOpt.ToString();
                                obj.ConfigName        = sConfigName?.ToString();
                            }
                        }
                        return(obj);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.StackTrace);
                        return(null);
                    }
                }