コード例 #1
0
        private void GetChildren(JSolidworksAsemble _JswDoc)
        {
            //this.Parts.Add((JSolidworksAsemble)_JswDoc); //先将此文件加入到子零部件列表中
            //如果是装配体
            if (_JswDoc.swDoc == null)
            {
                _JswDoc.Load();
            }
            Configuration swConf = (Configuration)_JswDoc.swDoc.GetActiveConfiguration();

            if (swConf == null)
            {
                return;
            }
            Component2 swRootComp = (Component2)swConf.GetRootComponent();

            if (swRootComp == null)
            {
                return;
            }
            else
            {
                object[] Children_List = swRootComp.GetChildren();
                foreach (object _doc in Children_List)
                {
                    ModelDoc2 t_doc = ((Component2)_doc).GetModelDoc2();
                    if (t_doc.GetType() == (int)swDocumentTypes_e.swDocPART)
                    {
                        //子件是
                        string          _Path = t_doc.GetPathName();
                        JSolidworksPart JPart = new JSolidworksPart(t_doc.GetPathName());
                        JPart.Load();
                        _JswDoc.Parts.Add(JPart);
                    }
                    else
                    {
                        if (t_doc.GetType() == (int)swDocumentTypes_e.swDocASSEMBLY)
                        {
                            JSolidworksAsemble JPart = new JSolidworksAsemble(t_doc.GetPathName());
                            JPart.Load();
                            _JswDoc.Parts.Add(JPart);
                        }
                    }
                }
            }
            return;
        }
コード例 #2
0
        public static void SetAttrById(string id, string AttrName, string AttrValue, object swDoc, bool isDeep)
        {
            //指定一个零件的ID和母文件,即可对其的属性进行修改。
            switch (swDoc.GetType().ToString())
            {
            case "JSolidworks.JSolidworksPart":
                JSolidworksPart JPart = swDoc as JSolidworksPart;
                if (JPart.GetAttr("id") == id)
                {
                    JPart.SetAttr(AttrName, AttrValue);
                }
                break;

            case "JSolidworks.JSolidworksAsemble":
                JSolidworksAsemble JAsemble = swDoc as JSolidworksAsemble;
                if (JAsemble.GetAttr("id") == id)
                {
                    JAsemble.SetAttr(AttrName, AttrValue);
                }
                else
                {
                    if (isDeep)
                    {
                        if (JAsemble.Parts.Count > 0)
                        {
                            foreach (object _swDoc in JAsemble.Parts)
                            {
                                SetAttrById(id, AttrName, AttrValue, _swDoc, isDeep);
                            }
                        }
                    }
                }
                break;

            default:
                break;
            }
        }