MrMike87
Mechanical
- Feb 26, 2012
- 2
I have searched on this forum and have found some useful information.
I have found code submitted in the above link, and I modified it to be the code below. I am wanting code that will modify and assign Find Number attribute data at the master assembly drawing level to all of the components in that drawing. From what I have read on this site, the attributes at the master assembly drawing level are called "Object Attributes." It is important to note that the attribute does not need to be the same as it is on the part level (we may have several drawings that refer to a part, but each drawing may use different find numbers to refer to that particular part). That is why I will only be assigning the Find Number attribute at the drawing level. I do not want to pull Part Attributes.
I also read on this site that you should be able to use Excel to do this. In the drawing, you would go to Tools > Spreadsheet > Click the 'Addins' Tab > Choose Extract Attributes > Modify The Attributes You Need > Click Update NX Part. This works except for one problem. If there are multiple instances of a certain component in your assembly (ie. 4 of the same wheels on a car or if you packed your ANT you would see WHEEL x4), updating the attributes only update one of the components in the ANT. We are using Excel 2010, and I know this isn't fully supported yet. This may be the reason that it does not work for multiple instances of the same component. Has anyone else experienced this? Plus, I noticed it looks like it tries to update all of the attributes, which can be several thousand rows, and it can be time consuming.
The code that I modified will give the user an input box to input a find number. It then assigns it to a "CALLOUT" attribute, which is a user added attribute (column) in the ANT. You could call this "FIND NO" or anything really. As long as you added the corresponding column to you ANT, it will show up. This code, however, only modifies the work part attribute. I need something that will go through and prompt the user to assign a FIND NUMBER for each component, not the drawing part file.
Ideally, if there are multiple instances of the same component in your assembly drawing (if you packed your ANT you would see some components with a "x" and the number of times they appeared in the assembly drawing), the user would only have to enter the FIND NUMBER once for that particular part.
A couple of points to note:
1) The main reason behind this is time. I know in the ANT you can right click > properties > attributes > and assign the attribute for each component, but this will be very cumbersome and time consuming for a very large assembly. I did notice that if you pack all and right click a packed component and assign the attribute that it WILL assign that attribute to all of the packed components. This is great because when you use the Parts List, you will see that number instead of a "...".
2) One possible procedure would be to use Excel update method to assign the FIND NUMBER attributes to all individual components. Then, pack all and right click each packed component and assign its find number. I am wanting a smoother process, though.
Here is the code that I modified. Any help on this would be greatly appreciated. I am still learning code. All that really needs to be done is instead of assigning the find number for the drawing file, look at each component and assign the find numbers for them using an input box that appears. I do not currently know enough about the API to do this. It currently calls the work part and not the components. Also, maybe if you could create an array that populates with each part name and find number as you enter it. Then, on the next component, you could compare that part name and see if it exists in the array. If it does, it gets the find number you already assigned to it, and it goes to the next component in the assembly. If not, it gets what you enter in the box. The array is updated, and you go to the next component in the assembly. That is how I was planning on solving only entering the FIND NUMBER once for each component. I do not want to enter a FIND NUMBER for every instance, but I'll take any help at this point.
Here is the modified code, and thanks in advance.
'-----START-----
Option Strict Off
Imports System
Imports NXOpen
Imports System.Windows.Forms
Imports NXOpenUI
Module NXJournal
Sub Main
Dim PrevNo As string
Dim Cur_Desc As String
Dim theSession As Session = Session.GetSession()
Dim Attrer As Integer
' ----------------------------------------------
' Check Attributes exist and get Strings
' ----------------------------------------------
Try
PrevNo = thesession.Parts.Display.GetStringAttribute("Callout")
Catch exc As NXException
'PrevNo = "XXXXX-XX"
Attrer = 1
End Try
'Try
'PrevPartNo = thesession.Parts.Work.GetStringAttribute("DB_PART_NAME")
'Catch exc As NXException
'PrevPartNo = "XXXXX-XX"
'Attrer = 1
'End Try
' ----------------------------------------------
' New CALLOUT prompt
' ----------------------------------------------
Try
Cur_Desc = thesession.Parts.Display.GetStringAttribute("Callout")
Catch exc As NXException
Cur_Desc = ""
Attrer = 1
End Try
dim Desc = NXInputBox.GetInputString("ENTER FIND NUMBER", "Callout",Cur_Desc)
Desc = desc.ToUpper()
' ----------------------------------------------
' Update Attributes
' ----------------------------------------------
Dim session_UndoMarkId1 As Session.UndoMarkId
session_UndoMarkId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Assign Attributes")
'theSession.Parts.Work.SetAttribute("DB_PART_NAME", PartNo)
'theSession.Parts.Work.SetAttribute("DB_DWG_NO", DrgNo)
theSession.Parts.Work.SetAttribute("Callout", Desc)
end_prog:
End Sub
End Module
'----END----
I have found code submitted in the above link, and I modified it to be the code below. I am wanting code that will modify and assign Find Number attribute data at the master assembly drawing level to all of the components in that drawing. From what I have read on this site, the attributes at the master assembly drawing level are called "Object Attributes." It is important to note that the attribute does not need to be the same as it is on the part level (we may have several drawings that refer to a part, but each drawing may use different find numbers to refer to that particular part). That is why I will only be assigning the Find Number attribute at the drawing level. I do not want to pull Part Attributes.
I also read on this site that you should be able to use Excel to do this. In the drawing, you would go to Tools > Spreadsheet > Click the 'Addins' Tab > Choose Extract Attributes > Modify The Attributes You Need > Click Update NX Part. This works except for one problem. If there are multiple instances of a certain component in your assembly (ie. 4 of the same wheels on a car or if you packed your ANT you would see WHEEL x4), updating the attributes only update one of the components in the ANT. We are using Excel 2010, and I know this isn't fully supported yet. This may be the reason that it does not work for multiple instances of the same component. Has anyone else experienced this? Plus, I noticed it looks like it tries to update all of the attributes, which can be several thousand rows, and it can be time consuming.
The code that I modified will give the user an input box to input a find number. It then assigns it to a "CALLOUT" attribute, which is a user added attribute (column) in the ANT. You could call this "FIND NO" or anything really. As long as you added the corresponding column to you ANT, it will show up. This code, however, only modifies the work part attribute. I need something that will go through and prompt the user to assign a FIND NUMBER for each component, not the drawing part file.
Ideally, if there are multiple instances of the same component in your assembly drawing (if you packed your ANT you would see some components with a "x" and the number of times they appeared in the assembly drawing), the user would only have to enter the FIND NUMBER once for that particular part.
A couple of points to note:
1) The main reason behind this is time. I know in the ANT you can right click > properties > attributes > and assign the attribute for each component, but this will be very cumbersome and time consuming for a very large assembly. I did notice that if you pack all and right click a packed component and assign the attribute that it WILL assign that attribute to all of the packed components. This is great because when you use the Parts List, you will see that number instead of a "...".
2) One possible procedure would be to use Excel update method to assign the FIND NUMBER attributes to all individual components. Then, pack all and right click each packed component and assign its find number. I am wanting a smoother process, though.
Here is the code that I modified. Any help on this would be greatly appreciated. I am still learning code. All that really needs to be done is instead of assigning the find number for the drawing file, look at each component and assign the find numbers for them using an input box that appears. I do not currently know enough about the API to do this. It currently calls the work part and not the components. Also, maybe if you could create an array that populates with each part name and find number as you enter it. Then, on the next component, you could compare that part name and see if it exists in the array. If it does, it gets the find number you already assigned to it, and it goes to the next component in the assembly. If not, it gets what you enter in the box. The array is updated, and you go to the next component in the assembly. That is how I was planning on solving only entering the FIND NUMBER once for each component. I do not want to enter a FIND NUMBER for every instance, but I'll take any help at this point.
Here is the modified code, and thanks in advance.
'-----START-----
Option Strict Off
Imports System
Imports NXOpen
Imports System.Windows.Forms
Imports NXOpenUI
Module NXJournal
Sub Main
Dim PrevNo As string
Dim Cur_Desc As String
Dim theSession As Session = Session.GetSession()
Dim Attrer As Integer
' ----------------------------------------------
' Check Attributes exist and get Strings
' ----------------------------------------------
Try
PrevNo = thesession.Parts.Display.GetStringAttribute("Callout")
Catch exc As NXException
'PrevNo = "XXXXX-XX"
Attrer = 1
End Try
'Try
'PrevPartNo = thesession.Parts.Work.GetStringAttribute("DB_PART_NAME")
'Catch exc As NXException
'PrevPartNo = "XXXXX-XX"
'Attrer = 1
'End Try
' ----------------------------------------------
' New CALLOUT prompt
' ----------------------------------------------
Try
Cur_Desc = thesession.Parts.Display.GetStringAttribute("Callout")
Catch exc As NXException
Cur_Desc = ""
Attrer = 1
End Try
dim Desc = NXInputBox.GetInputString("ENTER FIND NUMBER", "Callout",Cur_Desc)
Desc = desc.ToUpper()
' ----------------------------------------------
' Update Attributes
' ----------------------------------------------
Dim session_UndoMarkId1 As Session.UndoMarkId
session_UndoMarkId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Assign Attributes")
'theSession.Parts.Work.SetAttribute("DB_PART_NAME", PartNo)
'theSession.Parts.Work.SetAttribute("DB_DWG_NO", DrgNo)
theSession.Parts.Work.SetAttribute("Callout", Desc)
end_prog:
End Sub
End Module
'----END----