2010年10月15日金曜日

ジャーナルを作って合体させる

まずはジャーナルを記録します。記録する処理は、

  1. ボルト頭部の円筒ソリッドを作成
  2. ボルトねじ部の円筒ソリッドを作成
  3. 2つのソリッドを足して1つのソリッドにする

という操作を記録します。これは簡単にできましたし、再生しても問題ありませんでした。

そして、作成されたジャーナルに前回のVBコードを追加するわけですが、これが全然うまく動かない。びっくりするくらいできない。ググってもググってもググってもサンプルコードが見つからない...O| ̄|_
退職日も近くなり、もうだめだ...最初から無理だったんだよ...どんどん、ごめんね...などとあきらめかけていたその時!NXの中にサンプルコードがあったことを思い出ししました。NXインストフォルダを拡張子vbで全検索したところ、でてきましたよ、ずらずらっとvbファイルが。NX5では以下のフォルダに、それはそれはたくさんのサンプルコードがあります。
NXインストフォルダ\UGOPEN\SampleNXOpenApplications\.NET

いろいろ見て、良さそうなのをコピペ→実行→エラー、コピペ→実行→エラー、コピペ→実行→エラー...いったいどれくらいの時間が過ぎたのだろう...というくらい、どのファイルをどう参考にしたのかわからなくなってしまいましたが、以下のコードで動きました。

* ボルトソリッドは頭とねじ部を足して1ソリッドとしてあります。
* 穴ソリッドは座グリ穴、逃がし穴、ねじ下穴と全て単体のソリッドとして作成してあります。

Option Strict Off
Option Explicit On
Imports system.IO
Imports System.Windows.Forms
Imports System
Imports NXOpen

Module NXJournal
    Sub Main()
        Dim theSession As Session = Session.GetSession()
        Dim workPart As Part = theSession.Parts.Work
        Dim theUI As UI = UI.GetUI()
        Dim form As Form1 = New Form1(theSession, theUI)
        If form.ShowDialog() <> DialogResult.OK Then Exit Sub 
    End Sub
End Module

