×
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

VB Help!!! How do I call a attribute of a parent for a child component?

VB Help!!! How do I call a attribute of a parent for a child component?

VB Help!!! How do I call a attribute of a parent for a child component?

(OP)
Ok what I am trying to accomplish is creating a component or instance only attribute named "Order".
with the top level being numbered "1" then going down to the next component want to know if there is a parent if there is I want to read that order value and increment to the next number "2" and so on.
But I can only add this attribute to the component or instance because these assemblies and parts are used in other assemblies in TC. I have added a image and the code below to futher explain where im getting hung up at. Sorry if its cluttered I've been trying different pieces of Code on google.


Option Strict Off

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

Module Module1

Public theSession As Session = Session.GetSession()
Public ufs As UFSession = UFSession.GetUFSession()
Public lw As ListingWindow = theSession.ListingWindow

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

lw.Open()

Dim markId1 As Session.UndoMarkId
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Delete Attributes")
'delete attributes from the display part (the assembly)
DeleteAttributes(dispPart)

Dim fileName As String = workPart.FullPath
Dim result As String
result = Path.GetFileName(fileName)
Console.WriteLine("GetFileName('{0}') returns '{1}'", fileName, result)
Dim result0 As String
Dim result1 As String
result0 = result.Replace("D_", "")
result1 = result0.Replace("_-.prt", "")

' Dim message, title, defaultValue As String
' Dim PartNo As String
' ' Set prompt.
' message = "Please VERIFY the part number below is correct!" & vbCrLf & "Do NOT run this unless the drawing format has been removed from all sheets!"
' ' Set title.
' title = "Attribute Modifier"
' defaultValue = result1 ' Set default value.

' Display message, title, and default value.
' PartNo = InputBox(message, title, defaultValue)

Dim markId2 As Session.UndoMarkId
markId2 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Edit Properties")

' AddAttributes(PartNo)

Dim nErrs1 As Integer
nErrs1 = theSession.UpdateManager.DoUpdate(markId2)

Dim c As ComponentAssembly = dispPart.ComponentAssembly
'to process the work part rather than the display part,
' comment the previous line and uncomment the following line
'Dim c As ComponentAssembly = workPart.ComponentAssembly
If Not IsNothing(c.RootComponent) Then
'*** insert code to process 'root component' (assembly file)

lw.WriteLine("Assembly: " & c.RootComponent.DisplayName)
lw.WriteLine(" + Active Arrangement: " & c.ActiveArrangement.Name)
'*** end of code to process root component
reportComponentChildren(c.RootComponent, 0)
End If

theSession.Parts.SetWork(workPart)

lw.Close()

End Sub

'**********************************************************
Sub reportComponentChildren(ByVal comp As Component, _
ByVal indent As Integer)
Dim dispPart As Part = theSession.Parts.DisplaY
For Each child As Component In comp.GetChildren()
'*** insert code to process component or subassembly
' MakeWorkPart(child)
' DeleteAttributes(theSession.Parts.Work)
Dim objects(0) As NXObject
objects(0) = child
Dim attributePropertiesBuilder1 As AttributePropertiesBuilder
Dim assembliesParameterPropertiesBuilder1 As Assemblies.AssembliesParameterPropertiesBuilder
attributePropertiesBuilder1 = disppart.PropertiesManager.CreateAttributePropertiesBuilder(objects)
attributePropertiesBuilder1.ObjectPicker = AttributePropertiesBaseBuilder.ObjectOptions.ComponentAsPartAttribute
attributePropertiesBuilder1.DataType = AttributePropertiesBaseBuilder.DataTypeOptions.String
attributePropertiesBuilder1.Title = "Order"
attributePropertiesBuilder1.IsArray = False
attributePropertiesBuilder1.StringValue = 1

Dim nXObject2 As NXObject
nXObject2 = attributePropertiesBuilder1.Commit()
attributePropertiesBuilder1.Destroy()
lw.WriteLine(New String(" ", indent * 2) & child.DisplayName())
'*** end of code to process component or subassembly


If child.GetChildren.Length > 2 Then
'*** this is a subassembly, add code specific to subassemblies

objects(0) = child


attributePropertiesBuilder1 = disppart.PropertiesManager.CreateAttributePropertiesBuilder(objects)
attributePropertiesBuilder1.ObjectPicker = AttributePropertiesBaseBuilder.ObjectOptions.ComponentAsPartAttribute
attributePropertiesBuilder1.DataType = AttributePropertiesBaseBuilder.DataTypeOptions.String
attributePropertiesBuilder1.Title = "Order"
attributePropertiesBuilder1.IsArray = False
attributePropertiesBuilder1.StringValue = 2



nXObject2 = attributePropertiesBuilder1.Commit()
attributePropertiesBuilder1.Destroy()

lw.WriteLine(New String(" ", indent * 2) & _
"* subassembly with " & _
child.GetChildren.Length & " components")
lw.WriteLine(New String(" ", indent * 2) & _
" + Active Arrangement: " & _
child.OwningPart.ComponentAssembly.ActiveArrangement.Name)
'*** end of code to process subassembly
Else
'this component has no children (it is a leaf node)
'add any code specific to bottom level components

