Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations IDS 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 set Attribute into parent program group 1

Status
Not open for further replies.

nxexplorer

Mechanical
Jun 23, 2010
84
Hi,

I need help in NX CAM, is there any sample on how to set Attribute into parent program group(.Net vbscript) without typing/filling the form.
What I want to add the attribute:

attribute name: CNC Operator
Value: Operator-1
Type:String


At the end of the journal running, there is the information verified in listing window:
"Operator-1 has been added as CNC Operator"

Somebody share any help with this case, I very much appreciate.

Regards,
Maryadi

 
Replies continue below

Recommended for you

I have a recorded journal .vb from the customer site, that use NX10. The script as shown below:
Need guidance on how to modify it, so it will be able to be used as a command to create that attribute for other NX CAM sessions.
'=======================================================

Option Strict Off
Imports System
Imports NXOpen

Module NXJournal
Sub Main (ByVal args() As String)

Dim theSession As NXOpen.Session = NXOpen.Session.GetSession()
Dim workPart As NXOpen.Part = theSession.Parts.Work

Dim displayPart As NXOpen.Part = theSession.Parts.Display

Dim markId1 As NXOpen.Session.UndoMarkId
markId1 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "Edit PROGRAM")

Dim markId2 As NXOpen.Session.UndoMarkId
markId2 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Start")

Dim nCGroup1 As NXOpen.CAM.NCGroup = CType(workPart.CAMSetup.CAMGroupCollection.FindObject("PROGRAM"), NXOpen.CAM.NCGroup)

Dim programOrderGroupBuilder1 As NXOpen.CAM.ProgramOrderGroupBuilder
programOrderGroupBuilder1 = workPart.CAMSetup.CAMGroupCollection.CreateProgramOrderGroupBuilder(nCGroup1)

theSession.SetUndoMarkName(markId2, "Program Dialog")

Dim taggedObject1 As NXOpen.TaggedObject
taggedObject1 = programOrderGroupBuilder1.StartUdeSet.UdeList.FindItem(0)

Dim taggedObject2 As NXOpen.TaggedObject
taggedObject2 = programOrderGroupBuilder1.StartUdeSet.UdeList.FindItem(1)

Dim taggedObject3 As NXOpen.TaggedObject
taggedObject3 = programOrderGroupBuilder1.StartUdeSet.UdeList.FindItem(2)

' ----------------------------------------------
' Dialog Begin Program
' ----------------------------------------------
programOrderGroupBuilder1.Destroy()

theSession.UndoToMark(markId2, Nothing)

theSession.DeleteUndoMark(markId2, Nothing)

theSession.DeleteUndoMark(markId2, Nothing)

theSession.UndoToMark(markId1, "Edit PROGRAM")

theSession.DeleteUndoMarksUpToMark(markId1, "Edit PROGRAM", False)

' ----------------------------------------------
' Menu: Tools->Operation Navigator->Object->Properties
' ----------------------------------------------
Dim markId3 As NXOpen.Session.UndoMarkId
markId3 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "Start")

Dim objects1(0) As NXOpen.NXObject
objects1(0) = nCGroup1
Dim attributePropertiesBuilder1 As NXOpen.AttributePropertiesBuilder
attributePropertiesBuilder1 = theSession.AttributeManager.CreateAttributePropertiesBuilder(workPart, objects1, NXOpen.AttributePropertiesBuilder.OperationType.None)

attributePropertiesBuilder1.IsArray = False

attributePropertiesBuilder1.IsArray = False

attributePropertiesBuilder1.IsArray = False

attributePropertiesBuilder1.DataType = NXOpen.AttributePropertiesBaseBuilder.DataTypeOptions.String

attributePropertiesBuilder1.Units = "MilliMeter"

Dim objects2(0) As NXOpen.NXObject
objects2(0) = nCGroup1
Dim generalPropertiesBuilder1 As NXOpen.CAM.GeneralPropertiesBuilder
generalPropertiesBuilder1 = workPart.PropertiesManager.CreateGeneralCAMPropertiesBuilder(objects2)

generalPropertiesBuilder1.Name = "PROGRAM"

Dim objects3(0) As NXOpen.NXObject
objects3(0) = nCGroup1
attributePropertiesBuilder1.SetAttributeObjects(objects3)

attributePropertiesBuilder1.Units = "MilliMeter"

theSession.SetUndoMarkName(markId3, "CAM Task Properties Dialog")

attributePropertiesBuilder1.Title = "CNCOPERATOR"

Dim markId4 As NXOpen.Session.UndoMarkId
markId4 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "CAM Task Properties")

attributePropertiesBuilder1.StringValue = "OPERATOR-1"

