How to create a custom model view using NXOpen?
How to create a custom model view using NXOpen?
(OP)
Hello Everyone,
I am facing some difficulties in creating a custom model view using NXOpen. I am able to create the view when the application is in Modeling Mode , but if i try to do the same thing if the part is opened in Drafting mode , it throws an error saying the workview is not a model view.
I am using the following code to Switch the application from drafting to modelling mode.
UI.GetUI.MenuBarManager.ApplicationSwitchRequest("UG_APP_MODELING")
Please help!!!
Thanks,
Amitabh
I am facing some difficulties in creating a custom model view using NXOpen. I am able to create the view when the application is in Modeling Mode , but if i try to do the same thing if the part is opened in Drafting mode , it throws an error saying the workview is not a model view.
I am using the following code to Switch the application from drafting to modelling mode.
UI.GetUI.MenuBarManager.ApplicationSwitchRequest("UG_APP_MODELING")
CODE --> vb
Public Sub sCreateCustomModellingView(ByVal objPart As Part, ByVal X As Double, ByVal Y As Double, ByVal Z As Double, ByVal Xx As Double, ByVal Xy As Double, ByVal Xz As Double, _
ByVal Yx As Double, ByVal Yy As Double, ByVal Yz As Double, ByVal Zx As Double, _
ByVal Zy As Double, ByVal Zz As Double, ByVal sCustViewName As String, ByVal dScale As Double, _
Optional ByVal sDefaultRefView As String = "FRONT")
Dim objView As View = Nothing
Dim rotMatrix As Matrix3x3 = Nothing
rotMatrix.Xx = Xx
rotMatrix.Xy = Xy
rotMatrix.Xz = Xz
rotMatrix.Yx = Yx
rotMatrix.Yy = Yy
rotMatrix.Yz = Yz
rotMatrix.Zx = Zx
rotMatrix.Zy = Zy
rotMatrix.Zz = Zz
Dim translation As Point3d = New Point3d(X, Y, Z)
If Not objPart.ModelingViews.WorkView Is Nothing Then
objPart.ModelingViews.WorkView.SetRotationTranslationScale(rotMatrix, translation, dScale)
objView = objPart.Views.SaveAs(objPart.ModelingViews.WorkView, sCustViewName, False, False)
Else
For Each objMdVw As ModelingView In objPart.ModelingViews
If objMdVw.Name.ToUpper = sDefaultRefView Then
objMdVw.MakeWork()
objMdVw.SetRotationTranslationScale(rotMatrix, translation, dScale)
objPart.Views.SaveAs(objMdVw, sCustViewName, False, False)
Exit For
End If
Next
End If
End Sub Please help!!!
Thanks,
Amitabh





RE: How to create a custom model view using NXOpen?
CODE
Option Strict Off Imports System Imports NXOpen Imports NXOpen.UF Module Module1 Dim theSession As Session = Session.GetSession() Dim theUFSession As UFSession = UFSession.GetUFSession Sub Main() Dim workPart As Part = theSession.Parts.Work sCreateCustomModellingView(workPart, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, "myview", 1) End Sub Public Sub sCreateCustomModellingView(ByVal objPart As Part, ByVal X As Double, ByVal Y As Double, ByVal Z As Double, ByVal Xx As Double, ByVal Xy As Double, ByVal Xz As Double, _ ByVal Yx As Double, ByVal Yy As Double, ByVal Yz As Double, ByVal Zx As Double, _ ByVal Zy As Double, ByVal Zz As Double, ByVal sCustViewName As String, ByVal dScale As Double, _ Optional ByVal sDefaultRefView As String = "FRONT") Dim viewType As Integer = 0 '1 = modeling view '2 = drawing view 'other = error theUFSession.Draw.AskDisplayState(viewType) 'if drawing sheet shown, change to modeling view If viewType = 2 Then theUFSession.Draw.SetDisplayState(1) End If Dim objView As View = Nothing Dim rotMatrix As Matrix3x3 = Nothing rotMatrix.Xx = Xx rotMatrix.Xy = Xy rotMatrix.Xz = Xz rotMatrix.Yx = Yx rotMatrix.Yy = Yy rotMatrix.Yz = Yz rotMatrix.Zx = Zx rotMatrix.Zy = Zy rotMatrix.Zz = Zz Dim translation As Point3d = New Point3d(X, Y, Z) If Not objPart.ModelingViews.WorkView Is Nothing Then objPart.ModelingViews.WorkView.SetRotationTranslationScale(rotMatrix, translation, dScale) objView = objPart.Views.SaveAs(objPart.ModelingViews.WorkView, sCustViewName, False, False) Else For Each objMdVw As ModelingView In objPart.ModelingViews If objMdVw.Name.ToUpper = sDefaultRefView Then objMdVw.MakeWork() objMdVw.SetRotationTranslationScale(rotMatrix, translation, dScale) objPart.Views.SaveAs(objMdVw, sCustViewName, False, False) Exit For End If Next End If 'reset initial view state theUFSession.Draw.SetDisplayState(viewType) End Sub Public Function GetUnloadOption(ByVal dummy As String) As Integer 'Unloads the image when the NX session terminates GetUnloadOption = NXOpen.Session.LibraryUnloadOption.AtTermination End Function End Modulewww.nxjournaling.com
RE: How to create a custom model view using NXOpen?
Thank you very much.The code you have shared worked nicely.I was struggling with this for a long time.
Thanks,
Amitabh