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
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