theSession.DeleteUndoMark(markId4, Nothing)

Dim markId5 As NXOpen.Session.UndoMarkId
markId5 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "CAM Task Properties")

Dim nXObject1 As NXOpen.NXObject
nXObject1 = attributePropertiesBuilder1.Commit()

Dim nXObject2 As NXOpen.NXObject
nXObject2 = generalPropertiesBuilder1.Commit()

Dim id1 As NXOpen.Session.UndoMarkId
id1 = theSession.GetNewestUndoMark(NXOpen.Session.MarkVisibility.Visible)

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

theSession.DeleteUndoMark(markId5, Nothing)

theSession.SetUndoMarkName(id1, "CAM Task Properties")

attributePropertiesBuilder1.Destroy()

generalPropertiesBuilder1.Destroy()

' ----------------------------------------------
' Menu: Tools->Journal->Stop Recording
' ----------------------------------------------

End Sub
End Module
'========================================================
 
If I understand this code below can help you
Code:
Option Strict Off
Imports System
Imports NXOpen

Module NXJournal
    Sub Main (ByVal args() As String) 

        Dim theSession As NXOpen.Session = NXOpen.Session.GetSession()
        Dim workPart As NXOpen.Part = theSession.Parts.Work
        Dim lw As ListingWindow       = theSession.ListingWindow
        
        lw.Open()
        
        Dim Attributename As String = "CNC Operator"
        Dim Attributeval  As String = "Operator-1"
        
        Try
        
            Dim nCGroup1 As NXOpen.CAM.NCGroup = CType(workPart.CAMSetup.CAMGroupCollection.FindObject("PROGRAM"), NXOpen.CAM.NCGroup)
            nCGroup1.SetUserAttribute(Attributename, -1, Attributeval, Update.Option.Now)
            
            lw.Writeline(Attributeval & " has been added as " & Attributename)
        
        Catch ex As NXOpen.NXException
            lw.Writeline(ex.ToString())
        End Try

    End Sub
End Module
 
Hi UserCFAO,

Thank you for your help. The user has run this journal, and the error message is come out, as shown:

I think this because the Program Group Name is not "PROGRAM".

NXOpen.NXException: No object found with this name at NXOpen.CAM.NCGroupCollection.FindObject(String sid)
at NXJournal.Main(String[] args) in C:\Users\NCProgrammer1\AppData\Local\Temp\NXJournals7756\journal.vb:line 19

Best Regards,
Maryadi.


 
nxexplorer said:
I think this because the Program Group Name is not "PROGRAM".
You are right
Try this
Code:
Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF
Imports NXOpen.Utilities

Module NXJournal
    Sub Main (ByVal args() As String) 

        Dim theSession As NXOpen.Session = NXOpen.Session.GetSession()
        Dim ufs As UFSession             = UFSession.GetUFSession()
        Dim theUI As UI                  = UI.GetUI()
        Dim workPart As NXOpen.Part      = theSession.Parts.Work
        Dim lw As ListingWindow          = theSession.ListingWindow
        
        lw.Open()
        
        Dim Attributename As String  = "CNC Operator"
        Dim Attributeval  As String  = "Operator-1"
        Dim selectedCount As Integer = 0 
	Dim selectedTags As Tag()    = Nothing
        Dim type As Integer
        Dim subtype As Integer
        
        Try
        
            ufs.UiOnt.AskSelectedNodes(selectedCount, selectedTags)
            
            If selectedCount = 0 Then 
                theUI.NXMessageBox.Show("Error : ", _
                                        NXMessageBox.DialogType.Error, _
                                        "No CAM node selected...exit")
                Exit Sub
            End If
                        
            For i As Integer = 0 To selectedCount - 1
            
                ufs.Obj.AskTypeAndSubtype(selectedTags(i), type, subtype)
                
                If type = 121 Then 'Program group
        
                    Dim nCGroup1 As NXOpen.CAM.NCGroup = NXObjectManager.Get(selectedTags(i))
                    nCGroup1.SetUserAttribute(Attributename, -1, Attributeval, Update.Option.Now)
                    
                    lw.Writeline(Attributeval & " has been added as " & Attributename & " in " & nCGroup1.name())
                
                End If
                
            Next
        
        Catch ex As NXOpen.NXException
            lw.Writeline(ex.ToString())
        End Try

    End Sub
End Module
 
Hi UserCFAO,

It is works perfect! That is what I hope. The main purpose from this journal as now, the user want to change UDE procedure with an attribute. Now I will guide them on how to connect it into post builder and OWI.

I very much appreciate yours with this sharing.
UDE_to_Attribute_Change_x2dgv4.png


Regards,
Maryadi
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor