×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Assign the same material to all component accross the assembly
2

Assign the same material to all component accross the assembly

Assign the same material to all component accross the assembly

(OP)
I know that there is no way to assign the same material to all component accross the assembly in one operation.

Does anybody have a journal to do this ?

Thanks in advance

I am using NX7.5 and NX8


Regards
Didier Psaltopoulos
http://www.psi-cad.com

RE: Assign the same material to all component accross the assembly

AFAIk - you have to do some programming maybe cowski or frank have jounal for you

RE: Assign the same material to all component accross the assembly

(OP)
Hi

Nobody can help me ?


Regards
Didier Psaltopoulos
http://www.psi-cad.com

RE: Assign the same material to all component accross the assembly

Can't you just drawn a rectangular around the assembly so you have selected everything and drag the material to it? In the Assign Material menu you see beneath Type, Select Body(s), doesn't that mean you can pick multiple components?

Best regards,

Michaël.

NX7.5.4.4 + TC Unified 8.3
Win 7 64 bit (Intel(R) Xeon(R) CPU X5650 @2.67GHz)
24.0 GB
NVIDIA Quadro 4000 + NVIDIA Tesla C2050

RE: Assign the same material to all component accross the assembly

(OP)
It's not possible because the filter selection accross assembly is disabled. Try it


Regards
Didier Psaltopoulos
http://www.psi-cad.com

RE: Assign the same material to all component accross the assembly

Didier,

Please see if this meets your needs. Edit the desired material accordingly (two places).

HTH, Joe

CODE --> VB

' This program will walk an assembly structure.  For each component it will:
' Assign physical materials to the bodies in the components.
' This program changes the displayed part instead of simply changing the work part.
' Changing displayed part is slower than just changing work part, but it is safer.  If you
' have mixed unit parts (english / metric) then the program will error when trying to change
' work parts.

Option Strict Off
Imports System
Imports System.IO
Imports System.Collections

Imports NXOpen
Imports NXOpen.Assemblies
Imports NXOpen.UF
Imports NXOpenUI
Imports NXOpen.UIStyler

Module NXJournal
    ' Declare module variables.  These are available to all subroutines.
    Dim theSession As Session = Session.GetSession()
    Dim alreadyProcessed As Hashtable
    Dim knt As Integer = 0
    Dim partLoadStat As PartLoadStatus
    Dim LW As ListingWindow = theSession.ListingWindow
    Dim displayPart As Part = theSession.Parts.Display
    Dim workPart As Part

    Sub Main()  ' Program entry point
        LW.Open()
        LW.WriteLine("Listing child components")

        Try

            Dim part1 As Part = theSession.Parts.Work
            LW.WriteLine("Work part: " & part1.FullPath)
            LW.WriteLine(part1.Leaf)
            LW.WriteLine(CType(TimeOfDay(), String))

            ' Initialize a hash table to store components that have been processed.
            ' This will prevent components from being processed twice
            alreadyProcessed = New Hashtable

            Dim c As ComponentAssembly = part1.ComponentAssembly
		LW.WriteLine("first walk: ")
            Walk(c.RootComponent, 0)

            ' When the program is done "walking" the assembly it will return here.
            ' Set the work part back to what it was
			LW.WriteLine("Done: ")
            theSession.Parts.SetDisplay(part1, False, False, partLoadStat)

            LW.WriteLine(CType(TimeOfDay(), String))
        Catch e As Exception
            LW.WriteLine("Error running application: " & e.Message)
        End Try
    End Sub

    Sub Walk(ByVal c As Component, ByVal level As Integer)
	  LW.WriteLine("Walking: ")
        Dim ufs As UFSession = UFSession.GetUFSession()

        'Dim wrap As String = Chr(10)
        'Dim dwrap As String = wrap & wrap

        'Dim title As String
        'Dim value As String
        'Dim inx As Integer = 0
	
        Dim prototype As Part
        Dim children As Component() = c.GetChildren()

        Dim child As Component
        prototype = CType(c.Prototype, Part)

		'LW.WriteLine("Component: " & child.ToString)
             LW.WriteLine("Component: " & c.ToString)
		
        If Not alreadyProcessed.Contains(prototype.Leaf) Then

            ' Add this prototype to the hash table so that we don't process it again
            alreadyProcessed.Add(prototype.Leaf, prototype.Leaf)
            knt = knt + 1
            Dim msgText As String
            msgText = knt.ToString & " " & New String(" "c, (level * 4)) & prototype.Leaf
            'LW.WriteLine(msgText.ToString)
            theSession.Parts.SetDisplay(prototype, False, False, partLoadStat)
 '           displayPart = theSession.Parts.Display
             '==============
             Dim workPart As Part = theSession.Parts.Work


             Dim physicalMaterial1 As PhysicalMaterial

             Try
                 'load from library in case it is not used in the part yet
                  physicalMaterial1 = workPart.MaterialManager.PhysicalMaterials.LoadFromNxmatmllibrary("Aluminum_6061")
             Catch ex as Exception
                 ' the material is already known in the part so use it
                 physicalMaterial1 = CType(workPart.MaterialManager.PhysicalMaterials.FindObject("PhysicalMaterial[Aluminum_6061]"), PhysicalMaterial)
             End Try

             Dim bodies As BodyCollection = workPart.Bodies
             Dim solidBodies(0) As NXObject
             Dim counter As Integer = 0

             Dim bodyCount As Integer = bodies.ToArray.Length
      
             LW.WriteLine("Total Bodies in Work Part: " & bodyCount.ToString())
      
             If bodyCount > 0 Then

                 For Each thisBody As Body In bodies

                     If thisBody.IsSheetBody.Equals(False) Then
                         ReDim Preserve solidBodies(counter)
                         solidBodies(counter) = thisBody
                         LW.WriteLine("Solid Body: " & thisBody.ToString())
                         counter += 1
                     End If

                 Next

                 Dim solidBodyCount As Integer = solidBodies.Length()

                 LW.WriteLine("Solid Bodies in Work Part: " & _
                                solidBodyCount.ToString())

                 ' At this point, all solid bodies 
                 ' should be in an array called solidBodies
 
                 If (solidBodies.Length > 0) Then
                     physicalMaterial1.AssignObjects(solidBodies)
                 End If
                End If
          Else
              LW.WriteLine("Already processsed")
              'theSession.DisplayManager.MakeUpToDate()
        End if ' not already processed

        '==================
        For Each child In children
           LW.Writeline("next child = " & child.ToString)
            Walk(child, level + 1)
        Next
    End Sub


