{"id":647,"date":"2019-09-30T12:54:00","date_gmt":"2019-09-30T04:54:00","guid":{"rendered":"http:\/\/localhost:8080\/?p=647"},"modified":"2019-09-30T12:54:00","modified_gmt":"2019-09-30T04:54:00","slug":"c-solidworks-%e4%ba%8c%e6%ac%a1%e5%bc%80%e5%8f%91-api-%e9%81%8d%e5%8e%86%e8%8d%89%e5%9b%be","status":"publish","type":"post","link":"https:\/\/blog.ke-zhi.com\/?p=647","title":{"rendered":"C# SolidWorks \u4e8c\u6b21\u5f00\u53d1 API&#8212;\u904d\u5386\u8349\u56fe"},"content":{"rendered":"<h1> <a href=\"https:\/\/www.cnblogs.com\/solidworksapi\/p\/12897473.html\" target=\"_blank\" rel=\"nofollow noopener\"> <span>C# SolidWorks \u4e8c\u6b21\u5f00\u53d1 API&#8212;\u904d\u5386\u8349\u56fe<\/span> <\/a> <\/h1>\n<p><img decoding=\"async\" class=\"aligncenter\" src=\"https:\/\/img-blog.csdnimg.cn\/20190930125153194.png?x-oss-process=image\/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3plbmdxaDAzMTQ=,size_16,color_FFFFFF,t_70\"><\/p>\n<p>\u4ee3\u7801:<\/p>\n<p>\u8fd9\u91cc\u793a\u610f\u83b7\u53d6\u8349\u56fe\u4e2d\u7ebf\u6bb5\u7684\u603b\u957f:<\/p>\n<p><img decoding=\"async\" class=\"aligncenter\" src=\"https:\/\/img-blog.csdnimg.cn\/20190930125317966.png?x-oss-process=image\/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3plbmdxaDAzMTQ=,size_16,color_FFFFFF,t_70\"><\/p>\n<pre><code>private void Btn_T_sketchsegment_Click(object sender, EventArgs e)\n        {\n            ISldWorks swApp = Utility.ConnectToSolidWorks();\n\n            ModelDoc2 swModel = default(ModelDoc2);\n            ModelDocExtension swModelDocExt = default(ModelDocExtension);\n            SelectionMgr swSelMgr = default(SelectionMgr);\n            Feature swFeature = default(Feature);\n            string fileName = null;\n            bool status = false;\n            int errors = 0;\n            int warnings = 0;\n\n            \/\/\u6253\u5f00\u6587\u4ef6\n            fileName = \"C:\\\\Users\\\\Public\\\\Documents\\\\SOLIDWORKS\\\\SOLIDWORKS 2018\\\\samples\\\\tutorial\\\\tolanalyst\\\\offset\\\\top_plate.sldprt\";\n            swModel = (ModelDoc2)swApp.OpenDoc6(fileName, (int)swDocumentTypes_e.swDocPART, (int)swOpenDocOptions_e.swOpenDocOptions_Silent, \"\", ref errors, ref warnings);\n\n            swModelDocExt = (ModelDocExtension)swModel.Extension;\n\n            \/\/\u9009\u4e2d\u8349\u56fe\n            status = swModelDocExt.SelectByID2(\"Sketch1\", \"SKETCH\", 0, 0, 0, false, 0, null, 0);\n\n            swSelMgr = (SelectionMgr)swModel.SelectionManager;\n            \/\/\u8f6c\u6362\n            swFeature = (Feature)swSelMgr.GetSelectedObject6(1, -1);\n            \/\/\u8fdb\u5165\u7f16\u8f91\u8349\u56fe\n            swModel.EditSketch();\n            \/\/\u83b7\u53d6\u8349\u56fe\u4e2d\u7684\u6240\u6709\u7ebf\n            object[] vSketchSeg = (object[])swFeature.GetSpecificFeature2().GetSketchSegments();\n\n            SketchSegment swSketchSeg;\n            double totalLenth = 0;\n            foreach (var tempSeg in vSketchSeg)\n            {\n                swSketchSeg = (SketchSegment)tempSeg;\n                \/\/\u8fd9\u91cc\u5224\u65ad \u4e0d\u662f\u6587\u672c,\u5e76\u4e14\u4e0d\u662f\u4e2d\u5fc3\u7ebf \u5219\u52a0\u5165\u957f\u5ea6\n                if (swSketchSeg.GetType() != (int)swSketchSegments_e.swSketchTEXT &amp;&amp; swSketchSeg.ConstructionGeometry == false)\n                {\n                    totalLenth = totalLenth + swSketchSeg.GetLength();\n                }\n            }\n\n            swModel.EditSketch();\n            \/\/\u663e\u793a\u603b\u957f\n            swApp.SendMsgToUser(\"Total Length:\" + totalLenth * 1000);\n        }<\/code><\/pre>\n<p>&nbsp;<\/p>\n<p>          posted @<br \/>\n<span>2019-09-30 12:54<\/span>&nbsp;<br \/>\n<a href=\"https:\/\/www.cnblogs.com\/solidworksapi\/\" target=\"_blank\" rel=\"nofollow noopener\">painezeng<\/a>&nbsp; \u9605\u8bfb(<br \/>\n<span>131<\/span>)&nbsp; \u8bc4\u8bba(<br \/>\n<span>0<\/span>)&nbsp;<br \/>\n<a href=\"https:\/\/i.cnblogs.com\/EditPosts.aspx?postid=12897473\" 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;\u904d\u5386\u8349\u56fe \u4ee3\u7801: \u8fd9\u91cc\u793a\u610f\u83b7\u53d6\u8349\u56fe\u4e2d\u7ebf\u6bb5\u7684\u603b\u957f: p [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":648,"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-647","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-solidworks-","category-solidworks","tag-api","tag-solidworks","tag-8"],"views":186,"_links":{"self":[{"href":"https:\/\/blog.ke-zhi.com\/index.php?rest_route=\/wp\/v2\/posts\/647","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=647"}],"version-history":[{"count":0,"href":"https:\/\/blog.ke-zhi.com\/index.php?rest_route=\/wp\/v2\/posts\/647\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.ke-zhi.com\/index.php?rest_route=\/wp\/v2\/media\/648"}],"wp:attachment":[{"href":"https:\/\/blog.ke-zhi.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=647"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.ke-zhi.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=647"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.ke-zhi.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=647"},{"taxonomy":"series","embeddable":true,"href":"https:\/\/blog.ke-zhi.com\/index.php?rest_route=%2Fwp%2Fv2%2Fseries&post=647"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}