Journal for assigning material

Below is the journal for assigning material to the part:

Upon running material to be assigned is keyed in through windows form.
Also this journal created measure body expression and i have tried to capture the expression with unit as 'kg' and rename the expression as 'Mass' and Mass attribute is added to the attribute properties.

This macro is running fine. But i want to improvise few things.
1.) i want to check if any material is assigned previously and delete if any material is added.
2.) also the macro is failing sometimes if there are so many expressions in the part already. While running the search querf for expression with units 'kg' the macro is failing.

Could you please help in updating the journal.

' NX 12.0.1.7
' Journal created by Balaji_Sampath03 on Fri Mar 13 16:11:05 2019 India Standard Time
'
Imports System
Imports NXOpen
Imports System.Collections.Generic
Imports NXOpen.UF
Imports NXOpenUI

Module NXJournal
Sub Main (ByVal args() As String)

Dim theSession As NXOpen.Session = NXOpen.Session.GetSession()
Dim workPart As NXOpen.Part = theSession.Parts.Work
Dim displayPart As NXOpen.Part = theSession.Parts.Display

' ----------------------------------------------
' Menu: Tools->Materials->Assign Materials...
' ----------------------------------------------

Dim MaterialListBuilder1 As NXOpen.PhysMat.PhysicalMaterialListBuilder = Nothing
MaterialListBuilder1 = workPart.MaterialManager.PhysicalMaterials.CreateListBlockBuilder()

Dim MaterialAssignBuilder1 As NXOpen.PhysMat.PhysicalMaterialAssignBuilder = Nothing
MaterialAssignBuilder1 = workPart.MaterialManager.PhysicalMaterials.CreateMaterialAssignBuilder()

Dim physicalMaterialListBuilder3 As NXOpen.PhysMat.PhysicalMaterialListBuilder = Nothing
physicalMaterialListBuilder3 = workPart.MaterialManager.PhysicalMaterials.CreateListBlockBuilder()

Dim nXObject1 As NXOpen.NXObject = Nothing
Dim physicalMaterial1 As NXOpen.PhysicalMaterial = CType(nXObject1, NXOpen.PhysicalMaterial)

Dim MaterialToAssign As NXOpen.PhysicalMaterial = Nothing
Dim MaterialToAdd As String = Nothing

'create new form object
Dim myForm As New AddMaterial
'set form object properties (current part attribute title and value)
myForm.MaterialToAdd = MaterialToAdd
'display our form
myForm.ShowDialog()

If myForm.Canceled Then
'user pressed cancel, exit journal
Return
Else
'user pressed OK, assign value from form to part attribute
MaterialToAdd = myForm.MaterialToAdd

End If

MaterialToAssign = workPart.MaterialManager.PhysicalMaterials.LoadFromMatmlLibrary("Z:\Knowldege Management\BOK\References\RTCOE_MatLibrary\physicalmateriallibrary.xml", MaterialToAdd)

Dim physicalMaterialBuilder1 As NXOpen.PhysicalMaterialBuilder = Nothing
physicalMaterialBuilder1 = workPart.MaterialManager.PhysicalMaterials.CreatePhysicalMaterialInspectBuilder(MaterialToAssign)
physicalMaterialBuilder1.Destroy()

Dim theBody As Body
If SelectSolidToAssignMaterial("select a body", theBody) = Selection.Response.Cancel Then
Return
End If

Dim theBodies(0) As Body
theBodies(0) = theBody
MaterialToAssign.AssignObjects(theBodies)
MaterialListBuilder1.Destroy()
MaterialAssignBuilder1.Destroy()

' ----------------------------------------------
' Menu: Analysis->Measure Body...
' ----------------------------------------------

'Dim MeasureToDelete As NXOpen.Measure = DeleteMeasure()

Dim nullNXOpen_NXObject As NXOpen.NXObject = Nothing
Dim measureBodyBuilder1 As NXOpen.MeasureBodyBuilder = Nothing
measureBodyBuilder1 = workPart.MeasureManager.CreateMeasureBodyBuilder(nullNXOpen_NXObject)

