Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

Make Model view as the work view using NXOpen?

Status
Not open for further replies.

biw01

Automotive
Dec 31, 2011
152
Hello friends,

I am working on creating a sample code to make every view in the model as the work view. The sample procedure below is working in most cases but in some cases I am getting the following error "view to be replaced is not in layout". Can someone help me out and let me know where am I going wrong. Any help in this regard will be deeply appreciated.

Code:
'Every model view in NX is in a layout
    'Find the layout in which the current work view is in and then replace it with a new view so that the model view is displayed
    Sub sReplaceViewInLayout(ByVal objPart As Part, ByVal objModelViewToReplace As ModelingView)
        Dim viewType As Integer = 0
        '1 = modeling view
        '2 = drawing view
        'other = error
        FnGetUFSession.Draw.AskDisplayState(viewType)

        'if drawing sheet shown, change to modeling view
        If viewType = 2 Then
            FnGetUFSession.Draw.SetDisplayState(1)
        End If

        Dim sCurrentWorkView As ModelingView = Nothing
        sCurrentWorkView = objPart.ModelingViews.WorkView
        For Each objLayout As Layout In objPart.Layouts
            For Each objView As ModelingView In objLayout.GetViews()
                If objView.Name = sCurrentWorkView.Name Then
                    'Display the layout by changing the current layout
                    'View needs to be dispayed for it to be changed as a work view
                    objPart.Layouts.ChangeLayout(objLayout)
                    objLayout.ReplaceView(sCurrentWorkView, objModelViewToReplace, False)
                    'Make this view as the work view
                    objModelViewToReplace.MakeWork()
                    objModelViewToReplace.Restore()
                    Exit Sub
                End If
            Next
        Next
    End Sub

Thanks,
Amitabh
 
Replies continue below

Recommended for you

Cowski / Jerry,

Sorry for the delay in response. I was out of town on some other work.
I am working on NX parts where the user has created some custom model views by rotating the 3D model. In my NXOpen program I need to delete these existing model views before creating new ones. As NX does not let us delete the work view, so the process I am following is to check if the view to be deleted is the work view, if yes then I make any other existing model view as the work view and delete this view. In order to make any existing view as the work view, the view must be first displayed else NX will throw an error that the "view is not displayed" while executing the MakeWork() API. So in order to display this view, I am changing the view layout to the layout in which that view is present.

Hope this clarifies my intent so that you can provide me with a solution to my problem.

Thanks,
Amitabh
 
Code:
For Each objView As ModelingView In objLayout.GetViews()
    If objView.Name = sCurrentWorkView.Name Then

Your code assumes that the current work view is used in the layout that you are processing. This may not be the case.

The objView that you are processing in the loop may be the same as the work view; but the work view may not be used in the layout that you are processing. You can't replace a view in the layout if it doesn't exist in the layout. You need to check that the view exists in the layout before trying to replace it.

www.nxjournaling.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor