NX11 - Journal code for changing solid body attributes?
NX11 - Journal code for changing solid body attributes?
(OP)
We had a button that would take the solid body that was already selected, clear all the "solid body" attributes/properties, then add the following properties....
TOOL_CLASS = ALT STD
STOCK_SIZE = ANL217
PURCH_OPTION = P
DB_PART_NAME = NC BLANK
NOTE: This is how I added them through properties...(TITLE/ALIAS = VALUE) I used a string type for all attributes I added.
We are in the middle of switching from NX9 to NX11 and unfortunately this button ran a Macro instead of a Journal. Which now errors out when you run it.
I have tried to record Journals to clear all properties and add these properties but when I try playing them back, they always error out. Saying something about an attribute that is not modifiable so it cannot be set changed or deleted. Which doesnt make sense to me because it allowed me to delete the attributes while recording the journal. lol
Would anyone have any ideas about that or better yet, have code that does the general same thing that I could manipulate to the attributes we need?
TOOL_CLASS = ALT STD
STOCK_SIZE = ANL217
PURCH_OPTION = P
DB_PART_NAME = NC BLANK
NOTE: This is how I added them through properties...(TITLE/ALIAS = VALUE) I used a string type for all attributes I added.
We are in the middle of switching from NX9 to NX11 and unfortunately this button ran a Macro instead of a Journal. Which now errors out when you run it.
I have tried to record Journals to clear all properties and add these properties but when I try playing them back, they always error out. Saying something about an attribute that is not modifiable so it cannot be set changed or deleted. Which doesnt make sense to me because it allowed me to delete the attributes while recording the journal. lol
Would anyone have any ideas about that or better yet, have code that does the general same thing that I could manipulate to the attributes we need?





