第五个例子:怎样用VB.NET在UG中创建两个体然后做布尔加操作?
Imports System
Imports NXOpen
Imports NXOpen.UF
Imports NXOpen.UI
Imports NXOpen.Utilities
Module template_code
Sub Main()
Dim s As Session = Session.GetSession()
Dim ufs As UFSession = UFSession.GetUFSession()
'
' ------------------------------------------------- make sure we have a part
Dim this_part As NXOpen.Tag
Try
this_part = s.Parts.Work.Tag
Catch ex As Exception
If this_part = NXOpen.Tag.Null Then
MsgBox("You need an open part to run this program.", MsgBoxStyle.OKOnly)
' no part, so exit program gracefully
Exit Sub
End If
End Try
'
' ------------------------------------------------- first solid: a block
Dim corner_pt(2) As Double
Dim block_feat_tag As NXOpen.Tag
Dim edge_lengths(2) As String
' This is an alternate way to set the string value:
'
'Dim lengths(2) As Double
'lengths(0) = 150.1234
'edge_lengths(0) = lengths(0).ToString
'
' but setting it this way, we get the expression to boot:
edge_lengths(0) = "xlen=150.1234"
edge_lengths(1) = "ylen=65.4321"
edge_lengths(2) = "thickness=25."
Dim sign As FeatureSigns
sign = FeatureSigns.Nullsign
corner_pt(0) = 20
corner_pt(1) = 30
corner_pt(2) = -10
ufs.Modl.CreateBlock1(sign, corner_pt, edge_lengths, block_feat_tag)
If block_feat_tag <> NXOpen.Tag.Null Then
ufs.View.FitView(NXOpen.Tag.Null, 1.0)
MsgBox("First Solid Body tag is: " & block_feat_tag.ToString)
End If
'
' ------------------------------------------------- second solid: a cylinder
Dim height As String
Dim diameter As String
Dim direction(2) As Double
Dim cyl_feat_tag As NXOpen.Tag
height = "cyl_height=90"
diameter = "cyl_dia=40"
direction(0) = 0.707
direction(1) = 0.707
direction(2) = 0.707
ufs.Modl.CreateCyl1(sign, corner_pt, height, diameter, direction, cyl_feat_tag)
If cyl_feat_tag <> NXOpen.Tag.Null Then
ufs.View.FitView(NXOpen.Tag.Null, 1.0)
MsgBox("Second Solid Body tag is: " & cyl_feat_tag.ToString)
End If
'
' ------------------------------------------------- unite the two solids
Dim block_body_tag As NXOpen.Tag
Dim cyl_body_tag As NXOpen.Tag
ufs.Modl.AskFeatBody(block_feat_tag, block_body_tag)
ufs.Modl.AskFeatBody(cyl_feat_tag, cyl_body_tag)
ufs.Modl.UniteBodies(block_body_tag, cyl_body_tag)
'
' ------------------------------------------------- report count of solids
Dim all_bodies() As Body = s.Parts.Work.Bodies.ToArray()
Dim body_count As Integer
body_count = all_bodies.Length
MsgBox("Count of Bodies now in Work Part: " & body_count)
End Sub
Public Function GetUnloadOption(ByVal dummy As String) As Integer
GetUnloadOption = UFConstants.UF_UNLOAD_IMMEDIATELY
End Function
End Module
>>>关于创建方面的开发到此为止
本帖最后由 苏州人 于 2009-9-21 15:07 编辑 |