Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations KootK on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Assign Material with NX Journal 1

Status
Not open for further replies.

nxexplorer

Mechanical
Jun 23, 2010
84
I need help to create NX Journal (VB) for Assigning the Material in the workpart, where the material's name comes from the existing value of a String Attribute which is also similar to the one of Material's name in the Material Library.
'====================================================================
Option Strict Off
Imports System
Imports NXOpen

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

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

Dim physicalMaterialListBuilder1 As PhysMat.PhysicalMaterialListBuilder
Dim physicalMaterialAssignBuilder1 As PhysMat.PhysicalMaterialAssignBuilder
Dim id1 As Session.UndoMarkId
Dim markId3 As Session.UndoMarkId
Dim physicalMaterial1 As PhysicalMaterial
Dim markId2 As Session.UndoMarkId
Dim str_pre_matl As String = workPart.GetStringAttribute( "preMATL" )

markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Start")
physicalMaterialListBuilder1 = workPart.MaterialManager.PhysicalMaterials.CreateListBlockBuilder()
physicalMaterialAssignBuilder1 = workPart.MaterialManager.PhysicalMaterials.CreateMaterialAssignBuilder()
theSession.SetUndoMarkName(markId1, "Assign Material Dialog")
id1 = theSession.GetNewestUndoMark(Session.MarkVisibility.AnyVisibility)
markId2 = theSession.SetUndoMark(Session.MarkVisibility.Invisible, "Assign Material")
theSession.DeleteUndoMark(markId2, Nothing)
markId3 = theSession.SetUndoMark(Session.MarkVisibility.Invisible, "Assign Material")
physicalMaterial1 = workPart.MaterialManager.PhysicalMaterials.LoadFromNxmatmllibrary("&str_pre_matl&")
physicalMaterial1.AssignToAllBodies()
theSession.DeleteUndoMark(markId3, Nothing)
theSession.SetUndoMarkName(id1, "Assign Material")
physicalMaterialAssignBuilder1.Destroy()
physicalMaterialListBuilder1.Destroy()

End Sub
End Module
'====================================================
Any suggest is very much appreciated.


Best Regards,
Maryadi
 
Replies continue below

Recommended for you

I think you are trying to do this the "opposite" way of how it should be done.

This is how it is designed to work:
When you assign a material in NX,
NX will create an attribute with the value = material name. ( Customer defaults Gateway - Materials/Mass - Attributes - "Create Attribute")
This attribute is read-only for the user , the way to change it is to assign a different material or remove .
Doing it this way we remove the possibility for human errors.
The possibility to have a mismatch between the manual attribute and the assigned material is removed.


Regards,
Tomas

 
Hi Tomas,
Yes, you are correct. I try to apply the material to all solid bodies in the work part, with the name of material as a string defined in another part attribute. This is because I need to shorten the steps.

Thank you for the suggestion.

Best Regards,
Maryadi


 
We created a pulldown menu for "quick assign material" in which we only displayed the most frequent materials, it's a text dialog but divided into groups like "Aluminium" "Steel" "Stainless steel" etc. This option will use the assign option "All bodies in work part" and assign the selected material to these.
That journal will also change the color of the solids , stainless steel is white-grey compared to steel which has a slight blue tint etc.

Regards,
Tomas
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor