Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

Need Help, nx journal to get information if Assembly and Its Children has Drawing or not. 1

Status
Not open for further replies.

nxexplorer

Mechanical
Jun 23, 2010
84
Hi Experts,
I need help how to get information if Assembly and Its Child has Drawing or not.
Below is my existing code that only read the top assembly only, It is in NX9.
Any contributions, helps or suggests is very much appreciate.
'*********************************************************************
Option Strict Off

Imports System
Imports NXOpen
Imports NXOpen.UF
Imports NXOpen.Assemblies

Module NXJournal

Public theSession As Session = Session.GetSession()
Public ufs As UFSession = UFSession.GetUFSession()
Public lw As ListingWindow = theSession.ListingWindow
Dim workPart As Part = theSession.Parts.Work

Sub Main()
Dim workPart As Part = theSession.Parts.Work
Dim dispPart As Part = theSession.Parts.Display

lw.Open()
Dim ShortFilename As String = IO.Path.GetFileNameWithoutExtension(workPart.FullPath)
dispPart.SetUserAttribute("PART NAME", -1, ShortFilename , Update.Option.Now)

Try
Dim c As ComponentAssembly = dispPart.ComponentAssembly
if not IsNothing(c.RootComponent) then
ReportComponentChildren(c.RootComponent, 0)
else
lw.WriteLine("Part has no components")
end if
Catch e As Exception
theSession.ListingWindow.WriteLine("Failed: " & e.ToString)
End Try
lw.Close

End Sub

'**********************************************************
Sub reportComponentChildren( ByVal comp As Component, _
ByVal indent As Integer)
Dim dispPart As Part = theSession.Parts.Display
Dim Length as Integer
For Each child As Component In comp.GetChildren()
Dim objects(0) As NXObject
Dim workPart As Part = theSession.Parts.Work
Dim disPart As Part = theSession.Parts.Display
Dim c As ComponentAssembly = disPart.ComponentAssembly
Dim currentFileName As String = theSession.Parts.Work.leaf
objects(0) = child
lw.Open()

Dim attributePropertiesBuilder1 As AttributePropertiesBuilder
Dim attributePropertiesBuilder2 As AttributePropertiesBuilder
Dim assembliesParameterPropertiesBuilder1 As Assemblies.AssembliesParameterPropertiesBuilder
Dim assembliesParameterPropertiesBuilder2 As Assemblies.AssembliesParameterPropertiesBuilder

attributePropertiesBuilder1 = disppart.PropertiesManager.CreateAttributePropertiesBuilder(objects)
attributePropertiesBuilder1.ObjectPicker = AttributePropertiesBaseBuilder.ObjectOptions.ComponentAsPartAttribute
attributePropertiesBuilder1.DataType = AttributePropertiesBaseBuilder.DataTypeOptions.String
attributePropertiesBuilder1.Title = "PART NAME"
attributePropertiesBuilder1.IsArray = False
attributePropertiesBuilder1.StringValue = child.DisplayName

lw.WriteLine("====================================================")
lw.WriteLine(" " &child.DisplayName +".prt" )

Dim i As Integer = 0
lw.Open()

For Each sheet As Drawings.DrawingSheet In theSession.Parts.Display.DrawingSheets
i = i + 1
If i = 1 Then
lw.WriteLine(" has drawing(s) ")
attributePropertiesBuilder2 = disppart.PropertiesManager.CreateAttributePropertiesBuilder(objects)
attributePropertiesBuilder2.ObjectPicker = AttributePropertiesBaseBuilder.ObjectOptions.ComponentAsPartAttribute
attributePropertiesBuilder2.DataType = AttributePropertiesBaseBuilder.DataTypeOptions.String
attributePropertiesBuilder2.Title = "CAD FILE"
attributePropertiesBuilder2.IsArray = False
attributePropertiesBuilder2.StringValue = "3D/2D-DRAWING"

End If


If i = 0 Then
lw.WriteLine("====================================================")
lw.WriteLine(" doesn't have drawing")
lw.Close()


attributePropertiesBuilder2 = disppart.PropertiesManager.CreateAttributePropertiesBuilder(objects)
attributePropertiesBuilder2.ObjectPicker = AttributePropertiesBaseBuilder.ObjectOptions.ComponentAsPartAttribute
attributePropertiesBuilder2.DataType = AttributePropertiesBaseBuilder.DataTypeOptions.String
attributePropertiesBuilder2.Title = "CAD FILE"
attributePropertiesBuilder2.IsArray = False
attributePropertiesBuilder2.StringValue = "3D"
End If

