{"id":676,"date":"2019-09-10T16:47:00","date_gmt":"2019-09-10T08:47:00","guid":{"rendered":"http:\/\/localhost:8080\/?p=676"},"modified":"2019-09-10T16:47:00","modified_gmt":"2019-09-10T08:47:00","slug":"c-solidworks-%e4%ba%8c%e6%ac%a1%e5%bc%80%e5%8f%91-api-%e8%af%bb%e5%8f%96%e9%9b%b6%e4%bb%b6%e7%9b%b8%e5%85%b3%e5%b1%9e%e6%80%a7","status":"publish","type":"post","link":"https:\/\/blog.ke-zhi.com\/?p=676","title":{"rendered":"C# SolidWorks \u4e8c\u6b21\u5f00\u53d1 API &#8212;\u8bfb\u53d6\u96f6\u4ef6\u76f8\u5173\u5c5e\u6027"},"content":{"rendered":"<h1> <a href=\"https:\/\/www.cnblogs.com\/solidworksapi\/p\/12897487.html\" target=\"_blank\" rel=\"nofollow noopener\"> <span>C# SolidWorks \u4e8c\u6b21\u5f00\u53d1 API &#8212;\u8bfb\u53d6\u96f6\u4ef6\u76f8\u5173\u5c5e\u6027<\/span> <\/a> <\/h1>\n<h1>\u5982\u4f55\u8bfb\u53d6\u96f6\u4ef6\u76f8\u5173\u5c5e\u6027<\/h1>\n<hr>\n<p>\u8fd9\u4e00\u7bc7\u770b\u4e0b\u5982\u4f55\u8bfb\u53d6\u5c5e\u6027\uff1a<\/p>\n<p><img decoding=\"async\" class=\"aligncenter\" src=\"https:\/\/img-blog.csdnimg.cn\/20190910164524467.png?x-oss-process=image\/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3plbmdxaDAzMTQ=,size_16,color_FFFFFF,t_70\"><\/p>\n<p><img decoding=\"async\" class=\"aligncenter\" src=\"https:\/\/img-blog.csdnimg.cn\/20190910164559850.png?x-oss-process=image\/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3plbmdxaDAzMTQ=,size_16,color_FFFFFF,t_70\"><\/p>\n<p>\u76f4\u63a5\u4e0a\u4ee3\u7801\uff1a<\/p>\n<p><img decoding=\"async\" class=\"aligncenter\" src=\"https:\/\/img-blog.csdnimg.cn\/20190910164150879.png?x-oss-process=image\/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3plbmdxaDAzMTQ=,size_16,color_FFFFFF,t_70\"><\/p>\n<p>\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<pre><code>      private void BtnGetPartData_Click(object sender, EventArgs e)\n        {\n            \/\/\u8bf7\u5148\u6253\u5f00\u96f6\u4ef6: ..\\TemplateModel\\clamp1.sldprt\n\n            ISldWorks swApp = Utility.ConnectToSolidWorks();\n\n            if (swApp != null)\n            {\n                ModelDoc2 swModel = (ModelDoc2)swApp.ActiveDoc; \/\/\u5f53\u524d\u96f6\u4ef6\n\n                \/\/\u83b7\u53d6\u901a\u7528\u5c5e\u6027\u503c\n                string project = swModel.GetCustomInfoValue(\"\", \"Project\");\n\n                swModel.DeleteCustomInfo2(\"\", \"Qty\"); \/\/\u5220\u9664\u6307\u5b9a\u9879\n                swModel.AddCustomInfo3(\"\", \"Qty\", 30, \"1\"); \/\/\u589e\u52a0\u901a\u7528\u5c5e\u6027\u503c\n\n                var ConfigNames = (string[])swModel.GetConfigurationNames(); \/\/\u6240\u6709\u914d\u7f6e\u540d\u79f0\n\n                Configuration swConfig = null;\n\n                foreach (var configName in ConfigNames)\/\/\u904d\u5386\u6240\u6709\u914d\u7f6e\n                {\n                    swConfig = (Configuration)swModel.GetConfigurationByName(configName);\n\n                    var manger = swModel.Extension.CustomPropertyManager[configName];\n                    \/\/\u5220\u9664\u5f53\u524d\u914d\u7f6e\u4e2d\u7684\u5c5e\u6027\n                    manger.Delete2(\"Code\");\n                    \/\/\u589e\u52a0\u4e00\u4e2a\u5c5e\u6027\u5230\u4e9b\u914d\u7f6e\n                    manger.Add3(\"Code\", (int)swCustomInfoType_e.swCustomInfoText, \"A-\" + configName, (int)swCustomPropertyAddOption_e.swCustomPropertyReplaceValue);\n                    \/\/\u83b7\u53d6\u6b64\u914d\u7f6e\u4e2d\u7684Code\u5c5e\u6027\n                    string tempCode = manger.Get(\"Code\");\n                    \/\/\u83b7\u53d6\u6b64\u914d\u7f6e\u4e2d\u7684Description\u5c5e\u6027\n\n                    var tempDesc = manger.Get(\"Description\");\n                    Debug.Print(\"  Name of configuration  ---&gt; \" + configName + \" Desc.=\" + tempCode);\n                }\n            }\n            else\n            {\n                MessageBox.Show(\"Please open a part first.\");\n            }\n        }\n  <\/code><\/pre>\n<p>\u589e\u52a0\u4e00\u4e2a\u4fe1\u606f\uff0c\u8bfb\u53d6summy\u91cc\u9762\u7684\u4fe1\u606f\u9700\u8981\u7528<\/p>\n<pre>swModel.SummaryInfo((int)swSummInfoField_e.swSumInfoComment)\n<\/pre>\n<p><img decoding=\"async\" class=\"aligncenter\" src=\"https:\/\/img-blog.csdnimg.cn\/20200107105916975.png?x-oss-process=image\/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3plbmdxaDAzMTQ=,size_16,color_FFFFFF,t_70\"><\/p>\n<p>          posted @<br \/>\n<span>2019-09-10 16:47<\/span>&nbsp;<br \/>\n<a href=\"https:\/\/www.cnblogs.com\/solidworksapi\/\" target=\"_blank\" rel=\"nofollow noopener\">painezeng<\/a>&nbsp; \u9605\u8bfb(<br \/>\n<span>286<\/span>)&nbsp; \u8bc4\u8bba(<br \/>\n<span>0<\/span>)&nbsp;<br \/>\n<a href=\"https:\/\/i.cnblogs.com\/EditPosts.aspx?postid=12897487\" rel=\"nofollow noopener\" target=\"_blank\">\u7f16\u8f91<\/a>&nbsp;<br \/>\n<a href=\"\" target=\"_blank\" rel=\"nofollow noopener\">\u6536\u85cf<\/a>&nbsp;<br \/>\n<a href=\"\" target=\"_blank\" rel=\"nofollow noopener\">\u4e3e\u62a5<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>C# SolidWorks \u4e8c\u6b21\u5f00\u53d1 API &#8212;\u8bfb\u53d6\u96f6\u4ef6\u76f8\u5173\u5c5e\u6027 \u5982\u4f55\u8bfb\u53d6\u96f6\u4ef6\u76f8\u5173\u5c5e\u6027 \u8fd9\u4e00\u7bc7\u770b\u4e0b [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":677,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[4,5],"tags":[7,6,8],"series":[],"class_list":["post-676","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-solidworks-","category-solidworks","tag-api","tag-solidworks","tag-8"],"views":170,"_links":{"self":[{"href":"https:\/\/blog.ke-zhi.com\/index.php?rest_route=\/wp\/v2\/posts\/676","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.ke-zhi.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.ke-zhi.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.ke-zhi.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.ke-zhi.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=676"}],"version-history":[{"count":0,"href":"https:\/\/blog.ke-zhi.com\/index.php?rest_route=\/wp\/v2\/posts\/676\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.ke-zhi.com\/index.php?rest_route=\/wp\/v2\/media\/677"}],"wp:attachment":[{"href":"https:\/\/blog.ke-zhi.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=676"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.ke-zhi.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=676"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.ke-zhi.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=676"},{"taxonomy":"series","embeddable":true,"href":"https:\/\/blog.ke-zhi.com\/index.php?rest_route=%2Fwp%2Fv2%2Fseries&post=676"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}