End If




reportComponentChildren(child, indent + 1)
Next
End Sub

Sub DeleteAttributes(ByVal thePart As part)

' thePart.DeleteAttributeByTypeAndTitle(NXObject.AttributeType.String, "DB_EXPORT_CLASSIFICATION")
' thePart.DeleteAttributeByTypeAndTitle(NXObject.AttributeType.String, "DB_EXPORT_JURISDICTION")
' thePart.DeleteAttributeByTypeAndTitle(NXObject.AttributeType.String, "DB_ICLASS_CATEGORY")
' thePart.DeleteAttributeByTypeAndTitle(NXObject.AttributeType.String, "DB_ICLASS_TYPE")
' thePart.DeleteAttributeByTypeAndTitle(NXObject.AttributeType.String, "DB_INITIAL_MODEL")
' thePart.DeleteAttributeByTypeAndTitle(NXObject.AttributeType.String, "DB_IP_SENSITIVE")
' thePart.DeleteAttributeByTypeAndTitle(NXObject.AttributeType.String, "DB_OWNED")
' thePart.DeleteAttributeByTypeAndTitle(NXObject.AttributeType.String, "DB_REASONS_FOR_CONTROL")
' thePart.DeleteAttributeByTypeAndTitle(NXObject.AttributeType.String, "DB_SEED_PART_USED")
' thePart.DeleteAttributeByTypeAndTitle(NXObject.AttributeType.String, "DB_UNITS")
' thePart.DeleteAttributeByTypeAndTitle(NXObject.AttributeType.String, "XX_CAGECODE")
' thePart.DeleteAttributeByTypeAndTitle(NXObject.AttributeType.String, "XX_ICLASS_CONNECTED_SITE")
' thePart.DeleteAttributeByTypeAndTitle(NXObject.AttributeType.String, "XX_MODEL")
' thePart.DeleteAttributeByTypeAndTitle(NXObject.AttributeType.String, "XX_PARTNUMBER")
' thePart.DeleteAttributeByTypeAndTitle(NXObject.AttributeType.String, "ITEMREV_DESC")
' thePart.DeleteAttributeByTypeAndTitle(NXObject.AttributeType.String, "ITEMREV_DESC1")
' thePart.DeleteAttributeByTypeAndTitle(NXObject.AttributeType.String, "ITEMREV_NAME")
' thePart.DeleteAttributeByTypeAndTitle(NXObject.AttributeType.String, "MATERIAL")
' thePart.DeleteAttributeByTypeAndTitle(NXObject.AttributeType.String, "MOD_DATE")
' thePart.DeleteAttributeByTypeAndTitle(NXObject.AttributeType.String, "NX_NON_MASTER")
' thePart.DeleteAttributeByTypeAndTitle(NXObject.AttributeType.String, "REM-SPEC")
' thePart.DeleteAttributeByTypeAndTitle(NXObject.AttributeType.String, "SIMILAR_TO")
' thePart.DeleteAttributeByTypeAndTitle(NXObject.AttributeType.String, "STATUS")
' thePart.DeleteAttributeByTypeAndTitle(NXObject.AttributeType.String, "DB_DATASET_ID")
' thePart.DeleteAttributeByTypeAndTitle(NXObject.AttributeType.String, "DB_DATASET_REV")
' thePart.DeleteAttributeByTypeAndTitle(NXObject.AttributeType.String, "DB_SYNCHRONISATION_DATE")
' thePart.DeleteAttributeByTypeAndTitle(NXObject.AttributeType.String, "UGII_VERSION")
' thePart.DeleteAttributeByTypeAndTitle(NXObject.AttributeType.String, "XX_PART_NO")
' thePart.DeleteAttributeByTypeAndTitle(NXObject.AttributeType.String, "XX PART NO")
' thePart.DeleteAttributeByTypeAndTitle(NXObject.AttributeType.String, "CALLOUT")
' thePart.DeleteAttributeByTypeAndTitle(NXObject.AttributeType.String, "DB_SYNCHRONIZED_PARTS_LIST")


End Sub

Sub AddAttributes(ByVal thePartNumber As String)

theSession.Parts.Display.SetAttribute("DB_CAGECODE", "XXXXX")
' theSession.Parts.Display.SetAttribute("DB_PART_NAME", thePartNumber)
' theSession.Parts.Display.SetAttribute("DB_PART_NO", thePartNumber)
' theSession.Parts.Display.SetAttribute("DB_PART_REV", "-")
' theSession.Parts.Display.SetAttribute("DB_PART_TYPE", "ITEM")

End Sub

Sub MakeWorkPart(ByVal theComp As Component)

Dim partLoadStatus1 As PartLoadStatus
theSession.Parts.SetWorkComponent(theComp, PartCollection.RefsetOption.Current, PartCollection.WorkComponentOption.Visible, partLoadStatus1)
partLoadStatus1.Dispose()

End Sub

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

End Module

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