Public Class Form1
    Inherits System.Windows.Forms.Form

    ''''''''''
    '    PRIVATE DATA
    ''''''''''
    Private m_session As Session
    Private m_ui As UI
    ''''''''''
    '       PUBLIC METHODS
    ''''''''''
    Public Sub New(ByVal session As Session, ByVal ui As UI)
        MyBase.New()
        m_session = session
        m_ui = ui
        'This call is required by the Windows Form Designer.
        InitializeComponent()
    End Sub
    ' --------------------------■ 設定
    Private dsArray() As Single = {1.6, 2, 3, 4, 5, 6, 8, 10, 12, 16, 20, 24, 30, 36, 48, 56, 64}       ' 呼び
    Private dkArray() As Single = {3, 3, 5.5, 7, 8.5, 10, 13, 16, 18, 24, 30, 36, 45, 54, 72, 84, 96}   ' 頭径
    Private hkArray() As Single = {1.6, 2, 3, 4, 5, 6, 8, 10, 12, 16, 20, 24, 30, 36, 48, 56, 64}       ' 頭高
    Private hdsArray() As Single = {1.8, 2.4, 3.4, 4.5, 5.5, 6.6, 9, 11, 13.5, 17.5, 22, 26, 33, 39, 52, 62, 70}        ' 逃がし穴径
    Private hdkArray() As Single = {3.5, 4.4, 6.5, 8, 10, 11, 15, 18, 20, 26, 33, 40, 50, 58, 78, 0, 0}                 ' 座グリ穴径
    Private hhkArray() As Single = {1.8, 2.2, 3.5, 4.8, 5.8, 6.8, 8.8, 10.8, 12.8, 16.8, 21, 25, 31, 37, 49, 0, 0}      ' 座グリ穴深さ
    Private hdtArray() As Single = {1.25, 1.6, 2.5, 3.3, 4.2, 5, 6.75, 8.5, 10.25, 14, 17.5, 21, 26.5, 32, 43, 50.5, 58}' 下穴径

    ' --------------------------■ フォームソース
    'フォームがコンポーネントの一覧をクリーンアップするために dispose をオーバーライドします。
    <System.Diagnostics.DebuggerNonUserCode()> _
    Protected Overrides Sub Dispose(ByVal disposing As Boolean)
        Try
            If disposing AndAlso components IsNot Nothing Then
                components.Dispose()
            End If
        Finally
            MyBase.Dispose(disposing)
        End Try
    End Sub

    'Windows フォーム デザイナで必要です。
    Private components As System.ComponentModel.IContainer

    'メモ: 以下のプロシージャは Windows フォーム デザイナで必要です。
    'Windows フォーム デザイナを使用して変更できます。 
    'コード エディタを使って変更しないでください。
    <System.Diagnostics.DebuggerStepThrough()> _
    Private Sub InitializeComponent()
        Me.ComboBox1 = New System.Windows.Forms.ComboBox
        Me.Label1 = New System.Windows.Forms.Label
        Me.TextBox1 = New System.Windows.Forms.TextBox
        Me.Label2 = New System.Windows.Forms.Label
        Me.Button1 = New System.Windows.Forms.Button
        Me.Button2 = New System.Windows.Forms.Button
        Me.Label3 = New System.Windows.Forms.Label
        Me.PictureBox1 = New System.Windows.Forms.PictureBox
        Me.CheckBox1 = New System.Windows.Forms.CheckBox
        CType(Me.PictureBox1, System.ComponentModel.ISupportInitialize).BeginInit()
        Me.SuspendLayout()
        '
        'ComboBox1
        '
        Me.ComboBox1.FormattingEnabled = True
        Me.ComboBox1.Location = New System.Drawing.Point(81, 25)
        Me.ComboBox1.Margin = New System.Windows.Forms.Padding(4)
        Me.ComboBox1.Name = "ComboBox1"
        Me.ComboBox1.Size = New System.Drawing.Size(71, 23)
        Me.ComboBox1.TabIndex = 0
        '
        'Label1
        '
        Me.Label1.AutoSize = True
        Me.Label1.Location = New System.Drawing.Point(12, 28)
        Me.Label1.Margin = New System.Windows.Forms.Padding(4, 0, 4, 0)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(39, 15)
        Me.Label1.TabIndex = 1
        Me.Label1.Text = "呼び"
        '
        'TextBox1
        '
        Me.TextBox1.Location = New System.Drawing.Point(82, 55)
        Me.TextBox1.Name = "TextBox1"
        Me.TextBox1.Size = New System.Drawing.Size(71, 22)
        Me.TextBox1.TabIndex = 3
        '
        'Label2
        '
        Me.Label2.AutoSize = True
        Me.Label2.Location = New System.Drawing.Point(12, 58)
        Me.Label2.Name = "Label2"
        Me.Label2.Size = New System.Drawing.Size(63, 15)
        Me.Label2.TabIndex = 4
        Me.Label2.Text = "長さ(L)"
        '
        'Button1
        '
        Me.Button1.Location = New System.Drawing.Point(12, 193)
        Me.Button1.Name = "Button1"
        Me.Button1.Size = New System.Drawing.Size(70, 23)
        Me.Button1.TabIndex = 5
        Me.Button1.Text = "OK"
        Me.Button1.UseVisualStyleBackColor = True
        '
        'Button2
        '
        Me.Button2.Location = New System.Drawing.Point(88, 193)
        Me.Button2.Name = "Button2"
        Me.Button2.Size = New System.Drawing.Size(70, 23)
        Me.Button2.TabIndex = 6
        Me.Button2.Text = "Cancel"
        Me.Button2.UseVisualStyleBackColor = True
        '
        'Label3
        '
        Me.Label3.AutoSize = True
        Me.Label3.Location = New System.Drawing.Point(188, 197)
        Me.Label3.Name = "Label3"
        Me.Label3.Size = New System.Drawing.Size(295, 15)
        Me.Label3.TabIndex = 7
        Me.Label3.Text = "独断によりL1=L/2、L2=Lとしています。"
        '
        'PictureBox1
        '
        '★Resourceを使った以下の書式ではジャーナルでエラーとなります。
        'そのため、FromFileを使用しています。
