iCAx开思网
标题: 圓周分布鉆孔-宏 (已解決) [打印本页]
作者: ryouss 时间: 2018-5-24 17:36
标题: 圓周分布鉆孔-宏 (已解決)
本帖最后由 ryouss 于 2018-5-25 09:18 编辑
如圖所示,鉆孔直徑8時原點有孔,但改為鉆孔直徑5時原點就沒有孔,
有興趣者幫看一下,可否有解決方法!
宏是在2012版編程的.
附SWP文件 [attach]1257903[/attach]
原點沒孔
[attach]1257901[/attach]
原點有孔
[attach]1257902[/attach]
- ' *************************************************************
- ' macro recorded on 05/20/18 by scliang
- ' 功能:圓周分佈鉆孔,本範例因是用除料拉伸,所以鉆孔是平底.
- ' 操作: 1.在零件先選取要鉆孔之平面.
- ' 2.執行 "main" .
- ' 3.X座標取正數,若是負數可能會出錯.
- ' 4.首圈半徑近似於相鄰兩孔之中心(弧長)距離.
- '
- ' *************************************************************
- Dim X1 As Double 'TextBox1
- Dim Y1 As Double 'TextBox2
- Dim Drill_Diameter As Double 'TextBox3
- Dim Start_Circle_radius As Double 'TextBox4
- Dim Drill_depth As Double 'TextBox5
- Dim Circle_number As Integer 'TextBox6
- Dim X2 As Double
- Dim BX1 As Double
- Dim BX2 As Double
- Dim pi As Double
- Dim Circle_radius As Double
- Sub main()
- UserForm1.Show
- End Sub
- Sub Draw_()
- With UserForm1
- '判定資料是否沒打入
- If .TextBox1.Value = "" Or .TextBox2.Value = "" Or .TextBox3.Value = "" Or .TextBox4.Value = "" Or .TextBox5.Value = "" Or .TextBox6.Value = "" Then
- MsgBox ("Enter empty")
- Exit Sub
- End If
- '判定資料是否是輸入錯誤(起始圓半徑限制不能小於等於鉆孔直徑)
- Drill_Diameter = .TextBox3.Value / 1000
- Start_Circle_radius = .TextBox4.Value / 1000
- If Drill_Diameter >= Start_Circle_radius Then
- MsgBox ("Data error")
- Exit Sub
- End If
- Set swApp = Application.SldWorks
- Set Part = swApp.ActiveDoc
- Set swModel = swApp.ActiveDoc
- Set swSketchMgr = swModel.SketchManager
- Part.SketchManager.InsertSketch True '依據選取面插入草圖
- '中心圓之座標及作圖
- X1 = .TextBox1.Value / 1000
- Y1 = .TextBox2.Value / 1000
- X2 = X1 + Drill_Diameter / 2
- Set swSketchSegment = swSketchMgr.CreateCircle(X1, Y1, 0#, X2, Y1, 0#)
- '圓周分佈之鉆孔
- pi = Atn(1) * 4
- Circle_number = .TextBox6.Value
- Drill_depth = .TextBox5.Value / 1000 '鉆孔深
- For i = 1 To Circle_number
- Circle_radius = i * Start_Circle_radius '分佈圓周之半徑
- Copy_Number = Int(2 * Circle_radius * pi / Start_Circle_radius + 0.5) '分佈圓周之鉆孔數
- '分佈圓之基圓作圖
- BX1 = X1 + Circle_radius
- BX2 = BX1 + Drill_Diameter / 2
- Set swSketchSegment = swSketchMgr.CreateCircle(BX1, Y1, 0#, BX2, Y1, 0#)
- '分佈圓之複製孔數,圓周複製參數:圓弧半徑、圓弧角、花紋數、花紋間距(間隔弧度)、圖案旋轉、刪除實例
- boolstatus = swSketchMgr.CreateCircularSketchStepAndRepeat(Circle_radius, pi, Copy_Number, 2 * pi, True, "", True, True, True)
- Next
- End With
- '除料拉伸
- Dim myFeature As Object
- Set myFeature = Part.FeatureManager.FeatureCut3(True, False, False, 0, 0, Drill_depth, 0, False, False, False, False, 1.74532925199433E-02, _
- 1.74532925199433E-02, False, False, False, False, False, True, True, True, True, False, 0, 0, False)
- End Sub
复制代码
作者: pyczt 时间: 2018-5-25 08:18
ISketchManager::AddToDBalso avoids some of the peculiarities involved with creating entities via theuser interface, such as inferencing, automatic relations, and snapping to thegrid. Adding entities directly to the database also significantly increases theperformance of this method. When you are done creating entities, it isimportant to ISketchManager::AddToDB(False), to restore SolidWorks to itsnormal operating mode.
ISketchManager:AddToDB还避免了通过用户界面创建实体所涉及的一些特性,例如推理、自动关系和与网格的切换。将实体直接添加到数据库中也显著提高了该方法的性能。创建实体后,对于ISketchManager:AddToDB(False)来说,将SolidWorks恢复到其正常运行模式非常重要。
One of the benefitsof adding sketch entities directly to the database is that you can avoid gridand entity snapping. For example, if you create a sketch line whose endpoint isnear another entity or near a grid point, the new line endpoint snaps to theother item or grid point. Setting ISketchManager::AddToDB to true avoids thisbehavior during sketch entity creation.
将草图实体直接添加到数据库的好处之一是可以避免网格和实体抓取。例如,如果您创建了一个草图线,其端点位于另一个实体附近或网格点附近,则新的线端点将切换到另一个项或网格点。将ISketchManager:AddToDB设置为true,可以避免在创建草图实体时发生这种行为。
- Sub Draw_()
- With UserForm1
- '
- If .TextBox1.Value = "" Or .TextBox2.Value = "" Or .TextBox3.Value = "" Or .TextBox4.Value = "" Or .TextBox5.Value = "" Or .TextBox6.Value = "" Then
- MsgBox ("Enter empty")
- Exit Sub
- End If
- '
- Drill_Diameter = .TextBox3.Value / 1000
- Start_Circle_radius = .TextBox4.Value / 1000
- If Drill_Diameter >= Start_Circle_radius Then
- MsgBox ("Data error")
- Exit Sub
- End If
- Set swApp = Application.SldWorks
- Set Part = swApp.ActiveDoc
- Set swModel = swApp.ActiveDoc
- Set swSketchMgr = swModel.SketchManager
- Part.SketchManager.InsertSketch True '
- swModel.SketchManager.AddToDB = True
- X1 = .TextBox1.Value / 1000
- Y1 = .TextBox2.Value / 1000
- X2 = X1 + Drill_Diameter / 2
- Set swSketchSegment = swSketchMgr.CreateCircle(X1, Y1, 0#, X2, Y1, 0#)
- pi = Atn(1) * 4
- Circle_number = .TextBox6.Value
- Drill_depth = .TextBox5.Value / 1000
- For i = 1 To Circle_number
- Circle_radius = i * Start_Circle_radius
- Copy_Number = Int(2 * Circle_radius * pi / Start_Circle_radius + 0.5)
- BX1 = X1 + Circle_radius
- BX2 = BX1 + Drill_Diameter / 2
- Set swSketchSegment = swSketchMgr.CreateCircle(BX1, Y1, 0#, BX2, Y1, 0#)
- boolstatus = swSketchMgr.CreateCircularSketchStepAndRepeat(Circle_radius, pi, Copy_Number, 2 * pi, True, "", True, True, True)
- Next
- End With
- swModel.SketchManager.AddToDB = False
- Dim myFeature As Object
- Set myFeature = Part.FeatureManager.FeatureCut3(True, False, False, 0, 0, Drill_depth, 0, False, False, False, False, 1.74532925199433E-02, _
- 1.74532925199433E-02, False, False, False, False, False, True, True, True, True, False, 0, 0, False)
- End Sub
复制代码
作者: ryouss 时间: 2018-5-25 09:13
本帖最后由 ryouss 于 2018-5-25 11:23 编辑
pyczt 发表于 2018-5-25 08:18
ISketchManager::AddToDBalso avoids some of the peculiarities involved with creating entities via the ...
如上原程式補加 swModel.SketchManager.AddToDB = True 後,
不但解決了 x=0,y=0 的問題,也一併解決了 X 為負值的問題,再次謝謝 pyczt 大大的幫忙.
[attach]1257910[/attach]
作者: qxzch 时间: 2018-5-26 15:22
很神奇的宏!
作者: qxzch 时间: 2018-5-27 18:11
提点建议:1. 中心的孔做个选择,可以钻也可不钻;2. 首圈孔的个数可以自定义,现在是固定的6个。这样更人性化
作者: ryouss 时间: 2018-5-27 20:35
首圈半徑近似於相鄰兩孔之中心(弧長)距離.
為了滿足如上條件才6个.
作者: Trouble12138 时间: 2018-6-16 14:22
点了就要下载啊,本来就却积分
作者: makejon 时间: 2018-10-3 09:30
怎么提是empty
欢迎光临 iCAx开思网 (https://www.icax.org/) |
Powered by Discuz! X3.3 |