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
复制代码
|