'        Me.PictureBox1.Image = Global.NXGateCrtBolt.My.Resources.Resources.hcb21
        Me.PictureBox1.Image = System.Drawing.Image.FromFile("C:\NXGate\journal\Crtbolt\hcb.png")
        Me.PictureBox1.Location = New System.Drawing.Point(159, 12)
        Me.PictureBox1.Name = "PictureBox1"
        Me.PictureBox1.Size = New System.Drawing.Size(327, 176)
        Me.PictureBox1.TabIndex = 2
        Me.PictureBox1.TabStop = False
        '
        'CheckBox1
        '
        Me.CheckBox1.AutoSize = True
        Me.CheckBox1.Location = New System.Drawing.Point(15, 83)
        Me.CheckBox1.Name = "CheckBox1"
        Me.CheckBox1.Size = New System.Drawing.Size(90, 19)
        Me.CheckBox1.TabIndex = 9
        Me.CheckBox1.Text = "穴も作る"
        Me.CheckBox1.UseVisualStyleBackColor = True
        '
        'Form1
        '
        Me.AutoScaleDimensions = New System.Drawing.SizeF(8.0!, 15.0!)
        Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
        Me.ClientSize = New System.Drawing.Size(504, 230)
        Me.Controls.Add(Me.CheckBox1)
        Me.Controls.Add(Me.Label3)
        Me.Controls.Add(Me.Button2)
        Me.Controls.Add(Me.Button1)
        Me.Controls.Add(Me.Label2)
        Me.Controls.Add(Me.TextBox1)
        Me.Controls.Add(Me.PictureBox1)
        Me.Controls.Add(Me.Label1)
        Me.Controls.Add(Me.ComboBox1)
        Me.Font = New System.Drawing.Font("MS ゴシック", 11.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(128, Byte))
        Me.Margin = New System.Windows.Forms.Padding(4)
        Me.Name = "Form1"
        Me.Text = "ボルトの作成"
        CType(Me.PictureBox1, System.ComponentModel.ISupportInitialize).EndInit()
        Me.ResumeLayout(False)
        Me.PerformLayout()
        ' ----------------------------------------------
        '                                   ■ FormLoad
        ' ----------------------------------------------
        Dim sngTmp As Single
        ' -----リストに追加
        For Each sngTmp In dsArray                      '
            ComboBox1.Items.Add("M" & CStr(sngTmp))
        Next
        ' -----初期値
        ComboBox1.SelectedIndex = 0
        TextBox1.Text = 10
    End Sub

    Friend WithEvents ComboBox1 As System.Windows.Forms.ComboBox
    Friend WithEvents Label1 As System.Windows.Forms.Label
    Friend WithEvents PictureBox1 As System.Windows.Forms.PictureBox
    Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
    Friend WithEvents Label2 As System.Windows.Forms.Label
    Friend WithEvents Button1 As System.Windows.Forms.Button
    Friend WithEvents Button2 As System.Windows.Forms.Button
    Friend WithEvents Label3 As System.Windows.Forms.Label
    Friend WithEvents CheckBox1 As System.Windows.Forms.CheckBox
    ' ----------------------------------------------
    '                                   ■ Cancel
    ' ----------------------------------------------
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Me.Close()
    End Sub
    ' ----------------------------------------------
    '                                   ■ OK
    ' ----------------------------------------------
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim i As Short
        Dim ichk As Short
    dim l As Short
        i = Me.ComboBox1.SelectedIndex
        ichk = Me.CheckBox1.Checked     ' checked=-1
        l=CSng(Me.TextBox1.Text)    ' Bolt長さ
        Me.Close()
        ' ----------------------------------------------
        '                 ■ ここからJournal
        ' ----------------------------------------------
        Dim theSession As Session = Session.GetSession()
        Dim workPart As Part = theSession.Parts.Work
        Dim displayPart As Part = theSession.Parts.Display
        ' ----------------------------------------------
        ' メニュー: 挿入->Design Feature->Cylinder...
        ' ----------------------------------------------
        Dim markId1 As Session.UndoMarkId
        markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Start")
        ' ----------------------------------------------
        Dim nullFeatures_Feature As Features.Feature = Nothing
        Dim cylinderBuilder1 As Features.CylinderBuilder
        cylinderBuilder1 = workPart.Features.CreateCylinderBuilder(nullFeatures_Feature)
        Dim origin1 As Point3d = New Point3d(0.0, 0.0, 0.0)
        Dim vector1 As Vector3d = New Vector3d(0.0, 0.0, 1.0)
        Dim direction1 As Direction
        direction1 = workPart.Directions.CreateDirection(origin1, vector1, SmartObject.UpdateOption.WithinModeling)

        Dim coordinates1 As Point3d = New Point3d(0.0, 0.0, 0.0)
        Dim point1 As Point
        point1 = workPart.Points.CreatePoint(coordinates1)
        Dim axis1 As Axis
        axis1 = workPart.Axes.CreateAxis(point1, direction1, SmartObject.UpdateOption.WithinModeling)
        cylinderBuilder1.Axis = axis1
        cylinderBuilder1.BooleanOption.Type = GeometricUtilities.BooleanOperation.BooleanType.Create
        ' --------------------------------------円筒開始
        Dim targetBodies1(0) As Body
        Dim nullBody As Body = Nothing
        targetBodies1(0) = nullBody
        cylinderBuilder1.BooleanOption.SetTargetBodies(targetBodies1)
        cylinderBuilder1.Type = Features.CylinderBuilder.Types.AxisDiameterAndHeight
        theSession.SetUndoMarkName(markId1, "Cylinder")
        cylinderBuilder1.Diameter.RightHandSide = dkArray(i)        ' 選択値
        cylinderBuilder1.Height.RightHandSide = hkArray(i)        ' 選択値
        Dim markId2 As Session.UndoMarkId
        markId2 = theSession.SetUndoMark(Session.MarkVisibility.Invisible, "Cylinder")
        Dim nXObject1 As NXObject
        nXObject1 = cylinderBuilder1.Commit()
        ' --------------------------------------足し算用にID取得
        Dim strJID As String
        strJID = nXObject1.JournalIdentifier
        theSession.DeleteUndoMark(markId2, Nothing)
        cylinderBuilder1.Destroy()
        ' ----------------------------------------------
        ' 2つ目の円筒作成
        ' ----------------------------------------------
        ' ----------------------------------------------
        ' メニュー: 挿入->Design Feature->Cylinder...
        ' ----------------------------------------------
        Dim markId3 As Session.UndoMarkId
        markId3 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Start")
        ' ----------------------------------------------
        Dim cylinderBuilder2 As Features.CylinderBuilder
        cylinderBuilder2 = workPart.Features.CreateCylinderBuilder(nullFeatures_Feature)
        Dim origin2 As Point3d = New Point3d(0.0, 0.0, 0.0)
        Dim vector2 As Vector3d = New Vector3d(0.0, 0.0, 1.0)
        Dim direction2 As Direction
        direction2 = workPart.Directions.CreateDirection(origin2, vector2, SmartObject.UpdateOption.WithinModeling)

        Dim coordinates2 As Point3d = New Point3d(0.0, 0.0, 0.0)
        Dim point2 As Point
        point2 = workPart.Points.CreatePoint(coordinates2)
        Dim axis2 As Axis
        axis2 = workPart.Axes.CreateAxis(point2, direction2, SmartObject.UpdateOption.WithinModeling)
        cylinderBuilder2.Axis = axis2
        cylinderBuilder2.BooleanOption.Type = GeometricUtilities.BooleanOperation.BooleanType.Create

        Dim targetBodies2(0) As Body
        targetBodies2(0) = nullBody
        cylinderBuilder2.BooleanOption.SetTargetBodies(targetBodies2)
        cylinderBuilder2.Type = Features.CylinderBuilder.Types.AxisDiameterAndHeight
        theSession.SetUndoMarkName(markId3, "Cylinder")
        cylinderBuilder2.Diameter.RightHandSide = dsArray(i)                ' 選択値
        cylinderBuilder2.BooleanOption.Type = GeometricUtilities.BooleanOperation.BooleanType.Subtract
        Dim body1 As Body = CType(workPart.Bodies.FindObject(strJID), Body)
        cylinderBuilder2.BooleanOption.Type = GeometricUtilities.BooleanOperation.BooleanType.Unite
        Dim targetBodies3(0) As Body
        targetBodies3(0) = body1
        cylinderBuilder2.BooleanOption.SetTargetBodies(targetBodies3) 
        cylinderBuilder2.Height.RightHandSide = hkArray(i)+l                ' 選択値
        ' ----------------------------------------------
        Dim markId4 As Session.UndoMarkId
        markId4 = theSession.SetUndoMark(Session.MarkVisibility.Invisible, "Cylinder")
        ' ----------------------------------------------
        Dim nXObject2 As NXObject
        nXObject2 = cylinderBuilder2.Commit()
        ' ----------------------------------------------
        theSession.DeleteUndoMark(markId4, Nothing)
        cylinderBuilder2.Destroy()
        ' ----------------------------------------------
        ' 穴ソリッドも作る場合
        ' ----------------------------------------------
    If hdkArray(i)=0 then
            MessageBox.show("穴寸法が定義されていません")
        ElseIf ichk = -1 Then
            Dim markId5 As Session.UndoMarkId
            markId5 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Start")
            ' ----------------------------------------------
            ' 座グリ穴
            ' ----------------------------------------------
            Dim cylinderBuilder3 As Features.CylinderBuilder
            cylinderBuilder3 = workPart.Features.CreateCylinderBuilder(nullFeatures_Feature)
            Dim origin3 As Point3d = New Point3d(0.0, 0.0, 0.0)
            Dim vector3 As Vector3d = New Vector3d(0.0, 0.0, 1.0)
            Dim direction3 As Direction
            direction3 = workPart.Directions.CreateDirection(origin3, vector3, SmartObject.UpdateOption.WithinModeling)

            Dim coordinates3 As Point3d = New Point3d(0.0, 0.0, 0.0)
            Dim point3 As Point
            point3 = workPart.Points.CreatePoint(coordinates3)
            Dim axis3 As Axis
            axis3 = workPart.Axes.CreateAxis(point3, direction3, SmartObject.UpdateOption.WithinModeling)
            cylinderBuilder3.Axis = axis3
            cylinderBuilder3.BooleanOption.Type = GeometricUtilities.BooleanOperation.BooleanType.Create
            ' --------------------------------------円筒開始
            Dim targetBodies4(0) As Body
            targetBodies4(0) = nullBody
            cylinderBuilder3.BooleanOption.SetTargetBodies(targetBodies4)
            cylinderBuilder3.Type = Features.CylinderBuilder.Types.AxisDiameterAndHeight
            theSession.SetUndoMarkName(markId5, "Cylinder")
            cylinderBuilder3.Diameter.RightHandSide = hdkArray(i)        ' 座グリ穴径
            cylinderBuilder3.Height.RightHandSide = hhkArray(i)           ' 座グリ穴深さ
            Dim markId6 As Session.UndoMarkId
            markId6 = theSession.SetUndoMark(Session.MarkVisibility.Invisible, "Cylinder")
            Dim nXObject3 As NXObject
            nXObject3 = cylinderBuilder3.Commit()
            ' --------------------------------------色を変更
            Dim displayModification1 As DisplayModification
            displayModification1 = theSession.DisplayManager.NewDisplayModification()
            displayModification1.ApplyToAllFaces = True
            displayModification1.NewColor = 55                ' 穴の色
            Dim objects1(0) As DisplayableObject
            Dim body2 As Body = CType(workPart.Bodies.FindObject(nXObject3.JournalIdentifier), Body)
            objects1(0) = body2
            displayModification1.Apply(objects1)
            displayModification1.Dispose()
            ' ----------------------------------------------
            theSession.DeleteUndoMark(markId6, Nothing)
            cylinderBuilder3.Destroy()
            ' ----------------------------------------------
            ' 逃がし穴
            ' ----------------------------------------------
            Dim markId7 As Session.UndoMarkId
            markId7 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Start")
            ' ----------------------------------------------
            Dim cylinderBuilder4 As Features.CylinderBuilder
            cylinderBuilder4 = workPart.Features.CreateCylinderBuilder(nullFeatures_Feature)
            Dim origin4 As Point3d = New Point3d(0.0, 0.0, 0.0)
            Dim vector4 As Vector3d = New Vector3d(0.0, 0.0, 1.0)
            Dim direction4 As Direction
            direction4 = workPart.Directions.CreateDirection(origin4, vector4, SmartObject.UpdateOption.WithinModeling)

            Dim coordinates4 As Point3d = New Point3d(0.0, 0.0, 0.0)
            Dim point4 As Point
            point4 = workPart.Points.CreatePoint(coordinates4)
            Dim axis4 As Axis
            axis4 = workPart.Axes.CreateAxis(point4, direction4, SmartObject.UpdateOption.WithinModeling)
            cylinderBuilder4.Axis = axis4
            cylinderBuilder4.BooleanOption.Type = GeometricUtilities.BooleanOperation.BooleanType.Create
            ' --------------------------------------円筒開始
            Dim targetBodies5(0) As Body
            targetBodies5(0) = nullBody
            cylinderBuilder4.BooleanOption.SetTargetBodies(targetBodies5)
            cylinderBuilder4.Type = Features.CylinderBuilder.Types.AxisDiameterAndHeight
            theSession.SetUndoMarkName(markId7, "Cylinder")
            cylinderBuilder4.Diameter.RightHandSide = hdsArray(i)        ' 逃がし穴径
            cylinderBuilder4.Height.RightHandSide = hkArray(i)+l/2          ' 逃がし穴深さ
            Dim markId8 As Session.UndoMarkId
            markId8 = theSession.SetUndoMark(Session.MarkVisibility.Invisible, "Cylinder")
            Dim nXObject4 As NXObject
            nXObject4 = cylinderBuilder4.Commit()
            ' --------------------------------------色を変更
