コード例 #1
0
 public void CopyProperties()
 {
     try
     {
         parentDoc = (IModelDoc2)swApp.IActiveDoc;
         var parentItem = ExternalFileReferences.Get(swApp);
         childDoc = swApp.OpenDoc6(parentItem.ModelPathName, (int)swDocumentTypes_e.swDocPART,
                                   (int)swOpenDocOptions_e.swOpenDocOptions_Silent, "", 0, 0);
         swApp.ActivateDoc(parentDoc.GetTitle());
         parentDoc.SelectByName(0, parentItem.ModelPathName);
         parentItem = ExternalFileReferences.Get(swApp);
         PartProperties.AddAll(swApp, (ModelDoc2)parentDoc, PartProperties.GetAll(swApp, childDoc, ExternalFileReferences.Get(swApp).ConfigName));
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
コード例 #2
0
            public void CopyProperties()
            {
                try
                {
                    parentDoc = (IModelDoc2)swApp.IActiveDoc;
                    var parentItem = ExternalFileReferences.Get(swApp);

                    childDoc = swApp.OpenDoc6(parentItem.ModelPathName, (int)swDocumentTypes_e.swDocPART,
                                              (int)swOpenDocOptions_e.swOpenDocOptions_Silent, "", 0, 0);
                    swApp.ActivateDoc(parentDoc.GetTitle());
                    var props = PartProperties.GetAll(swApp, childDoc, ExternalFileReferences.Get(swApp).ConfigName);
                    //foreach (var item in props)
                    //{
                    //    MessageBox.Show(item.Key + " - " + item.Value, "Свойство заготовки");
                    //}
                    PartProperties.AddAll(swApp, (ModelDoc2)parentDoc, props);
                }
                catch (Exception)
                {
                    throw;
                }
            }
コード例 #3
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);
                        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               i = 0;

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

                        swModDocExt = (ModelDocExtension)swModel.Extension;

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


                        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.Message);
                        return(null);
                    }
                }
コード例 #4
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);
                    }
                }