Dim BodyToMeasure(0) As NXOpen.Body
BodyToMeasure(0) = theBody

Dim bodyDumbRule1 As NXOpen.BodyDumbRule = Nothing
bodyDumbRule1 = workPart.ScRuleFactory.CreateRuleBodyDumb(BodyToMeasure, True)

Dim rules1(0) As NXOpen.SelectionIntentRule
rules1(0) = bodyDumbRule1
measureBodyBuilder1.BodyCollector.ReplaceRules(rules1, False)

Dim massUnits1(4) As NXOpen.Unit
Dim SurfaceArea As NXOpen.Unit = CType(workPart.UnitCollection.FindObject("SquareMilliMeter"), NXOpen.Unit)
Dim Volume As NXOpen.Unit = CType(workPart.UnitCollection.FindObject("CubicMilliMeter"), NXOpen.Unit)
Dim Mass As NXOpen.Unit = CType(workPart.UnitCollection.FindObject("Kilogram"), NXOpen.Unit)
Dim Length As NXOpen.Unit = CType(workPart.UnitCollection.FindObject("MilliMeter"), NXOpen.Unit)
Dim Weight As NXOpen.Unit = CType(workPart.UnitCollection.FindObject("Newton"), NXOpen.Unit)

Dim measureBodies1 As NXOpen.MeasureBodies = Nothing
measureBodies1 = workPart.MeasureManager.NewMassProperties(massUnits1, 0.98999999999999999, False, measureBodyBuilder1.BodyCollector)
Dim measure1 As NXOpen.Measure = Nothing
measure1 = measureBodies1.CreateFeature()

measureBodies1.Dispose()
measureBodyBuilder1.Destroy()

' ----------------------------------------------
' Menu: Tools-> Expression-> Rename Measured Body Expressions
' ----------------------------------------------

For Each temp As Expression In workPart.Expressions

If temp.Units.Symbol = "kg" Then
workPart.Expressions.Rename(temp, "Mass")
End If

' If temp.Units.Symbol = "mm²" Then
' workPart.Expressions.Rename(temp, "SurfaceArea")
' End If

' If temp.Units.Symbol = "mm³" Then
' workPart.Expressions.Rename(temp, "Volume")
' End If

' If temp.Units.Symbol = "N" Then
' workPart.Expressions.Rename(temp, "Weight")
' End If

Next

' ----------------------------------------------
' Dialog Begin Expressions Properties Builder
' ----------------------------------------------

Dim objectsAttribute(0) As NXOpen.NXObject
objectsAttribute(0) = workPart

Dim attributePropertiesBuilder1 As NXOpen.AttributePropertiesBuilder = Nothing
attributePropertiesBuilder1 = theSession.AttributeManager.CreateAttributePropertiesBuilder(workPart, objectsAttribute, NXOpen.AttributePropertiesBuilder.OperationType.None)

attributePropertiesBuilder1.Category = "Materials"
attributePropertiesBuilder1.Title = "Weight"
attributePropertiesBuilder1.DataType = NXOpen.AttributePropertiesBaseBuilder.DataTypeOptions.Number
'attributePropertiesBuilder1.Units = "Tesla"
attributePropertiesBuilder1.Units = "Kilogram"

Dim MassProperties As NXOpen.Expression = Nothing
MassProperties = workPart.Expressions.CreateSystemExpressionWithUnits("0.0", Mass)
MassProperties.RightHandSide = "Mass"
attributePropertiesBuilder1.IsReferenceType = False

attributePropertiesBuilder1.Expression = MassProperties

Dim nXObject2 As NXOpen.NXObject = Nothing
nXObject2 = attributePropertiesBuilder1.Commit()

attributePropertiesBuilder1.Destroy()

End Sub

Function SelectSolidToAssignMaterial(ByVal prompt As String, ByRef selObj As TaggedObject) As Selection.Response

Dim theUI As UI = UI.GetUI
Dim title As String = "Select Solid To Assign Material"
Dim includeFeatures As Boolean = False
Dim keepHighlighted As Boolean = False
Dim selAction As Selection.SelectionAction = Selection.SelectionAction.ClearAndEnableSpecific
Dim cursor As Point3d
Dim scope As Selection.SelectionScope = Selection.SelectionScope.WorkPart
Dim selectionMask_array(0) As Selection.MaskTriple

