Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

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

i try to run the code from GTAC, but gives me error message

Status
Not open for further replies.

godpaul

Automotive
Joined
May 4, 2014
Messages
119
Location
US
i am studying the code from GTAC.
the code is to update all parts and all drawing. but when i run, it gives error:
Nxopen.Nxexception. part or occurence is not a descendant of the root part
at NXopen.parCollection.Setwork(Basepart.part)

what does this error mean?

what i did is create 4 models, save them ,and then open up each of them and finally run the code to see what happen,

but now it's error..


Code:
Option Strict Off

Imports System
Imports NXOpen
Imports NXOpen.UF
Imports NXOpen.UI
Imports NXOpen.Utilities
Imports NXOpen.Drawings

Module update_all_parts_then_update_all_drawings

    Dim s As Session = Session.GetSession()
    Dim ufSess As UFSession = UFSession.GetUFSession()

    Sub Main()



        ufSess.Modl.SetUpdateFailOption(UFModl.UpdateOption.UpdateAcceptAll)

        Dim o_wp As Part = s.Parts.Work()

        Dim layout1 As Layout = CType(o_wp.Layouts.FindObject("L1"), Layout)
        'layout1.Open()

        For Each prt As Part In s.Parts
[indent][/indent][COLOR=#CC0000]this line gives trouble.[/color]
            [COLOR=#CC0000]s.Parts.SetWork(prt)[/color]
            ufSess.Modl.UpdateAllFeatures()
        Next

        s.Parts.SetWork(o_wp)

        Dim mark1 As Session.UndoMarkId
        mark1 = s.SetUndoMark(Session.MarkVisibility.Invisible, "")
        s.UpdateManager.DoInterpartUpdate(mark1)

        For Each dwg As DrawingSheet In o_wp.DrawingSheets
            ' Sometimes updating a specific view will cause a previously updated
            ' view to become out-of-date again, so this is While not If
            While dwg.IsOutOfDate
                For Each dv As DraftingView In dwg.GetDraftingViews()
                    If dv.IsOutOfDate Then
                        dv.Update()
                    End If
                Next
            End While
        Next

    End Sub

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

End Module
 
.net API reference said:
The work component will be set to one of the visible components that represent this part in the current visible assembly. See SetWorkComponent . If no visible component is available, then an exception is thrown.

It seems this code was meant to operate only on an assembly and its components. Create a test assembly, make it the display part (close any parts that do not belong to the assembly as components) and try running the code. It should make each of the components the work part in turn and perform an update on each.

www.nxjournaling.com
 
yes, it runs!!!!

one more questions,

if i want to update severl models, no assemlby file involved, do i only have to revise the code to :

For Each prt As Part In s.Parts
ChangeDisplayPart(prt) <---------- does this do the trick?
ufSess.Modl.UpdateAllFeatures()
Next
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top