.net语言 开发UG NX二次开发 NX12 (第九天)
1.查询长宽高有小数的体
1 Imports System 2 Imports NXOpen 3 Imports NXOpen.UF 4 Imports NXOpen.UF.UFConstants 5 Module NXHole 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 Lw = theSession.ListingWindow 10 11 Sub Main(ByVal args() As String) 12 Dim bodyTag As Tag 13 ufs.Obj.CycleObjsInPart(workPart.Tag(), UF_solid_type, bodyTag) 14 While bodyTag <> Tag.Null 15 Dim type1 As Integer = 0 16 Dim subtype1 As Integer = 0 17 ufs.Obj.AskTypeAndSubtype(bodyTag, type1, subtype1) 18 If type1 = UF_solid_type And subtype1 = UF_solid_body_subtype Then 19 Dim DispProps As UFObj.DispProps 20 ufs.Obj.AskDisplayProperties(bodyTag, DispProps) 21 If DispProps.layer >= 100 Then 22 ufs.Obj.SetBlankStatus(bodyTag, UF_OBJ_BLANKED) '跳过在图层100以上的 23 Else 24 If DispProps.blank_status = 0 Then '跳过隐藏体 25 FindFaces(bodyTag) 26 End If 27 End If 28 End If 29 ufs.Obj.CycleObjsInPart(workPart.Tag(), UF_solid_type, bodyTag) 30 End While 31 32 End Sub 33 34 Function FindFaces(ByVal BodyTag As Tag) 35 Dim MaxBox As Double() = {10000, 10000, 10000, -10000, -10000, -10000} 36 Dim Box As Double() = {0, 0, 0, 0, 0, 0} 37 38 ufs.Modl.AskBoundingBox(BodyTag, Box) 39 MaxBox(0) = IIf(MaxBox(0) < Box(0), MaxBox(0), Box(0)) 40 MaxBox(1) = IIf(MaxBox(1) < Box(1), MaxBox(1), Box(1)) 41 MaxBox(2) = IIf(MaxBox(2) < Box(2), MaxBox(2), Box(2)) 42 MaxBox(3) = IIf(MaxBox(3) > Box(3), MaxBox(3), Box(3)) 43 MaxBox(4) = IIf(MaxBox(4) > Box(4), MaxBox(4), Box(4)) 44 MaxBox(5) = IIf(MaxBox(5) > Box(5), MaxBox(5), Box(5)) 45 46 Dim Length_ As Double = MaxBox(3) - MaxBox(0) 47 Dim Width_ As Double = MaxBox(4) - MaxBox(1) 48 Dim Height_ As Double = MaxBox(5) - MaxBox(2) 49 50 Dim lDec As Integer = IIf(Int(-Format(Length_, "0.0000") * 1000) = Fix(-Format(Length_, "0.0000") * 1000), 0, -1) 'x轴 51 Dim wDec As Integer = IIf(Int(-Format(Width_, "0.0000") * 1000) = Fix(-Format(Width_, "0.0000") * 1000), 0, -1) 'y轴 52 Dim hDec As Integer = IIf(Int(-Format(Height_, "0.0000") * 1000) = Fix(-Format(Height_, "0.0000") * 1000), 0, -1) 'Z轴 53 54 If lDec = -1 Or wDec = -1 Or hDec = -1 Then 55 FaceSetColor(BodyTag, lDec, wDec, hDec) 56 Else 57 ufs.Obj.SetBlankStatus(BodyTag, UF_OBJ_BLANKED) 58 End If 59 Return "" 60 End Function 61 Function FaceSetColor(BodyTag As Tag, lDec As Integer, wDec As Integer, hDec As Integer) 62 63 Dim FaceTagList As Tag() = {} 64 ufs.Modl.AskBodyFaces(BodyTag, FaceTagList) 65 66 Dim tmpCount As Integer = 1 67 ufs.Modl.AskListCount(FaceTagList, tmpCount) 68 69 Dim tmpType As Integer = 0 70 Dim tmpPoint As Double() = {0, 0, 0} 71 Dim tmpDir As Double() = {0, 0, 0} 72 Dim tmpBox As Double() = {0, 0, 0, 0, 0, 0} 73 Dim tmpRadius As Double = 0 74 Dim tmpRadData As Double = 0 75 Dim tmpNormDir As Integer = 0 76 77 Dim i As Integer = 0 78 Dim FaceTag As Tag = Tag.Null 79 For i = 0 To tmpCount - 1 80 ufs.Modl.AskListItem(FaceTagList, i, FaceTag) 81 ufs.Modl.AskFaceData(FaceTag, tmpType, tmpPoint, tmpDir, tmpBox, tmpRadius, tmpRadData, tmpNormDir) 82 If tmpType = UF_MODL_PLANAR_FACE And lDec = -1 And tmpDir(0) <> 0 And tmpDir(1) = 0 And tmpDir(2) = 0 Then 83 ufs.Obj.SetColor(FaceTag, 186) 84 85 End If 86 If tmpType = UF_MODL_PLANAR_FACE And wDec = -1 And tmpDir(0) = 0 And tmpDir(1) <> 0 And tmpDir(2) = 0 Then 87 ufs.Obj.SetColor(FaceTag, 186) 88 89 End If 90 If tmpType = UF_MODL_PLANAR_FACE And hDec = -1 And tmpDir(0) = 0 And tmpDir(1) = 0 And tmpDir(2) <> 0 Then 91 ufs.Obj.SetColor(FaceTag, 186) 92 93 End If 94 Next i 95 Return "" 96 End Function 97 End Module