With selectionMask_array(0)
.Type = UFConstants.UF_solid_type
.SolidBodySubtype = UFConstants.UF_UI_SEL_FEATURE_SOLID_BODY
End With

Dim resp As Selection.Response = theUI.SelectionManager.SelectTaggedObject(prompt, _
title, scope, selAction, _
includeFeatures, keepHighlighted, selectionMask_array, _
selobj, cursor)
If resp = Selection.Response.ObjectSelected OrElse resp = Selection.Response.ObjectSelectedByName Then
Return Selection.Response.Ok
Else
Return Selection.Response.Cancel
End If

End Function

Public Function GetUnloadOption(ByVal dummy As String) As Integer

'Unloads the image immediately after execution within NX
GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Immediately

End Function

'Function DeleteMeasure() As NXOpen.Measure
' Dim objects1(0) As NXOpen.TaggedObject
' Dim MeasureToDelete As NXOpen.Measure = CType(workPart.Features.FindObject("BODY_MEASUREMENT(4)"), NXOpen.Measure)
' objects1(0) = MeasureToDelete
'End Function

End Module

Public Class AddMaterial
Private _frmAttributeValue As String
Public Property MaterialToAdd() As String
Get
Return _frmAttributeValue
End Get
Set(ByVal value As String)
_frmAttributeValue = value
End Set
End Property

Private _canceled As Boolean = False
Public ReadOnly Property Canceled() As Boolean
Get
Return _canceled
End Get
End Property

Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
Label1.Text = "Material"
TextBox1.Text = _frmAttributeValue
End Sub

Private Sub btnCancel_Click(sender As System.Object, e As System.EventArgs) Handles btnCancel.Click
_canceled = True
Me.Close()
End Sub

Private Sub btnOK_Click(sender As System.Object, e As System.EventArgs) Handles btnOK.Click
_frmAttributeValue = TextBox1.Text.ToUpper
Me.Close()
End Sub

End Class

_
Partial Class AddMaterial
Inherits System.Windows.Forms.Form

'Form overrides dispose to clean up the component list.
_
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.
_
Private Sub InitializeComponent()
Me.btnCancel = New System.Windows.Forms.Button()
Me.btnOK = New System.Windows.Forms.Button()
Me.Label1 = New System.Windows.Forms.Label()
Me.TextBox1 = New System.Windows.Forms.TextBox()
Me.SuspendLayout()
'
'btnCancel
'
Me.btnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel
Me.btnCancel.Location = New System.Drawing.Point(178, 107)
Me.btnCancel.Name = "btnCancel"
Me.btnCancel.Size = New System.Drawing.Size(85, 50)
Me.btnCancel.TabIndex = 0
Me.btnCancel.Text = "Cancel"
Me.btnCancel.UseVisualStyleBackColor = True
'
'btnOK
'
Me.btnOK.Location = New System.Drawing.Point(66, 107)
Me.btnOK.Name = "btnOK"
Me.btnOK.Size = New System.Drawing.Size(85, 50)
Me.btnOK.TabIndex = 1
Me.btnOK.Text = "Ok"
Me.btnOK.UseVisualStyleBackColor = True
'
'Label1
'
Me.Label1.Location = New System.Drawing.Point(12, 54)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(79, 13)
Me.Label1.TabIndex = 2
Me.Label1.Text = "Label1"
Me.Label1.TextAlign = System.Drawing.ContentAlignment.MiddleRight
'
'TextBox1
'
Me.TextBox1.Location = New System.Drawing.Point(97, 51)
Me.TextBox1.Name = "TextBox1"
Me.TextBox1.Size = New System.Drawing.Size(166, 20)
Me.TextBox1.TabIndex = 3
'
'MaterialCreation
'
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(284, 176)
Me.Controls.Add(Me.TextBox1)
Me.Controls.Add(Me.Label1)
Me.Controls.Add(Me.btnOK)
Me.Controls.Add(Me.btnCancel)
Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog
Me.MaximizeBox = False
Me.MinimizeBox = False
Me.Name = "AddMaterial"
Me.Text = "AddMaterial"
Me.ResumeLayout(False)
Me.PerformLayout()

