3dr
Automotive
- Jul 10, 2004
- 451
Below is some code I got from NX Journaling.com
I've modified it to work with the specific expression I'd like to change but it's limited to the displayed work part only.
For it to be useful I need to also be able to use it at the assembly level.
Select 1 or more parts and apply the input to all selected.
With one other wrinkle... a drop down list of inputs.
From what I've read this may be an issue that requires a Dynamic winform which is different than the one currently in this code.
Any input??
' This Will show a winform dialogue for editing an expression with "Shape" in the comments column.
' You workpart you want to change has to be the displayed workpart.
Option Strict Off
Imports System
Imports System.Collections.Generic
Imports NXOpen
Imports NXOpen.UF
Module Module1
Public theSession As Session = Session.GetSession()
Public theUfSession As UFSession = UFSession.GetUFSession()
Public Const commentText As String = "Shape"
Dim theUI As UI = UI.GetUI()
Dim lw As ListingWindow = theSession.ListingWindow
Sub Main()
Dim markId1 As Session.UndoMarkId
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "NXJ")
lw.Open()
Dim myExpressions As New List(Of Expression)
For Each temp As Expression In theSession.Parts.Work.Expressions
If temp.RightHandSide.Contains("//") Then
'expression contains comment
Dim expComment As String = ""
expComment = temp.RightHandSide.Substring(temp.RightHandSide.IndexOf("//") + 2).Trim
'lw.WriteLine("comment: " & expComment)
If expComment.ToUpper = commentText.ToUpper Then
myExpressions.Add(temp)
End If
End If
Next
'For Each temp As Expression In myExpressions
' lw.WriteLine("name: " & temp.Name)
'Next
Dim expForm As New Form1
expForm.Expressions = myExpressions
expForm.ShowDialog()
theSession.UpdateManager.DoUpdate(markId1)
lw.Close()
End Sub
Public Function GetUnloadOption(ByVal dummy As String) As Integer
'Unloads the image immediately after execution within NX
GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Immediately
End Function
End Module
Public Class Form1
Private fExpressions As New List(Of NXOpen.Expression)
Public Property Expressions() As List(Of NXOpen.Expression)
Get
Return fExpressions
End Get
Set(ByVal value As List(Of NXOpen.Expression))
fExpressions = value
End Set
End Property
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load
'no error checking is done
txtExp1Name.Text = fExpressions.Item(0).Name
txtExp1Val.Text = fExpressions.Item(0).RightHandSide.Substring(0, fExpressions.Item(0).RightHandSide.IndexOf("//"))
End Sub
Private Sub btnCancel_Click(sender As Object, e As EventArgs) Handles btnCancel.Click
Me.Close()
End Sub
Private Sub btnOk_Click(sender As Object, e As EventArgs) Handles btnOk.Click
Try
fExpressions.Item(0).SetName(txtExp1Name.Text)
Catch ex As NXOpen.NXException
End Try
theSession.Parts.Work.Expressions.Edit(fExpressions.Item(0), txtExp1Val.Text & "//" & commentText)
Me.Close()
End Sub
End Class
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Partial Class Form1
Inherits System.Windows.Forms.Form
'Form overrides dispose to clean up the component list.
<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
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
<System.Diagnostics.DebuggerStepThrough()> _
Private Sub InitializeComponent()
Me.txtExp1Name = New System.Windows.Forms.TextBox()
Me.txtExp1Val = New System.Windows.Forms.TextBox()
Me.btnOk = New System.Windows.Forms.Button()
Me.btnCancel = New System.Windows.Forms.Button()
Me.SuspendLayout()
'
'txtExp1Name
'
Me.txtExp1Name.Location = New System.Drawing.Point(23, 38)
Me.txtExp1Name.Name = "txtExp1Name"
Me.txtExp1Name.Size = New System.Drawing.Size(92, 20)
Me.txtExp1Name.TabIndex = 0
'
'txtExp1Val
'
Me.txtExp1Val.Location = New System.Drawing.Point(121, 38)
Me.txtExp1Val.Name = "txtExp1Val"
Me.txtExp1Val.Size = New System.Drawing.Size(188, 20)
Me.txtExp1Val.TabIndex = 1
'
'btnOk
'
Me.btnOk.Location = New System.Drawing.Point(23, 103)
Me.btnOk.Name = "btnOk"
Me.btnOk.Size = New System.Drawing.Size(133, 59)
Me.btnOk.TabIndex = 2
Me.btnOk.Text = "OK"
Me.btnOk.UseVisualStyleBackColor = True
'
'btnCancel
'
Me.btnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel
Me.btnCancel.Location = New System.Drawing.Point(176, 103)
Me.btnCancel.Name = "btnCancel"
Me.btnCancel.Size = New System.Drawing.Size(133, 59)
Me.btnCancel.TabIndex = 3
Me.btnCancel.Text = "Cancel"
Me.btnCancel.UseVisualStyleBackColor = True
'
'Form1
'
Me.AcceptButton = Me.btnOk
Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
Me.CancelButton = Me.btnCancel
Me.ClientSize = New System.Drawing.Size(335, 186)
Me.Controls.Add(Me.btnCancel)
Me.Controls.Add(Me.btnOk)
Me.Controls.Add(Me.txtExp1Val)
Me.Controls.Add(Me.txtExp1Name)
Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle
Me.MaximizeBox = False
Me.MinimizeBox = False
Me.Name = "Configure Dim Reporting"
Me.Text = "Configure Dim Reporting"
Me.ResumeLayout(False)
Me.PerformLayout()
End Sub
Friend WithEvents txtExp1Name As System.Windows.Forms.TextBox
Friend WithEvents txtExp1Val As System.Windows.Forms.TextBox
Friend WithEvents btnOk As System.Windows.Forms.Button
Friend WithEvents btnCancel As System.Windows.Forms.Button
End Class
Dave
Automotive Tooling / Aircraft Tooling / Ground Support Structures
NX1851, Win 10 Pro
I've modified it to work with the specific expression I'd like to change but it's limited to the displayed work part only.
For it to be useful I need to also be able to use it at the assembly level.
Select 1 or more parts and apply the input to all selected.
With one other wrinkle... a drop down list of inputs.
From what I've read this may be an issue that requires a Dynamic winform which is different than the one currently in this code.
Any input??
' This Will show a winform dialogue for editing an expression with "Shape" in the comments column.
' You workpart you want to change has to be the displayed workpart.
Option Strict Off
Imports System
Imports System.Collections.Generic
Imports NXOpen
Imports NXOpen.UF
Module Module1
Public theSession As Session = Session.GetSession()
Public theUfSession As UFSession = UFSession.GetUFSession()
Public Const commentText As String = "Shape"
Dim theUI As UI = UI.GetUI()
Dim lw As ListingWindow = theSession.ListingWindow
Sub Main()
Dim markId1 As Session.UndoMarkId
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "NXJ")
lw.Open()
Dim myExpressions As New List(Of Expression)
For Each temp As Expression In theSession.Parts.Work.Expressions
If temp.RightHandSide.Contains("//") Then
'expression contains comment
Dim expComment As String = ""
expComment = temp.RightHandSide.Substring(temp.RightHandSide.IndexOf("//") + 2).Trim
'lw.WriteLine("comment: " & expComment)
If expComment.ToUpper = commentText.ToUpper Then
myExpressions.Add(temp)
End If
End If
Next
'For Each temp As Expression In myExpressions
' lw.WriteLine("name: " & temp.Name)
'Next
Dim expForm As New Form1
expForm.Expressions = myExpressions
expForm.ShowDialog()
theSession.UpdateManager.DoUpdate(markId1)
lw.Close()
End Sub
Public Function GetUnloadOption(ByVal dummy As String) As Integer
'Unloads the image immediately after execution within NX
GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Immediately
End Function
End Module
Public Class Form1
Private fExpressions As New List(Of NXOpen.Expression)
Public Property Expressions() As List(Of NXOpen.Expression)
Get
Return fExpressions
End Get
Set(ByVal value As List(Of NXOpen.Expression))
fExpressions = value
End Set
End Property
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load
'no error checking is done
txtExp1Name.Text = fExpressions.Item(0).Name
txtExp1Val.Text = fExpressions.Item(0).RightHandSide.Substring(0, fExpressions.Item(0).RightHandSide.IndexOf("//"))
End Sub
Private Sub btnCancel_Click(sender As Object, e As EventArgs) Handles btnCancel.Click
Me.Close()
End Sub
Private Sub btnOk_Click(sender As Object, e As EventArgs) Handles btnOk.Click
Try
fExpressions.Item(0).SetName(txtExp1Name.Text)
Catch ex As NXOpen.NXException
End Try
theSession.Parts.Work.Expressions.Edit(fExpressions.Item(0), txtExp1Val.Text & "//" & commentText)
Me.Close()
End Sub
End Class
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Partial Class Form1
Inherits System.Windows.Forms.Form
'Form overrides dispose to clean up the component list.
<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
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
<System.Diagnostics.DebuggerStepThrough()> _
Private Sub InitializeComponent()
Me.txtExp1Name = New System.Windows.Forms.TextBox()
Me.txtExp1Val = New System.Windows.Forms.TextBox()
Me.btnOk = New System.Windows.Forms.Button()
Me.btnCancel = New System.Windows.Forms.Button()
Me.SuspendLayout()
'
'txtExp1Name
'
Me.txtExp1Name.Location = New System.Drawing.Point(23, 38)
Me.txtExp1Name.Name = "txtExp1Name"
Me.txtExp1Name.Size = New System.Drawing.Size(92, 20)
Me.txtExp1Name.TabIndex = 0
'
'txtExp1Val
'
Me.txtExp1Val.Location = New System.Drawing.Point(121, 38)
Me.txtExp1Val.Name = "txtExp1Val"
Me.txtExp1Val.Size = New System.Drawing.Size(188, 20)
Me.txtExp1Val.TabIndex = 1
'
'btnOk
'
Me.btnOk.Location = New System.Drawing.Point(23, 103)
Me.btnOk.Name = "btnOk"
Me.btnOk.Size = New System.Drawing.Size(133, 59)
Me.btnOk.TabIndex = 2
Me.btnOk.Text = "OK"
Me.btnOk.UseVisualStyleBackColor = True
'
'btnCancel
'
Me.btnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel
Me.btnCancel.Location = New System.Drawing.Point(176, 103)
Me.btnCancel.Name = "btnCancel"
Me.btnCancel.Size = New System.Drawing.Size(133, 59)
Me.btnCancel.TabIndex = 3
Me.btnCancel.Text = "Cancel"
Me.btnCancel.UseVisualStyleBackColor = True
'
'Form1
'
Me.AcceptButton = Me.btnOk
Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
Me.CancelButton = Me.btnCancel
Me.ClientSize = New System.Drawing.Size(335, 186)
Me.Controls.Add(Me.btnCancel)
Me.Controls.Add(Me.btnOk)
Me.Controls.Add(Me.txtExp1Val)
Me.Controls.Add(Me.txtExp1Name)
Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle
Me.MaximizeBox = False
Me.MinimizeBox = False
Me.Name = "Configure Dim Reporting"
Me.Text = "Configure Dim Reporting"
Me.ResumeLayout(False)
Me.PerformLayout()
End Sub
Friend WithEvents txtExp1Name As System.Windows.Forms.TextBox
Friend WithEvents txtExp1Val As System.Windows.Forms.TextBox
Friend WithEvents btnOk As System.Windows.Forms.Button
Friend WithEvents btnCancel As System.Windows.Forms.Button
End Class
Dave
Automotive Tooling / Aircraft Tooling / Ground Support Structures
NX1851, Win 10 Pro