{"id":580,"date":"2020-03-26T15:40:00","date_gmt":"2020-03-26T07:40:00","guid":{"rendered":"http:\/\/localhost:8080\/?p=580"},"modified":"2020-03-26T15:40:00","modified_gmt":"2020-03-26T07:40:00","slug":"c-solidworks-%e4%ba%8c%e6%ac%a1%e5%bc%80%e5%8f%91-api-%e5%a6%82%e4%bd%95%e4%bf%ae%e6%94%b9%e8%8d%89%e5%9b%be%e9%87%8c%e9%9d%a2%e7%9a%84%e7%9b%b4%e7%ba%bf","status":"publish","type":"post","link":"https:\/\/blog.ke-zhi.com\/?p=580","title":{"rendered":"C# SolidWorks \u4e8c\u6b21\u5f00\u53d1 API &#8212;\u5982\u4f55\u4fee\u6539\u8349\u56fe\u91cc\u9762\u7684\u76f4\u7ebf"},"content":{"rendered":"<h1> <a href=\"https:\/\/www.cnblogs.com\/solidworksapi\/p\/12897436.html\" target=\"_blank\" rel=\"nofollow noopener\"> <span>C# SolidWorks \u4e8c\u6b21\u5f00\u53d1 API &#8212;\u5982\u4f55\u4fee\u6539\u8349\u56fe\u91cc\u9762\u7684\u76f4\u7ebf<\/span> <\/a> <\/h1>\n<p>&nbsp;\u6628\u5929\u6709\u7f51\u53cb\u60f3\u77e5\u9053\u600e\u4e48\u4fee\u6539\u8349\u56fe\u7684\u5185\u5bb9\uff0c\u4eca\u5929\u6765\u5e26\u7740\u627e\u4e00\u627e\u5982\u4f55\u89e3\u51b3\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/img-blog.csdnimg.cn\/20200326135404695.png\" class=\"aligncenter\"><\/p>\n<p>\u5728\u4e4b\u524d\u6253\u5f00\u548c\u521b\u5efa\u90a3\u4e2a\u547d\u4ee4\u91cc\u9762\u6211\u5199\u8fc7\u5982\u4e0b\u4ee3\u7801 \uff1a<\/p>\n<pre><code>                    \/\/\u9009\u62e9\u5bf9\u5e94\u7684\u8349\u56fe\u57fa\u51c6\u9762\n                    bool boolstatus = swModel.Extension.SelectByID2(\"Plane1\", \"PLANE\", 0, 0, 0, false, 0, null, 0);\n\n                    \/\/\u521b\u5efa\u4e00\u4e2a2d\u8349\u56fe\n                    swModel.SketchManager.InsertSketch(true);\n\n                    \/\/\u753b\u4e00\u6761\u7ebf \u957f\u5ea6100mm  (solidworks \u4e2d\u7cfb\u7edf\u5355\u4f4d\u662f\u7c73,\u6240\u4ee5\u8fd9\u91cc\u51990.1)\n                    swModel.SketchManager.CreateLine(0, 0, 0, 0, 0.1, 0);\n\n                    \/\/\u5173\u95ed\u8349\u56fe\n                    swModel.SketchManager.InsertSketch(true);<\/code><\/pre>\n<p>\u8fd9\u91cc\u9762\u77e5\u9053\u4e86\u8349\u56fe\u7ba1\u7406\u5668\u662fSketchManager.<\/p>\n<p>\u6211\u4eec\u53bbAPI\u5e2e\u52a9\u91cc\u9762\u67e5\u627eSketchManager.\u5f88\u5bb9\u6613\u5c31\u80fd\u627e\u5230\u8fd9\u91cc\u6709\u4e2a\u5b98\u65b9\u793a\u4f8b\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/img-blog.csdnimg.cn\/20200326140341369.png?x-oss-process=image\/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3plbmdxaDAzMTQ=,size_16,color_FFFFFF,t_70\" class=\"aligncenter\"><\/p>\n<p>&nbsp;<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/img-blog.csdnimg.cn\/20200326141010246.png?x-oss-process=image\/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3plbmdxaDAzMTQ=,size_16,color_FFFFFF,t_70\" class=\"aligncenter\"><\/p>\n<p>\u8fd9\u91cc\u867d\u7136\u662fVBA\u7684\uff0c\u4f46\u662f\u53ef\u4ee5\u5927\u6982\u77e5\u9053\u5927\u4f53\u6b65\u9aa4\uff0c\u53c2\u8003\u8fd9\u4e2a\u5c31\u80fd\u77e5\u9053\u5982\u4f55\u8bfb\u53d6\u8fd9\u4e9b\u4fe1\u606f\u4e86\uff0c\u53ef\u4ee5\u5148\u628a\u8fd9\u4e2a\u4f8b\u5b50\u5f04\u61c2\u3002\u518d\u6765\u8003\u8651\u600e\u4e48\u4fee\u6539\uff0c\u6211\u4e5f\u5c31\u5199\u51e0\u884c\u7b80\u5355\u7684\u4ee3\u7801\uff0c\u628a\u4e4b\u524d \u6211\u5728\u56fe\u4e2d\u753b\u7684\u4e00\u6761\u76f4\u7ebf\u957f\u5ea6 \u548c\u4f4d\u7f6e\u4fee\u6539\u6389\u3002<\/p>\n<p>\u9ed8\u8ba4\u5f53\u524d\u72b6\u6001\uff1a<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/img-blog.csdnimg.cn\/20200326141615826.png?x-oss-process=image\/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3plbmdxaDAzMTQ=,size_16,color_FFFFFF,t_70\" class=\"aligncenter\"><\/p>\n<p>\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<pre><code>        private void btnCreateSketch_Click(object sender, EventArgs e)\n        {\n            \/\/\u5982\u679c\u6ca1\u6709\u6253\u5f00\u6587\u4ef6\uff0c\u8bf7\u6267\u884c\u6253\u5f00\u548c\u521b\u5efa\u7684\u64cd\u4f5c\uff1a\n            \/\/BtnOpenAndNew_Click(null, null);\n\n            \/\/\u8fde\u63a5\u5230Solidworks\n            ISldWorks swApp = Utility.ConnectToSolidWorks();\n\n            ModelDoc2 swModel = (ModelDoc2)swApp.ActiveDoc;\n\n            \/\/\u5b9a\u4e49\u8349\u56fe\u7ba1\u7406\u5668\n            SketchManager sketchManager = swModel.SketchManager;\n\n            \/\/\u6309\u540d\u5b57\u9009\u62e9\u8349\u56fe\n            bool boolstatus = swModel.Extension.SelectByID2(\"Sketch1\", \"SKETCH\", 0, 0, 0, false, 0, null, 0);\n\n            if (boolstatus == true)\n            {\n                \/\/\u7f16\u8f91\u8349\u56fe\n                sketchManager.InsertSketch(false);\n                \/\/\u83b7\u53d6\u5f53\u524d\u8349\u56fe\uff0c\u5f53\u83b7\u53d6\u8349\u56fe\u4e2d\u7684Segment\u5bf9\u8c61\n                Sketch sketch = swModel.GetActiveSketch2();\n                object[] sketchSegments = sketch.GetSketchSegments();\n\n                if (sketchSegments != null)\n                {\n                    \/\/\u904d\u5386\n                    foreach (var skSeg in sketchSegments)\n                    {\n                        SketchSegment sketchSegment = (SketchSegment)skSeg;\n\n                        \/\/\u5224\u65ad\u662f\u76f4\u7ebf\u65f6\u6267\u884c\n                        if (sketchSegment.GetType() == (int)swSketchSegments_e.swSketchLINE)\n                        {\n                            SketchLine sketchLine = (SketchLine)sketchSegment;\n                            SketchPoint sketchPointStart = sketchLine.GetStartPoint2();\n                            SketchPoint sketchPointEnd = sketchLine.GetEndPoint2();\n\n                            \/\/\u8fd9\u91cc\u663e\u793a\u5f39\u51fa\u5750\u6807\uff0c\u5355\u4f4d\u9ed8\u8ba4\u662f\u7c73\n                            MessageBox.Show(sketchPointStart.X.ToString() + \",\" + sketchPointStart.Y.ToString());\n                            MessageBox.Show(sketchPointEnd.X.ToString() + \",\" + sketchPointEnd.Y.ToString());\n\n                            SelectionMgr swSelMgr = swModel.SelectionManager;\n\n                            \/\/\u5b9a\u4e49\u9009\u62e9\u6570\u636e\n                            SelectData swSelData = swSelMgr.CreateSelectData();\n\n                            \/\/\u9009\u62e9\u6b64\u76f4\u7ebf\n\n                            sketchSegment.Select4(false, swSelData);\n\n                            \/\/\u5220\u9664\u5f53\u524d\u7684\u7ea6\u675f\u5173\u7cfb\n                            swModel.SketchConstraintsDelAll();\n\n                            \/\/\u4e0b\u5728\u6211\u4eec\u6765\u4fee\u6539\u5750\u6807\n                            sketchPointStart.X = 0.05;\n                            sketchPointStart.Y = 0.04;\n\n                            sketchPointEnd.X = 0.2;\n                            sketchPointEnd.Y = 0.2;\n                        }\n                    }\n                }\n\n                \/\/\u9000\u51fa\u8349\u56fe\n                sketchManager.InsertSketch(true);\n            }\n        }\n<\/code><\/pre>\n<p>\u6267\u884c\u8fc7\u540e\uff0c\u6587\u4ef6\u4e2d\u7684\u8349\u56fe\u53d8\u6210\u4e86\uff1a<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/img-blog.csdnimg.cn\/20200326153751421.png?x-oss-process=image\/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3plbmdxaDAzMTQ=,size_16,color_FFFFFF,t_70\" class=\"aligncenter\"><\/p>\n<p>\u8fd9\u91cc\u8bb2\u89e3\u7684\u5c31\u662f\u4e00\u4e2a\u601d\u8def\uff0c\u5927\u5bb6\u5e94\u8be5\u80fd\u770b\u660e\u767d\u5427\u3002<\/p>\n<p>\u5177\u4f53\u7684\u4ee3\u7801\u53ef\u4ee5\u53bb\u6211\u7684\u7801\u4e91\u6216\u8005github\u4e0b\u8f7d\uff0c\u6b22\u8fce\u5927\u5bb6\u63d0\u95ee\u3002<\/p>\n<p>&nbsp;<\/p>\n<p>          posted @<br \/>\n<span>2020-03-26 15:40<\/span>&nbsp;<br \/>\n<a href=\"https:\/\/www.cnblogs.com\/solidworksapi\/\" target=\"_blank\" rel=\"nofollow noopener\">painezeng<\/a>&nbsp; \u9605\u8bfb(<br \/>\n<span>174<\/span>)&nbsp; \u8bc4\u8bba(<br \/>\n<span>0<\/span>)&nbsp;<br \/>\n<a href=\"https:\/\/i.cnblogs.com\/EditPosts.aspx?postid=12897436\" 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;\u5982\u4f55\u4fee\u6539\u8349\u56fe\u91cc\u9762\u7684\u76f4\u7ebf &nbsp;\u6628\u5929\u6709\u7f51\u53cb\u60f3\u77e5 [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":581,"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-580","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-solidworks-","category-solidworks","tag-api","tag-solidworks","tag-8"],"views":161,"_links":{"self":[{"href":"https:\/\/blog.ke-zhi.com\/index.php?rest_route=\/wp\/v2\/posts\/580","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=580"}],"version-history":[{"count":0,"href":"https:\/\/blog.ke-zhi.com\/index.php?rest_route=\/wp\/v2\/posts\/580\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.ke-zhi.com\/index.php?rest_route=\/wp\/v2\/media\/581"}],"wp:attachment":[{"href":"https:\/\/blog.ke-zhi.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=580"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.ke-zhi.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=580"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.ke-zhi.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=580"},{"taxonomy":"series","embeddable":true,"href":"https:\/\/blog.ke-zhi.com\/index.php?rest_route=%2Fwp%2Fv2%2Fseries&post=580"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}