End Sub
Friend WithEvents btnCancel As System.Windows.Forms.Button
Friend WithEvents btnOK As System.Windows.Forms.Button
Friend WithEvents Label1 As System.Windows.Forms.Label
Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
End Class

Thanks

hi, im getting the error ' object reference not set to an instance of an object' for the below line

If temp.Units.Symbol = "kg" Then

could you please help me out... thanks

Balaji

If you have any constant expressions in your file, the .Units property will be null. When you try to access a property of a null object, you get the error message.

For Each temp As Expression In theSession.Parts.Work.Expressions

If IsNothing(temp.Units) Then
lw.WriteLine(temp.Name & ": no units")
Else
lw.WriteLine(temp.Name & ": " & temp.Units.Name)
End If

Next

hi thanks for your explanation. lets's say.. i have a number of unit expressions and i want to rename only the expression having unit as 'kg'... could you please give me the code to rename the expression from it's default name 'p100' or something to 'Mass'... thanks :)

Balaji

Take your code that looks for the units and renames the expression and add it to the "else" clause of my code.

hi, thanks a lot. it worked. :):)

Balaji

Hi, below is the updated version of the above journal for assigning material, creating part attribute.
Updates include:
1.Checks for previously assigned material and deletes all material.
2.Deletes all measure body expression.
3.Deletes part attribute titled 'Weight' and recreates the attribute.

Many thanks to the NXJournaling. Have taken so many codes of other journals from this site.(checking the used material/attribute type/edit or renaming expressions).

I have not included any exceptions which i'am thinking of including as soon as i could.
Could someone say if this code could be optimized. Thanks, B

' NX 12.0.1.7
' Journal created by Balaji_Sampath03 on Wed Jul 08 16:53:05 2020 India Standard Time
'**************************************************************************************
'a> This Macro Assigns material to the selected body.
'b> Creates Measure body expression.
'c> Renames the expression with 'kg' unit as 'Mass'
'd> Creates Part Attribute 'Weight' linked to the renamed expression 'Mass'

'While performing the above tasks:
'1> Checks for previously assigned material and deletes all material
'2> Deletes all previous measure body expression
'3> Looks for part attribute with Title 'Weight' and deletes it
'4> looks for expression named 'Mass' and deletes it
'***************************************************************************************
Imports System
Imports NXOpen
Imports System.Collections.Generic
Imports NXOpen.UF
Imports NXOpenUI
Imports NXOpen.Features

Module NXJournal

Dim theSession As NXOpen.Session = NXOpen.Session.GetSession()
Dim workPart As NXOpen.Part = theSession.Parts.Work
Dim displayPart As NXOpen.Part = theSession.Parts.Display
Dim lw As ListingWindow = theSession.ListingWindow

Sub Main (ByVal args() As String)

Const undoMarkName1 As String = "Assign Material"
Dim markId1 As Session.UndoMarkId
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, undoMarkName1)
' ------------------------
' Delete Previous Material
' ------------------------
Dim physicalMaterial As NXOpen.PhysicalMaterial = Nothing

For Each tempMaterial As PhysicalMaterial In workPart.MaterialManager.PhysicalMaterials '.GetUsedMaterials
physicalMaterial = tempMaterial
physicalMaterial.Delete()
Next
' ---------------
' Assign Material
' ---------------
Dim MaterialListBuilder1 As NXOpen.PhysMat.PhysicalMaterialListBuilder = Nothing
MaterialListBuilder1 = workPart.MaterialManager.PhysicalMaterials.CreateListBlockBuilder()

Dim MaterialAssignBuilder1 As NXOpen.PhysMat.PhysicalMaterialAssignBuilder = Nothing
MaterialAssignBuilder1 = workPart.MaterialManager.PhysicalMaterials.CreateMaterialAssignBuilder()