Next

Dim nXObject2 As NXObject
Dim nXObject3 As NXObject
nXObject2 = attributePropertiesBuilder1.Commit()
nXObject3 = attributePropertiesBuilder2.Commit()
attributePropertiesBuilder1.Destroy()
attributePropertiesBuilder2.Destroy()

reportComponentChildren(child, indent + 1)
Next
End Sub
'**********************************************************
Public Function GetUnloadOption(ByVal dummy As String) As Integer
Return Session.LibraryUnloadOption.Immediately
End Function
'**********************************************************

End Module


Best Regards,
Maryadi
 
Replies continue below

Recommended for you

Try the following journal. For best results, the components should be fully loaded.
Code:
Option Strict Off

Imports System
Imports NXOpen
Imports NXOpen.UF
Imports NXOpen.Assemblies

Module Module184

    Public theSession As Session = Session.GetSession()
    Public ufs As UFSession = ufsession.GetUFSession()
    Public lw As ListingWindow = theSession.ListingWindow
    Dim workPart As Part = theSession.Parts.Work

    Sub Main()
        Dim workPart As Part = theSession.Parts.Work
        Dim dispPart As Part = theSession.Parts.Display

        lw.Open()
        Dim ShortFilename As String = IO.Path.GetFileNameWithoutExtension(workPart.FullPath)
        dispPart.SetUserAttribute("PART NAME", -1, ShortFilename, Update.Option.Now)

        Try
            Dim c As ComponentAssembly = dispPart.ComponentAssembly
            If Not IsNothing(c.RootComponent) Then
                reportComponentChildren(c.RootComponent, 0)
            Else
                lw.WriteLine("Part has no components")
            End If
        Catch e As Exception
            theSession.ListingWindow.WriteLine("Failed: " & e.ToString)
        End Try
        lw.Close

    End Sub

    '**********************************************************
    Sub reportComponentChildren(ByVal comp As Component, ByVal indent As Integer)

        Dim attributePropertiesBuilder1 As AttributePropertiesBuilder
        attributePropertiesBuilder1 = comp.Prototype.OwningPart.PropertiesManager.CreateAttributePropertiesBuilder({comp})
        attributePropertiesBuilder1.ObjectPicker = AttributePropertiesBaseBuilder.ObjectOptions.ComponentAsPartAttribute
        attributePropertiesBuilder1.DataType = AttributePropertiesBaseBuilder.DataTypeOptions.String
        attributePropertiesBuilder1.Title = "PART NAME"
        attributePropertiesBuilder1.IsArray = False
        attributePropertiesBuilder1.StringValue = comp.DisplayName
        Dim nXObject2 As NXObject
        nXObject2 = attributePropertiesBuilder1.Commit()
        attributePropertiesBuilder1.Destroy()

        lw.WriteLine("====================================================")
        lw.WriteLine(" " & comp.DisplayName + ".prt")

        Dim currentPart As Part = comp.Prototype.OwningPart

        Dim attributePropertiesBuilder2 As AttributePropertiesBuilder
        attributePropertiesBuilder2 = currentPart.PropertiesManager.CreateAttributePropertiesBuilder({comp})
        attributePropertiesBuilder2.ObjectPicker = AttributePropertiesBaseBuilder.ObjectOptions.ComponentAsPartAttribute
        attributePropertiesBuilder2.DataType = AttributePropertiesBaseBuilder.DataTypeOptions.String
        attributePropertiesBuilder2.Title = "CAD FILE"
        attributePropertiesBuilder2.IsArray = False

        If currentPart.DrawingSheets.ToArray.Length > 0 Then
            lw.WriteLine(" has drawing(s) ")
            attributePropertiesBuilder2.StringValue = "3D/2D-DRAWING"

        Else

            lw.WriteLine("====================================================")
            lw.WriteLine(" doesn't have drawing")

            attributePropertiesBuilder2.StringValue = "3D"

        End If

        Dim nXObject3 As NXObject
        nXObject3 = attributePropertiesBuilder2.Commit()
        attributePropertiesBuilder2.Destroy()

        For Each child As Component In comp.GetChildren()
            reportComponentChildren(child, indent + 1)
        Next

    End Sub
    '**********************************************************
    Public Function GetUnloadOption(ByVal dummy As String) As Integer
        Return Session.LibraryUnloadOption.Immediately
    End Function
    '**********************************************************

End Module

www.nxjournaling.com
 
Wow,Perfect! Now it is running like what I need.
Cowski,Thank you for your help.

Best Regards,
Maryadi
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor