Forums:
Hi All,
I would like to get material name from part or body or body(linked) in assembly.
First I tried to get it from attributes but it didn't lead anywhere. Attributes were empty probably due to company settings.
The best way would be to work with "User MatML Library" because I need more then material name, like thermal conductivity etc. Till now I have not got it work.
Using AskMaterialOfObject is not possible due to older NX version that I am using
So what i made so far is using "UF_SF_locate_material", see code below
UF_SF_locate_material
My problem is why it only works on linked bodies in assembly and not on the parts? If I select part then it generate error. If I run it in displayed part view then it is ok.
thanks for help
Option Strict Off Imports System Imports NXOpen Imports NXOpen.UFImports System.CollectionsImports System.Collections.Generic Module RetrieveMat Dim ui As UI = UI.GetUI() Sub Main()Dim theSession As Session = Session.GetSession()Dim workPart As Part = theSession.Parts.WorkDim lw As ListingWindow = theSession.ListingWindowDim ufs As UFSession = UFSession.GetUFSession() lw.Open() Dim selectionMask()As Selection.MaskTriple=Nothing BuildSelectionMask(selectionMask)Dim prompt AsStringDim title AsString Dim myBodies()As TaggedObject =Nothing prompt ="Select Bodies bodies" title ="Select Bodies bodies"If SelectObjects(selectionMask, myBodies, prompt, title)= Selection.Response.CancelThen Return EndIf lw.WriteLine("Number of bodies: "& myBodies.Length) Dim MaterialTag As Tag ForEach tmpbody As Body In myBodies lw.WriteLine("body: "& tmpbody.Tag) ufs.Sf.LocateMaterial(tmpbody.Tag, MaterialTag)Dim MaterialObject As Material MaterialObject = theSession.GetObjectManager.GetTaggedObject(MaterialTag) lw.WriteLine("Material Name: "& MaterialObject.Name)Next lw.Close()EndSubSub BuildSelectionMask(ByRef maskArray()As Selection.MaskTriple) Dim theSelectionMasks AsNew List(Of Selection.MaskTriple)Dim newSelMask As Selection.MaskTripleWith newSelMask .Type= UFConstants.UF_solid_type.SolidBodySubtype= UFConstants.UF_UI_SEL_FEATURE_BODY.SolidBodySubtype= UFConstants.UF_UI_SEL_FEATURE_SOLID_BODYEndWith theSelectionMasks.Add(newSelMask) maskArray = theSelectionMasks.ToArrayEndSubFunction SelectObjects(ByVal selMask()As Selection.MaskTriple, ByRef selObj()As TaggedObject, ByVal prompt AsString, ByVal title AsString)As Selection.Response Dim theUI As UI = UI.GetUI Dim includeFeatures AsBoolean=FalseDim keepHighlighted AsBoolean=FalseDim selAction As Selection.SelectionAction= Selection.SelectionAction.ClearAndEnableSpecific Dim scope As Selection.SelectionScope= Selection.SelectionScope.AnyInAssemblyDim resp As Selection.Response= theUI.SelectionManager.SelectTaggedObjects( prompt, title, scope, selAction, includeFeatures, keepHighlighted, selMask, selObj) If resp = Selection.Response.OkThenReturn Selection.Response.OkElseReturn Selection.Response.CancelEndIf EndFunction PublicFunction GetUnloadOption(ByVal dummy AsString)AsInteger'Unloads the image when the NX session terminates'GetUnloadOption = NXOpen.Session.LibraryUnloadOption.AtTermination GetUnloadOption = NXOpen.Session.LibraryUnloadOption.ImmediatelyEndFunction EndModule