Dim physicalMaterialListBuilder3 As NXOpen.PhysMat.PhysicalMaterialListBuilder = Nothing
physicalMaterialListBuilder3 = workPart.MaterialManager.PhysicalMaterials.CreateListBlockBuilder()

Dim MaterialToAssign As NXOpen.PhysicalMaterial = Nothing
Dim MaterialToAdd As String = Nothing
' ------------------------------------------------
' Create New form Object to get Material to Assign
' ------------------------------------------------
Dim myForm As New AddMaterial
'set form object properties (current part attribute title and value)
myForm.MaterialToAdd = MaterialToAdd
'display our form
myForm.ShowDialog()

If myForm.Canceled Then
'user pressed cancel, exit journal
Return
Else
'user pressed OK, assign value from form to part attribute
MaterialToAdd = myForm.MaterialToAdd
End If

MaterialToAssign = workPart.MaterialManager.PhysicalMaterials.LoadFromMatmlLibrary("D:\physicalmateriallibrary.xml", MaterialToAdd)

Dim physicalMaterialBuilder1 As NXOpen.PhysicalMaterialBuilder = Nothing
physicalMaterialBuilder1 = workPart.MaterialManager.PhysicalMaterials.CreatePhysicalMaterialInspectBuilder(MaterialToAssign)
physicalMaterialBuilder1.Destroy()

' -------------------------------
' Select Soild to Assign Material
' -------------------------------
Dim theBody As Body
If SelectSolidToAssignMaterial("select a body", theBody) = Selection.Response.Cancel Then
Return
End If

Dim theBodies(0) As Body
theBodies(0) = theBody
MaterialToAssign.AssignObjects(theBodies)
MaterialListBuilder1.Destroy()
MaterialAssignBuilder1.Destroy()

lw.WriteLine("Material Assigned:" & myForm.MaterialToAdd)
' ----------------------------
' Delete Previous Body Measure
' ----------------------------
For Each tempMeasure As Feature In theSession.Parts.Work.Features
Dim featureType As String = Nothing
featureType = tempMeasure.FeatureType
If featureType = "BODY_MEASUREMENT" Then
Dim objToDel(0) As NXOpen.TaggedObject
objToDel(0) = tempMeasure
Dim nErrs As Integer = Nothing
nErrs = theSession.UpdateManager.AddObjectsToDeleteList(objToDel)
Dim notifyOnDelete As Boolean = Nothing
notifyOnDelete = theSession.Preferences.Modeling.NotifyOnDelete
End If
Next
' --------------------------------
' Delete Previous Part Attribute
' --------------------------------
If workPart.HasUserAttribute("Weight", NXObject.AttributeType.Any, -1) Then
Dim aInfo As NXObject.AttributeInformation
aInfo = workPart.GetUserAttribute("Weight", NXObject.AttributeType.Any, -1)
workPart.DeleteUserAttribute(aInfo.Type, aInfo.Title, False, Update.Option.Now)
Else
lw.WriteLine("Attribute Titled 'Weight' is not found.New attribute will be created")
End If
' ----------------------------
' Delete Previous expression
' ----------------------------
For Each temp As Expression In theSession.Parts.Work.Expressions
If IsNothing(temp.Units) Then
'lw.WriteLine(temp.Name & ": no units")
Else
If temp.Units.Symbol= "kg" And temp.Name <> "Mass" Then
workPart.Expressions.Delete(temp)
End If
End If
Next
' -------------------
' Create Body Measure
' -------------------
Dim nullNXOpen_NXObject As NXOpen.NXObject = Nothing
Dim measureBodyBuilder1 As NXOpen.MeasureBodyBuilder = Nothing
measureBodyBuilder1 = workPart.MeasureManager.CreateMeasureBodyBuilder(nullNXOpen_NXObject)

Dim BodyToMeasure(0) As NXOpen.Body
BodyToMeasure(0) = theBody

Dim bodyDumbRule1 As NXOpen.BodyDumbRule = Nothing
bodyDumbRule1 = workPart.ScRuleFactory.CreateRuleBodyDumb(BodyToMeasure, True)

Dim rules1(0) As NXOpen.SelectionIntentRule
rules1(0) = bodyDumbRule1
measureBodyBuilder1.BodyCollector.ReplaceRules(rules1, False)

