找回密码
 立即注册

QQ登录

只需一步,快速开始

微信扫码登录

搜索
查看: 25|回复: 0

[分享] 创建带长方体 源程序分享

[复制链接]

3

主题

185

回帖

436

积分

二级士官

积分
436
发表于 2 小时前 | 显示全部楼层 |阅读模式
'创建新零件
        Dim newPart As Part = Nothing
        Dim partName As String = InputBox("请输入新零件名称(不带扩展名):", "新建零件", "block_part")
        If partName Is Nothing OrElse partName = "" Then Return

        Try
            ' 创建新部件文件,使用毫米单位
            newPart = theSession.Parts.NewBaseDisplay(partName & ".prt", Part.Units.Millimeters)

            If newPart Is Nothing Then
                theUI.NXMessageBox.Show("错误", NXMessageBox.DialogType.Error, "创建新零件失败!")
                Return
            End If

            Dim workPart As Part = newPart

            ' 获取用户输入的长宽高(使用自定义对话框,3个独立输入框)
            Dim dialog As New BlockInputDialog()
            Dim result As DialogResult = dialog.ShowDialog()

            If result <> DialogResult.OK OrElse Not dialog.DialogOK Then
                Return
            End If

            Dim length As Double = dialog.Length
            Dim width As Double = dialog.Width
            Dim height As Double = dialog.Height

            ' 开始
            Dim nullFeatures_Feature As Features.Feature = Nothing
            Dim blockFeatureBuilder As Features.BlockFeatureBuilder
            blockFeatureBuilder = workPart.Features.CreateBlockFeatureBuilder(nullFeatures_Feature)

            ' 设置长方体类型为原点和边长
            blockFeatureBuilder.Type = Features.BlockFeatureBuilder.Types.OriginAndEdgeLengths

            ' 设置原点,使长方体中心与工作坐标系原点重合
            ' 长方体的一个角点为 (-length/2, -width/2, -height/2),这样中心就在 (0, 0, 0)
            Dim origin As Point3d = New Point3d(-length/2, -width/2, -height/2)
            blockFeatureBuilder.SetOriginAndLengths(origin, length, width, height)

            ' 应用并生成长方体
            Dim nXObject1 As NXObject
            nXObject1 = blockFeatureBuilder.Commit()
            blockFeatureBuilder.Destroy()


您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

咨询QQ:1359218528|发帖须知!|Archiver|手机版|UG爱好者论坛 ( 京ICP备10217105号-2 )

GMT+8, 2026-10-10 14:02

Powered by Discuz! X3.5 Licensed

© 2001-2025 Discuz! Team.

快速回复 返回顶部 返回列表