RE: NX11 - Journal code for changing solid body attributes?
CODE
Option Strict Off Imports System Imports System.Collections.Generic Imports NXOpen Imports NXOpen.UF Module Module1 Dim theSession As Session = Session.GetSession() Dim theUfSession As UFSession = UFSession.GetUFSession() 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, "body attributes") lw.Open() Dim selobj As NXObject Dim type As Integer Dim subtype As Integer Dim theBodies As New List(Of Body) Dim theUI As UI = UI.GetUI Dim numsel As Integer = theUI.SelectionManager.GetNumSelectedObjects() 'process the preselected bodies If numsel > 0 Then For inx As Integer = 0 To numsel - 1 selobj = theUI.SelectionManager.GetSelectedTaggedObject(inx) theUfSession.Obj.AskTypeAndSubtype(selobj.Tag, type, subtype) If type = UFConstants.UF_solid_type Then theBodies.Add(selobj) End If Next Else 'prompt to select bodies If SelectBodies("Select Bodies to reset attributes", theBodies) = Selection.Response.Cancel Then Return End If End If For Each temp As Body In theBodies DeleteAllAttributes(temp) AddBodyAttribute(temp, "TOOL_CLASS", "ALT STD") AddBodyAttribute(temp, "STOCK_SIZE", "ANL217") AddBodyAttribute(temp, "PURCH_OPTION", "P") AddBodyAttribute(temp, "DB_PART_NAME", "NC BLANK") Next lw.Close() End Sub Function SelectBodies(ByVal prompt As String, ByRef selBod As List(Of Body)) As Selection.Response Dim theUI As UI = UI.GetUI Dim title As String = "Select bodies" Dim includeFeatures As Boolean = False Dim keepHighlighted As Boolean = False Dim selAction As Selection.SelectionAction = Selection.SelectionAction.ClearAndEnableSpecific Dim scope As Selection.SelectionScope = Selection.SelectionScope.WorkPart Dim selectionMask_array(0) As Selection.MaskTriple Dim selObj() As TaggedObject With selectionMask_array(0) .Type = UFConstants.UF_solid_type .SolidBodySubtype = UFConstants.UF_UI_SEL_FEATURE_BODY End With Dim resp As Selection.Response = theUI.SelectionManager.SelectTaggedObjects(prompt, title, scope, selAction, includeFeatures, keepHighlighted, selectionMask_array, selObj) If resp = Selection.Response.Ok Then For Each temp As TaggedObject In selObj selBod.Add(temp) Next Return Selection.Response.Ok Else Return Selection.Response.Cancel End If End Function Sub AddBodyAttribute(ByVal theBody As Body, ByVal attTitle As String, ByVal attValue As String) Dim markId4 As Session.UndoMarkId markId4 = theSession.SetUndoMark(Session.MarkVisibility.Invisible, "add body attribute") Dim attributePropertiesBuilder1 As AttributePropertiesBuilder attributePropertiesBuilder1 = theSession.AttributeManager.CreateAttributePropertiesBuilder(theSession.Parts.Work, {theBody}, AttributePropertiesBuilder.OperationType.None) attributePropertiesBuilder1.IsArray = False attributePropertiesBuilder1.DataType = AttributePropertiesBaseBuilder.DataTypeOptions.String attributePropertiesBuilder1.Title = attTitle attributePropertiesBuilder1.StringValue = attValue Dim nXObject1 As NXObject nXObject1 = attributePropertiesBuilder1.Commit() Dim id1 As Session.UndoMarkId id1 = theSession.GetNewestUndoMark(Session.MarkVisibility.Visible) Dim nErrs1 As Integer nErrs1 = theSession.UpdateManager.DoUpdate(id1) attributePropertiesBuilder1.Destroy() End Sub Sub DeleteAllAttributes(ByVal theObject As NXObject) Dim attributeInfo() As NXObject.AttributeInformation = theObject.GetUserAttributes For Each temp As NXObject.AttributeInformation In attributeInfo theObject.DeleteUserAttributes(temp.Type, Update.Option.Now) Next 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 Modulewww.nxjournaling.com
RE: NX11 - Journal code for changing solid body attributes?
RE: NX11 - Journal code for changing solid body attributes?
I have modified Cowski's journal to get this attribute result but what I desire is to be prompted to enter a string for each attribute (i.e. "MATERIAL", ("") and then I would type material type etc.
PART_NAME = STRING (String)
PART_NUMBER = STRING (String)
TOOL_NUMBER = STRING (String)
DET_NUMBER = STRING (String)
MATERIAL = STRING (String)
STOCK_SIZE = STRING (String)
HEAT_TREAT = STRING (String)
SURFACE_FINISH = STRING (String)
I'm frankly terrible with journaling - is there an easy way to add this functionality?
~Felicia H.
NX 9.0.2.5
"Design all things as simple as possible but not simpler."
RE: NX11 - Journal code for changing solid body attributes?
http://www.nxjournaling.com/content/user-input-inp...
If you want to get fancy and have the time to dig into it, you could create your own input form to show all the required input at the same time, something like:
thread561-406179: attribute windows . need another row
www.nxjournaling.com
RE: NX11 - Journal code for changing solid body attributes?
The first link you posted is exactly the one I tried to add to (I think) another of your or John Baker's journals but it errors out probably because I'm a daft coder :)
Option Strict Off
Imports System
Imports System.Collections.Generic
Imports NXOpen
Imports NXOpen.UF
Module Module1
Dim theSession As Session = Session.GetSession()
Dim theUfSession As UFSession = UFSession.GetUFSession()
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, "body attributes")
lw.Open()
Dim selobj As NXObject
Dim type As Integer
Dim subtype As Integer
Dim theBodies As New List(Of Body)
Dim theUI As UI = UI.GetUI
Dim numsel As Integer = theUI.SelectionManager.GetNumSelectedObjects()
Dim answer As String = ""
'process the preselected bodies
If numsel > 0 Then
For inx As Integer = 0 To numsel - 1
selobj = theUI.SelectionManager.GetSelectedTaggedObject(inx)
theUfSession.Obj.AskTypeAndSubtype(selobj.Tag, type, subtype)
If type = UFConstants.UF_solid_type Then
theBodies.Add(selobj)
End If
Next
Else
'prompt to select bodies
If SelectBodies("Select Bodies to reset attributes", theBodies) = Selection.Response.Cancel Then
Return
End If
End If
For Each temp As Body In theBodies
DeleteAllAttributes(temp)
AddBodyAttribute(temp, "SURFACE_FINISH", "STRING")
'input box: prompt only
answer = NXInputBox.GetInputString("prompt only")
'input box: prompt and title
answer = NXInputBox.GetInputString("prompt", "title bar caption")
'input box: prompt, title, and initial text
answer = NXInputBox.GetInputString("prompt", "title bar caption", "initial text")
'echo the input
MsgBox("answer: """ & answer & """")
AddBodyAttribute(temp, "HEAT_TREAT", "STRING")
AddBodyAttribute(temp, "STOCK_SIZE", "STRING")
AddBodyAttribute(temp, "MATERIAL", "STRING")
AddBodyAttribute(temp, "DET_NUMBER", "STRING")
AddBodyAttribute(temp, "TOOL_NUMBER", "STRING")
AddBodyAttribute(temp, "PART_NUMBER", "STRING")
AddBodyAttribute(temp, "PART_NAME", "STRING")
Next
lw.Close()
End Sub
Function SelectBodies(ByVal prompt As String, ByRef selBod As List(Of Body)) As Selection.Response
Dim theUI As UI = UI.GetUI
Dim title As String = "Select bodies"
Dim includeFeatures As Boolean = False
Dim keepHighlighted As Boolean = False
Dim selAction As Selection.SelectionAction = Selection.SelectionAction.ClearAndEnableSpecific
Dim scope As Selection.SelectionScope = Selection.SelectionScope.WorkPart
Dim selectionMask_array(0) As Selection.MaskTriple
Dim selObj() As TaggedObject
With selectionMask_array(0)
.Type = UFConstants.UF_solid_type
.SolidBodySubtype = UFConstants.UF_UI_SEL_FEATURE_BODY
End With
Dim resp As Selection.Response = theUI.SelectionManager.SelectTaggedObjects(prompt,
title, scope, selAction,
includeFeatures, keepHighlighted, selectionMask_array, selObj)
If resp = Selection.Response.Ok Then
For Each temp As TaggedObject In selObj
selBod.Add(temp)
Next
Return Selection.Response.Ok
Else
Return Selection.Response.Cancel
End If
End Function
Sub AddBodyAttribute(ByVal theBody As Body, ByVal attTitle As String, ByVal attValue As String)
Dim markId4 As Session.UndoMarkId
markId4 = theSession.SetUndoMark(Session.MarkVisibility.Invisible, "add body attribute")
Dim attributePropertiesBuilder1 As AttributePropertiesBuilder
attributePropertiesBuilder1 = theSession.AttributeManager.CreateAttributePropertiesBuilder(theSession.Parts.Work, {theBody}, AttributePropertiesBuilder.OperationType.None)
attributePropertiesBuilder1.IsArray = False
attributePropertiesBuilder1.DataType = AttributePropertiesBaseBuilder.DataTypeOptions.String
attributePropertiesBuilder1.Title = attTitle
attributePropertiesBuilder1.StringValue = attValue
Dim nXObject1 As NXObject
nXObject1 = attributePropertiesBuilder1.Commit()
Dim id1 As Session.UndoMarkId
id1 = theSession.GetNewestUndoMark(Session.MarkVisibility.Visible)
Dim nErrs1 As Integer
nErrs1 = theSession.UpdateManager.DoUpdate(id1)
attributePropertiesBuilder1.Destroy()
End Sub
Sub DeleteAllAttributes(ByVal theObject As NXObject)
Dim attributeInfo() As NXObject.AttributeInformation = theObject.GetUserAttributes
For Each temp As NXObject.AttributeInformation In attributeInfo
theObject.DeleteUserAttributes(temp.Type, Update.Option.Now)
Next
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
~Felicia H.
NX 9.0.2.5
"Design all things as simple as possible but not simpler."
RE: NX11 - Journal code for changing solid body attributes?
CODE
OR
change the NXInputBox references from
CODE
to:
CODE
www.nxjournaling.com
RE: NX11 - Journal code for changing solid body attributes?
That helped but I'm at a loss for how to proceed further. In the sub below once I select a body I'm prompted to add a string but the string I enter is not being passed to the attribute.
Near the top I have
Dim answer As String = ""
Then,
For Each temp As Body In theBodies
DeleteAllAttributes(temp)
AddBodyAttribute(temp, "Detail Number", "")
'input box: prompt only
answer = NXInputBox.GetInputString("")
'input box: prompt and title
answer = NXInputBox.GetInputString("Material", "")
'input box: prompt, title, and initial text
answer = NXInputBox.GetInputString("Stock Size", "")
'input box: prompt, title, and initial text
answer = NXInputBox.GetInputString("Heat Treat", "")
'input box: prompt, title, and initial text
answer = NXInputBox.GetInputString("Surface Treatment", "")
'echo the input
MsgBox("answer: """ & answer & """")
Next
lw.Close()
End Sub
~Felicia H.
NX 9.0.2.5
"Design all things as simple as possible but not simpler."
RE: NX11 - Journal code for changing solid body attributes?
CODE
For Each temp As Body In theBodies DeleteAllAttributes(temp) 'input box: prompt and title answer = NXInputBox.GetInputString("Detail Number", "") AddBodyAttribute(temp, "DET_NUMBER", answer) 'input box: prompt and title answer = NXInputBox.GetInputString("Heat Treat", "") AddBodyAttribute(temp, "HEAT_TREAT", answer) 'add other attributes as needed Nextwww.nxjournaling.com
RE: NX11 - Journal code for changing solid body attributes?
I feel like it's calling a Microsoft dialog box rather than an NX and the screen position of it isn't great but it works!
I owe you a cocktail
Here it is for anyone else looking for the same thing:
Option Strict Off
Imports NXOpenUI
Imports System
Imports System.Collections.Generic
Imports NXOpen
Imports NXOpen.UF
Module Module1
Dim theSession As Session = Session.GetSession()
Dim theUfSession As UFSession = UFSession.GetUFSession()
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, "body attributes")
lw.Open()
Dim selobj As NXObject
Dim type As Integer
Dim subtype As Integer
Dim theBodies As New List(Of Body)
Dim theUI As UI = UI.GetUI
Dim numsel As Integer = theUI.SelectionManager.GetNumSelectedObjects()
Dim answer As String = ""
'process the preselected bodies
If numsel > 0 Then
For inx As Integer = 0 To numsel - 1
selobj = theUI.SelectionManager.GetSelectedTaggedObject(inx)
theUfSession.Obj.AskTypeAndSubtype(selobj.Tag, type, subtype)
If type = UFConstants.UF_solid_type Then
theBodies.Add(selobj)
End If
Next
Else
'prompt to select bodies
If SelectBodies("Select Bodies to reset attributes", theBodies) = Selection.Response.Cancel Then
Return
End If
End If
For Each temp As Body In theBodies
DeleteAllAttributes(temp)
'input box: prompt and title
answer = NXInputBox.GetInputString("Detail Name", "")
AddBodyAttribute(temp, "DET_NAME", answer)
'input box: prompt and title
answer = NXInputBox.GetInputString("Detail Number", "")
AddBodyAttribute(temp, "DET_NUMBER", answer)
'input box: prompt and title
answer = NXInputBox.GetInputString("Material", "")
AddBodyAttribute(temp, "MAT'L", answer)
'input box: prompt and title
answer = NXInputBox.GetInputString("Stock Size", "")
AddBodyAttribute(temp, "STOCK_SIZE", answer)
'input box: prompt and title
answer = NXInputBox.GetInputString("Heat Treat", "")
AddBodyAttribute(temp, "HEAT_TREAT", answer)
'input box: prompt and title
answer = NXInputBox.GetInputString("Surface Finish", "")
AddBodyAttribute(temp, "SURFACE_FINISH", answer)
'input box: prompt and title
answer = NXInputBox.GetInputString("Vendor", "")
AddBodyAttribute(temp, "VENDOR", answer)
'add other attributes as needed
Next
lw.Close()
End Sub
Function SelectBodies(ByVal prompt As String, ByRef selBod As List(Of Body)) As Selection.Response
Dim theUI As UI = UI.GetUI
Dim title As String = "Select bodies"
Dim includeFeatures As Boolean = False
Dim keepHighlighted As Boolean = False
Dim selAction As Selection.SelectionAction = Selection.SelectionAction.ClearAndEnableSpecific
Dim scope As Selection.SelectionScope = Selection.SelectionScope.WorkPart
Dim selectionMask_array(0) As Selection.MaskTriple
Dim selObj() As TaggedObject
With selectionMask_array(0)
.Type = UFConstants.UF_solid_type
.SolidBodySubtype = UFConstants.UF_UI_SEL_FEATURE_BODY
End With
Dim resp As Selection.Response = theUI.SelectionManager.SelectTaggedObjects(prompt,
title, scope, selAction,
includeFeatures, keepHighlighted, selectionMask_array, selObj)
If resp = Selection.Response.Ok Then
For Each temp As TaggedObject In selObj
selBod.Add(temp)
Next
Return Selection.Response.Ok
Else
Return Selection.Response.Cancel
End If
End Function
Sub AddBodyAttribute(ByVal theBody As Body, ByVal attTitle As String, ByVal attValue As String)
Dim markId4 As Session.UndoMarkId
markId4 = theSession.SetUndoMark(Session.MarkVisibility.Invisible, "add body attribute")
Dim attributePropertiesBuilder1 As AttributePropertiesBuilder
attributePropertiesBuilder1 = theSession.AttributeManager.CreateAttributePropertiesBuilder(theSession.Parts.Work, {theBody}, AttributePropertiesBuilder.OperationType.None)
attributePropertiesBuilder1.IsArray = False
attributePropertiesBuilder1.DataType = AttributePropertiesBaseBuilder.DataTypeOptions.String
attributePropertiesBuilder1.Title = attTitle
attributePropertiesBuilder1.StringValue = attValue
Dim nXObject1 As NXObject
nXObject1 = attributePropertiesBuilder1.Commit()
Dim id1 As Session.UndoMarkId
id1 = theSession.GetNewestUndoMark(Session.MarkVisibility.Visible)
Dim nErrs1 As Integer
nErrs1 = theSession.UpdateManager.DoUpdate(id1)
attributePropertiesBuilder1.Destroy()
End Sub
Sub DeleteAllAttributes(ByVal theObject As NXObject)
Dim attributeInfo() As NXObject.AttributeInformation = theObject.GetUserAttributes
For Each temp As NXObject.AttributeInformation In attributeInfo
theObject.DeleteUserAttributes(temp.Type, Update.Option.Now)
Next
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
~Felicia H.
NX 9.0.2.5
"Design all things as simple as possible but not simpler."
RE: NX11 - Journal code for changing solid body attributes?
https://msdn.microsoft.com/en-us/library/microsoft...
www.nxjournaling.com
RE: NX11 - Journal code for changing solid body attributes?
Big bummer...
~Felicia H.
NX 9.0.2.5
"Design all things as simple as possible but not simpler."