Dim massUnits1(4) As NXOpen.Unit
Dim SurfaceArea As NXOpen.Unit = CType(workPart.UnitCollection.FindObject("SquareMilliMeter"), NXOpen.Unit)
Dim Volume As NXOpen.Unit = CType(workPart.UnitCollection.FindObject("CubicMilliMeter"), NXOpen.Unit)
Dim Mass As NXOpen.Unit = CType(workPart.UnitCollection.FindObject("Kilogram"), NXOpen.Unit)
Dim Length As NXOpen.Unit = CType(workPart.UnitCollection.FindObject("MilliMeter"), NXOpen.Unit)
Dim Weight As NXOpen.Unit = CType(workPart.UnitCollection.FindObject("Newton"), NXOpen.Unit)

Dim measureBodies1 As NXOpen.MeasureBodies = Nothing
measureBodies1 = workPart.MeasureManager.NewMassProperties(massUnits1, 0.98999999999999999, False, measureBodyBuilder1.BodyCollector)
Dim measure1 As NXOpen.Measure = Nothing
measure1 = measureBodies1.CreateFeature()

measureBodies1.Dispose()
measureBodyBuilder1.Destroy()

lw.WriteLine("New Measure Body feature created")

' --------------------------------
' Rename Measured Body Expressions
' --------------------------------
For Each temp As Expression In theSession.Parts.Work.Expressions
If IsNothing(temp.Units) Then
'lw.WriteLine(temp.Name & ": no units")
Else
If temp.Units.Symbol= "kg" Then
workPart.Expressions.Rename(temp, "Mass")
End If
End If
Next
lw.WriteLine("'kg' Unit Expression renamed to 'Mass'")
' ----------------------------------------------
' Dialog Begin Expressions Properties Builder
' ----------------------------------------------
Dim objectsAttribute(0) As NXOpen.NXObject
objectsAttribute(0) = workPart

Dim attributePropertiesBuilder As NXOpen.AttributePropertiesBuilder = Nothing
attributePropertiesBuilder = theSession.AttributeManager.CreateAttributePropertiesBuilder(workPart, objectsAttribute, NXOpen.AttributePropertiesBuilder.OperationType.None)
attributePropertiesBuilder.Category = "Materials"
attributePropertiesBuilder.Title = "Weight"
attributePropertiesBuilder.DataType = NXOpen.AttributePropertiesBaseBuilder.DataTypeOptions.Number
attributePropertiesBuilder.Units = "Kilogram"

Dim MassProperties As NXOpen.Expression = Nothing
MassProperties = workPart.Expressions.CreateSystemExpressionWithUnits("0.0", Mass)
MassProperties.RightHandSide = "Mass"
attributePropertiesBuilder.IsReferenceType = False
attributePropertiesBuilder.Expression = MassProperties

Dim nXObject2 As NXOpen.NXObject = Nothing
nXObject2 = attributePropertiesBuilder.Commit()
attributePropertiesBuilder.Destroy()

lw.WriteLine("Part attribute 'Weight' created")

End Sub

Function SelectSolidToAssignMaterial(ByVal prompt As String, ByRef selObj As TaggedObject) As Selection.Response
Dim theUI As UI = UI.GetUI
Dim title As String = "Select Solid To Assign Material"
Dim includeFeatures As Boolean = False
Dim keepHighlighted As Boolean = False
Dim selAction As Selection.SelectionAction = Selection.SelectionAction.ClearAndEnableSpecific
Dim cursor As Point3d
Dim scope As Selection.SelectionScope = Selection.SelectionScope.WorkPart
Dim selectionMask_array(0) As Selection.MaskTriple

With selectionMask_array(0)
.Type = UFConstants.UF_solid_type
.SolidBodySubtype = UFConstants.UF_UI_SEL_FEATURE_SOLID_BODY
End With

Dim resp As Selection.Response = theUI.SelectionManager.SelectTaggedObject(prompt, _
title, scope, selAction, _
includeFeatures, keepHighlighted, selectionMask_array, _
selobj, cursor)
If resp = Selection.Response.ObjectSelected OrElse resp = Selection.Response.ObjectSelectedByName Then
Return Selection.Response.Ok
Else
Return Selection.Response.Cancel
End If
End Function

