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.
Thanks,
Amitabh
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