×
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

How to create a custom model view using NXOpen?

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")

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?

Try the following code:

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 Module 

www.nxjournaling.com

RE: How to create a custom model view using NXOpen?

(OP)
Cowski,

Thank you very much.The code you have shared worked nicely.I was struggling with this for a long time.

Thanks,
Amitabh

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