×
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

Make Model view as the work view using NXOpen?

Make Model view as the work view using NXOpen?

Make Model view as the work view using NXOpen?

(OP)
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 --> VB.NET

'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

RE: Make Model view as the work view using NXOpen?

Quote (biw01)

make every view in the model as the work view

I don't understand what you are trying to accomplish. Care to explain?

www.nxjournaling.com

RE: Make Model view as the work view using NXOpen?

So are you working in a layout with multiple views?

RE: Make Model view as the work view using NXOpen?

(OP)
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

RE: Make Model view as the work view using NXOpen?

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

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