.net语言 开发UG NX二次开发 NX12 (第六天)

1.查看体的TAG

a.先设置环镜    UGII_DISPLAY_DEBUG 1

b.重启UG

 

 

 

 

 

2.批量移除参数

 1 Imports System
 2 Imports NXOpen
 3 Imports NXOpen.UF
 4 Module NXJournal
 5     Sub Main(ByVal args() As String)
 6         Dim theSession As NXOpen.Session = NXOpen.Session.GetSession()
 7         Dim workPart As NXOpen.Part = theSession.Parts.Work
 8         Dim ufs As UFSession = UFSession.GetUFSession()
 9         Dim tag1 As Tag = 72077
10Dim tag2 As Tag 
11         Dim body_list As Tag() = {}
12         ufs.Modl.CreateList(body_list)
13         ufs.Modl.PutListItem(body_list, tag1) 
14        ‘ ufs.Modl.PutListItem(body_list, tag2)  ‘加上tag一起去参
15         ufs.Modl.DeleteBodyParms(body_list)
16     End Sub
17 
18 End Module
19      

 3.批量修改孔的大小及颜色

 1 Imports System
 2 Imports NXOpen
 3 Imports NXOpen.UF
 4 Imports NXOpen.Utilities
 5 Module NXJournal
 6     Sub Main(ByVal args() As String)
 7         Dim theSession As NXOpen.Session = NXOpen.Session.GetSession()
 8         Dim workPart As NXOpen.Part = theSession.Parts.Work
 9         Dim ufs As UFSession = UFSession.GetUFSession()
10 
11         Try
12             MsgBox(FindFaces())
13         Catch
14             MsgBox("失败")
15         End Try
16     End Sub
17     Function SetHoleSize(faces1() As Face, SetSize As Double) '修改孔大小
18 
19         Dim theSession As NXOpen.Session = NXOpen.Session.GetSession()
20         Dim workPart As NXOpen.Part = theSession.Parts.Work
21         Dim nullNXOpen_Features_AdmResizeFace As NXOpen.Features.AdmResizeFace = Nothing
22         Dim admResizeFaceBuilder1 As NXOpen.Features.AdmResizeFaceBuilder = Nothing
23         admResizeFaceBuilder1 = workPart.Features.CreateAdmResizeFaceBuilder(nullNXOpen_Features_AdmResizeFace)
24         Dim faceDumbRule1 As NXOpen.FaceDumbRule = Nothing
25         faceDumbRule1 = workPart.ScRuleFactory.CreateRuleFaceDumb(faces1)
26         Dim rules2(0) As NXOpen.SelectionIntentRule
27         rules2(0) = faceDumbRule1
28         admResizeFaceBuilder1.FaceToResize.FaceCollector.ReplaceRules(rules2, False)
29         admResizeFaceBuilder1.Diameter.RightHandSide = SetSize
30         Dim nXObject1 As NXOpen.NXObject = Nothing
31         nXObject1 = admResizeFaceBuilder1.Commit()
32         Dim expression1 As NXOpen.Expression = admResizeFaceBuilder1.Diameter
33         admResizeFaceBuilder1.Destroy()
34         Return True
35     End Function
36     Function DelBodyParms(tag1 As Tag) '移除参数
37         Dim theSession As NXOpen.Session = NXOpen.Session.GetSession()
38         Dim workPart As NXOpen.Part = theSession.Parts.Work
39         Dim ufs As UFSession = UFSession.GetUFSession()
40         'Dim tag1 As Tag = 72077
41         Dim body_list As Tag() = {}
42         ufs.Modl.CreateList(body_list)
43         ufs.Modl.PutListItem(body_list, tag1)
44         ufs.Modl.DeleteBodyParms(body_list)
45         Return True
46     End Function
47     Function FindFaces()
48         Dim theSession As NXOpen.Session = NXOpen.Session.GetSession()
49         Dim workPart As NXOpen.Part = theSession.Parts.Work
50         Dim BodyTag As Tag = 72077
51         Dim FaceTagList As Tag() = {}
52         Dim FaceTag As Tag = Tag.Null
53         Dim ufs As UFSession = UFSession.GetUFSession()
54         ufs.Modl.AskBodyFaces(BodyTag, FaceTagList)
55         Dim tmpCount As Integer = 1
56         ufs.Modl.AskListCount(FaceTagList, tmpCount)
57         Dim i As Integer
58         For i = 0 To tmpCount - 1
59             ufs.Modl.AskListItem(FaceTagList, i, FaceTag)
60             Dim tmpType As Integer
61             Dim tmpPoint As Double() = {0, 0, 0}
62             Dim tmpDir As Double() = {0, 0, 0}
63             Dim tmpBox As Double() = {0, 0, 0, 0, 0, 0}
64             Dim tmpRadius As Double
65             Dim tmpRadData As Double
66             Dim tmpNormDir As Integer
67 
68 
69             Dim faces1(0) As Face
70             Dim face1 As Face
71             ufs.Modl.AskFaceData(FaceTag, tmpType, tmpPoint, tmpDir, tmpBox, tmpRadius, tmpRadData, tmpNormDir)
72             If tmpType = 16 And tmpNormDir = -1 Then
73                 face1 = NXObjectManager.Get(FaceTag)
74                 faces1(0) = face1
75                 If Math.Round(tmpRadius, 1) = 4 Then '销孔 8.0002
76                     SetHoleSize(faces1, 8.0002)
77                     ufs.Obj.SetColor(FaceTag, 186)
78                 End If
79                 If Math.Round(tmpRadius, 1) = 3.4 Then 'M8螺丝孔 6.806
80                     SetHoleSize(faces1, 6.806)
81                     ufs.Obj.SetColor(FaceTag, 211)
82                 End If
83                 If Math.Round(tmpRadius, 1) = 4.5 Then 'M8螺丝过孔 9.007
84                     SetHoleSize(faces1, 9.007)
85                     ufs.Obj.SetColor(FaceTag, 39)
86                 End If
87 
88             End If
89         Next i
90         DelBodyParms(BodyTag)
91         Return "成功"
92     End Function
93 
94 End Module

 

posted @ 2021-10-08 14:57  KingMAX(没事杀杀毒)  阅读(571)  评论(0)    收藏  举报