Public Function GetUnloadOption(ByVal dummy As String) As Integer
'Unloads the image immediately after execution within NX
GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Immediately
End Function

'Function DeleteMeasure() As NXOpen.Measure
' Dim objects1(0) As NXOpen.TaggedObject
' Dim MeasureToDelete As NXOpen.Measure = CType(workPart.Features.FindObject("BODY_MEASUREMENT(4)"), NXOpen.Measure)
' objects1(0) = MeasureToDelete
'End Function

End Module

Public Class AddMaterial
Private _frmAttributeValue As String
Public Property MaterialToAdd() As String
Get
Return _frmAttributeValue
End Get
Set(ByVal value As String)
_frmAttributeValue = value
End Set
End Property

Private _canceled As Boolean = False
Public ReadOnly Property Canceled() As Boolean
Get
Return _canceled
End Get
End Property

Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
Label1.Text = "Material"
TextBox1.Text = _frmAttributeValue
End Sub

Private Sub btnCancel_Click(sender As System.Object, e As System.EventArgs) Handles btnCancel.Click
_canceled = True
Me.Close()
End Sub

Private Sub btnOK_Click(sender As System.Object, e As System.EventArgs) Handles btnOK.Click
_frmAttributeValue = TextBox1.Text.ToUpper
Me.Close()
End Sub

End Class

_
Partial Class AddMaterial
Inherits System.Windows.Forms.Form

'Form overrides dispose to clean up the component list.
_
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.
_
Private Sub InitializeComponent()
Me.btnCancel = New System.Windows.Forms.Button()
Me.btnOK = New System.Windows.Forms.Button()
Me.Label1 = New System.Windows.Forms.Label()
Me.TextBox1 = New System.Windows.Forms.TextBox()
Me.SuspendLayout()
'
'btnCancel
'
Me.btnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel
Me.btnCancel.Location = New System.Drawing.Point(178, 107)
Me.btnCancel.Name = "btnCancel"
Me.btnCancel.Size = New System.Drawing.Size(85, 50)
Me.btnCancel.TabIndex = 0
Me.btnCancel.Text = "Cancel"
Me.btnCancel.UseVisualStyleBackColor = True
'
'btnOK
'
Me.btnOK.Location = New System.Drawing.Point(66, 107)
Me.btnOK.Name = "btnOK"
Me.btnOK.Size = New System.Drawing.Size(85, 50)
Me.btnOK.TabIndex = 1
Me.btnOK.Text = "Ok"
Me.btnOK.UseVisualStyleBackColor = True
'
'Label1
'
Me.Label1.Location = New System.Drawing.Point(12, 54)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(79, 13)
Me.Label1.TabIndex = 2
Me.Label1.Text = "Label1"
Me.Label1.TextAlign = System.Drawing.ContentAlignment.MiddleRight
'
'TextBox1
'
Me.TextBox1.Location = New System.Drawing.Point(97, 51)
Me.TextBox1.Name = "TextBox1"
Me.TextBox1.Size = New System.Drawing.Size(166, 20)
Me.TextBox1.TabIndex = 3
'
'MaterialCreation
'
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(284, 176)
Me.Controls.Add(Me.TextBox1)
Me.Controls.Add(Me.Label1)
Me.Controls.Add(Me.btnOK)
Me.Controls.Add(Me.btnCancel)
Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog
Me.MaximizeBox = False
Me.MinimizeBox = False
Me.Name = "AddMaterial"
Me.Text = "AddMaterial"
Me.ResumeLayout(False)
Me.PerformLayout()

End Sub
Friend WithEvents btnCancel As System.Windows.Forms.Button
Friend WithEvents btnOK As System.Windows.Forms.Button
Friend WithEvents Label1 As System.Windows.Forms.Label
Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
End Class

Balaji

Looking for a journal to assign material to certain component solids of an assembly by selecting the components and not having to go into the component file. Currently using NX1892 and up. Thanks in advance.

AngieL