在SW的工程图中,给“半圆”标十字中心线是个老在难的问题,用过的同学都知道,总是有一条“长长的尾巴”,笨小编每次被它搞的一点脾气都没有。。。文章源自 solidworks教程网 http://gocae.comsolidworks教程网-http://gocae.com/1627.html
文章源自 solidworks教程网 http://gocae.comsolidworks教程网-http://gocae.com/1627.html
但是办法总是有的,世界上总是有牛人的存在,用solidworks“宏”就可以自动成半圆的“十字中心线”,具体的操作方法如下:文章源自 solidworks教程网 http://gocae.comsolidworks教程网-http://gocae.com/1627.html
1. 准备好“宏”的代码
- Sub main()
- Set swApp = Application.SldWorks
- Set DrawingDoc = swApp.ActiveDoc
- If DrawingDoc.GetType <> 3 Then Exit Sub
- Set SelMgr = DrawingDoc.SelectionManager
- If SelMgr.GetSelectedObjectType2(1) <> 12 Then Exit Sub
- Set swview = SelMgr.GetSelectedObjectsDrawingView(1)
- Set swDrawComp = swview.RootDrawingComponent
- DrawingDoc.ActivateView swDrawComp.View.GetName2
- Set Part = swview.ReferencedDocument
- Set FeatObj = Part.FirstFeature
- FeatObjFeatObjFeatObjname = FeatObj.GetTypeName
- While FeatObjname <> "OriginProfileFeature"
- Set FeatObjFeatObjFeatObj = FeatObj.GetNextFeature
- FeatObjFeatObjFeatObjname = FeatObj.GetTypeName
- Wend
- Featname = FeatObj.Name
- ViewOutlines = swview.GetOutline
- ViewCXform = swview.GetXform
- ViewXform = swview.GetViewXform
- Hp1x = (ViewOutlines(0) - ViewCXform(0)) / ViewXform(12)
- Hp1y = ((ViewOutlines(1) + ViewOutlines(3)) / 2 - ViewCXform(1)) / ViewXform(12)
- Hp2x = (ViewOutlines(2) - ViewCXform(0)) / ViewXform(12)
- Hp2y = Hp1y
- Vp1x = ((ViewOutlines(0) + ViewOutlines(2)) / 2 - ViewCXform(0)) / ViewXform(12)
- Vp1y = (ViewOutlines(3) - ViewCXform(1)) / ViewXform(12)
- Vp2x = Vp1x
- Vp2y = (ViewOutlines(1) - ViewCXform(1)) / ViewXform(12)
- DrawingDoc.SetAddToDB (True)
- Set SkLineH = DrawingDoc.SketchManager.CreateCenterLine(Hp1x, Hp1y, 0, Hp2x, Hp2y, 0)
- DrawingDoc.SketchAddConstraints "sgHORIZONTAL2D"
- boolstatus = DrawingDoc.Extension.SelectByID2("Point1@" & Featname & "@" & swDrawComp.Name & "@" & swDrawComp.View.GetName2, "EXTSKETCHPOINT", 0, 0, 0, True, 0, Nothing, 0)
- DrawingDoc.SketchAddConstraints "sgCOINCIDENT"
- Set SkLineV = DrawingDoc.SketchManager.CreateCenterLine(Vp1x, Vp1y, 0, Vp2x, Vp2y, 0)
- DrawingDoc.SketchAddConstraints "sgVERTICAL2D"
- boolstatus = DrawingDoc.Extension.SelectByID2("Point1@" & Featname & "@" & swDrawComp.Name & "@" & swDrawComp.View.GetName2, "EXTSKETCHPOINT", 0, 0, 0, True, 0, Nothing, 0)
- DrawingDoc.SketchAddConstraints "sgCOINCIDENT"
- DrawingDoc.ClearSelection2 True
- End Sub
2. 新建一个“宏”
工具->宏->新建宏,再把上面的“代码”复制过去,保存,如下图文章源自 solidworks教程网 http://gocae.comsolidworks教程网-http://gocae.com/1627.html
文章源自 solidworks教程网 http://gocae.comsolidworks教程网-http://gocae.com/1627.html
3. 选中“半圆”,再运行“宏”, OK文章源自 solidworks教程网 http://gocae.comsolidworks教程网-http://gocae.com/1627.html
原文作者Francis,出自http://www.solidworks.org.tw/forum.php?mod=viewthread&tid=24262文章源自 solidworks教程网 http://gocae.comsolidworks教程网-http://gocae.com/1627.html
总结:在SW没出标注半圆的工具之前,这是工作必备的技巧,小编一直在用,直的是很方便。文章源自 solidworks教程网 http://gocae.comsolidworks教程网-http://gocae.com/1627.html
文章源自 solidworks教程网 http://gocae.comsolidworks教程网-http://gocae.com/1627.html文章源自 solidworks教程网 http://gocae.comsolidworks教程网-http://gocae.com/1627.html
Comments