'            Dim displayModification1 As DisplayModification
            displayModification1 = theSession.DisplayManager.NewDisplayModification()
            displayModification1.ApplyToAllFaces = True
            displayModification1.NewColor = 55                ' 穴の色
            Dim objects2(0) As DisplayableObject
            Dim body3 As Body = CType(workPart.Bodies.FindObject(nXObject4.JournalIdentifier), Body)
            objects2(0) = body3
            displayModification1.Apply(objects2)
            displayModification1.Dispose()
            ' ----------------------------------------------
            theSession.DeleteUndoMark(markId8, Nothing)
            cylinderBuilder4.Destroy()
            ' ----------------------------------------------
            ' 下穴
            ' ----------------------------------------------
            Dim markId9 As Session.UndoMarkId
            markId9 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Start")
            ' ----------------------------------------------
            Dim cylinderBuilder5 As Features.CylinderBuilder
            cylinderBuilder5 = workPart.Features.CreateCylinderBuilder(nullFeatures_Feature)
            Dim origin5 As Point3d = New Point3d(0.0, 0.0, 0.0)
            Dim vector5 As Vector3d = New Vector3d(0.0, 0.0, 1.0)
            Dim direction5 As Direction
            direction5 = workPart.Directions.CreateDirection(origin5, vector5, SmartObject.UpdateOption.WithinModeling)

            Dim coordinates5 As Point3d = New Point3d(0.0, 0.0, 0.0)
            Dim point5 As Point
            point5 = workPart.Points.CreatePoint(coordinates5)
            Dim axis5 As Axis
            axis5 = workPart.Axes.CreateAxis(point5, direction5, SmartObject.UpdateOption.WithinModeling)
            cylinderBuilder5.Axis = axis5
            cylinderBuilder5.BooleanOption.Type = GeometricUtilities.BooleanOperation.BooleanType.Create
            ' --------------------------------------円筒開始
            Dim targetBodies6(0) As Body
            targetBodies6(0) = nullBody
            cylinderBuilder5.BooleanOption.SetTargetBodies(targetBodies6)
            cylinderBuilder5.Type = Features.CylinderBuilder.Types.AxisDiameterAndHeight
            theSession.SetUndoMarkName(markId9, "Cylinder")
            cylinderBuilder5.Diameter.RightHandSide = hdtArray(i)        ' 下穴径
            cylinderBuilder5.Height.RightHandSide = hkArray(i)+l+l/2     ' 下穴深さ
            Dim markId10 As Session.UndoMarkId
            markId10 = theSession.SetUndoMark(Session.MarkVisibility.Invisible, "Cylinder")
            Dim nXObject5 As NXObject
            nXObject5 = cylinderBuilder5.Commit()
            ' --------------------------------------色を変更
            displayModification1 = theSession.DisplayManager.NewDisplayModification()
            displayModification1.ApplyToAllFaces = True
            displayModification1.NewColor = 55                ' 穴の色
            Dim objects3(0) As DisplayableObject
            Dim body4 As Body = CType(workPart.Bodies.FindObject(nXObject5.JournalIdentifier), Body)
            objects3(0) = body4
            displayModification1.Apply(objects3)
            displayModification1.Dispose()
            ' ----------------------------------------------
            theSession.DeleteUndoMark(markId10, Nothing)
            cylinderBuilder5.Destroy()
        End If
    End Sub
End Class

太字のところが編集した箇所です。
特にフォーム定義のPictureBoxの箇所は、画像をソースに埋め込む方法がわからなかったので、絶対パスで画像ファイルを読み込ませています。

これはエラー↓
        Me.PictureBox1.Image = Global.NXGateCrtBolt.My.Resources.Resources.hcb21 
これはOK↓
        Me.PictureBox1.Image = System.Drawing.Image.FromFile("C:\NXGate\journal\Crtbolt\hcb.png")

ということで何とか退職までに間に合いました。

参考までに、作成されるボルトと穴の寸法表を次ページに載せておきます。

寸法表へ

それでは、またいつか、どこかでお会いできる日を楽しみにしています。

0 件のコメント:

コメントを投稿