End Module 

RE: Assign the same material to all component accross the assembly

(OP)
Hi Joe

Thanks a lot, it works very well dazed


Regards
Didier Psaltopoulos
http://www.psi-cad.com

RE: Assign the same material to all component accross the assembly

Hi Joe,

Could you adapt this so that it gives partnames included with the component numbers?

Regards,

Olaf

RE: Assign the same material to all component accross the assembly

Olaf,

At the risk of abbetting thread hijacking... winky smile

Here is a modified version of code that is available to all customers from the GTAC support site
http://gtac.industrysoftware.automation.siemens.com/view.php?sort=desc&p=1&q=.DisplayName+.Net+Sample&i=nx_api3555&k=2&o=0
that reports part name, path and component names to get you started.

HTH, Joe

CODE --> VB

Imports System
Imports NXOpen
Imports NXOpen.Assemblies

Module NXJournal

    Dim s As session = session.GetSession()
    Dim lw As ListingWindow = s.ListingWindow
       Dim c_part As Part = Nothing

    Sub ShowAssemblyTree(ByVal c As Component, ByVal indent As String)
        Dim children As Component() = c.GetChildren()
        Dim newIndent As String
        For Each child As Component In children
            If indent.Length = 0 Then
                newIndent = " "
            Else
                newIndent = indent & " "
            End If

            c_Part = ctype(child.Prototype(),part)

            lw.WriteLine(newIndent & "Display Name: " & child.DisplayName)
            lw.WriteLine(newIndent & "Full Path: " & c_Part.FullPath)
            lw.WriteLine(newIndent & "Component  Name: " &child.Name)
            ShowAssemblyTree(child, newIndent)
        Next

    End Sub

    Sub Main(ByVal args As String())

        lw.Open()

        If args.Length = 0 And s.Parts.Work Is Nothing Then
            lw.WriteLine("Part file argument expected or work part required")
            Return
        End If

        Try
            Dim part1 As Part
            If args.Length = 0 Then
                part1 = s.Parts.Work
            Else
                Dim loadStatus1 As PartLoadStatus
                part1 = s.Parts.OpenDisplay(args(0), loadStatus1)
                loadStatus1.Dispose()
            End If

            Dim c As Component = part1.ComponentAssembly.RootComponent
            lw.WriteLine("*Display name: " & c.DisplayName)

            ShowAssemblyTree(c, " ")

        Catch e As Exception
            lw.WriteLine("Failed: " & e.Message)
        End Try
    End Sub
End Module 

RE: Assign the same material to all component accross the assembly

Thanks!!!!!!!!

RE: Assign the same material to all component accross the assembly

Didier,

Regarding:

Quote (Didier)

After some tests I found that if a material already exist in the part I have to confirm each time (attached jpeg file). could you add a command to delete all assigned material ?

I understand the request for deleting any/all existing materials to avoid the dialog for "Multiple materials are assigned to Bodies, Please select the one to represent the part material".

This happens even when (re) assigning a new material interactively.

The function call to do that would be

CODE --> VB

physicalMaterial1.UnassignAllObjects() 

I can't promise when/if I will be able to find time to supply tested code.

Happy New Year,

Joe

RE: Assign the same material to all component accross the assembly

(OP)
Hi Joe

Thanks a lot and happy new year. I'll test next week because I am on holliday. I will let you informed even for the other post.


Regards
Didier Psaltopoulos
http://www.psi-cad.com

RE: Assign the same material to all component accross the assembly

(OP)
Hi Joe,

Sorry for asking your help one more time but I don't know where to add the following line:

physicalMaterial1.UnassignAllObjects()

TIA


Regards
Didier Psaltopoulos
http://www.psi-cad.com

RE: Assign the same material to all component accross the assembly

Didier,

Please the three lines, at the location shown.

Regards,

Joe

CODE --> VB

           Dim workPart As Part = theSession.Parts.Work

        For Each aMaterial As PhysicalMaterial In workPart.MaterialManager.PhysicalMaterials.ToArray()
            aMaterial.UnassignAllObjects()
        Next

             Dim physicalMaterial1 As PhysicalMaterial

             Try
                 'load from library in case it is not used in the part yet 

RE: Assign the same material to all component accross the assembly

(OP)
Hi Joe

Thansk a lot


Regards
Didier Psaltopoulos
http://www.psi-cad.com

RE: Assign the same material to all component accross the assembly

Hi,
I tried to run this Journal in NX6 but it is giving error as mentioned below. Please help on this.
'LoadFromNxmatmllibrary' is not a member of NXOpen.PhysicalMaterialCollection.

Bambila

Bambila
Mechanical Engineer

RE: Assign the same material to all component accross the assembly

That command is only available in NX7.5 or later.

www.nxjournaling.com

RE: Assign the same material to all component accross the assembly

Is it possible to convert this Journal such that it can be run in NX6? Actually this journal very usefull for us.

Bambila
Mechanical Engineer

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources