×
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

Journal to select drafting view

Journal to select drafting view

Journal to select drafting view

(OP)
Hello,

I wanna create journal to select drafting view and then toggle between hidden lines invisible or dashed.
I create some code, but I need help.

CODE

Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF
Imports NXOpen.UI

Module Module1

        Dim theSession As Session = Session.GetSession()
	Dim ui As UI = UI.GetUI()
	Dim ufs As UFSession = UFSession.GetUFSession()

    Sub Main()

        If IsNothing(theSession.Parts.BaseWork) Then
            'active part required
            Return
        End If

        Dim workPart As Part = theSession.Parts.Work
        Dim lw As ListingWindow = theSession.ListingWindow
        lw.Open()

        Dim theDrftView As Drawings.DraftingView
	Dim response1 as Selection.Response = Selection.Response.Cancel

start1:
        response1 = SelectDraftingView(theDrftView)

        EditView(theDrftView)
end1:
    End Sub



    Sub EditView(ByVal thedrafview as drawings.DraftingView)

	Dim markId3 As Session.UndoMarkId
	Dim dimname1 As String = Nothing

        For Each selectedView As View In theDrftView 
            dimname1 = selectedView.ToString()


		If dimname1.Contains("projected") = True Then
		   Dim projectedView1 As Drawings.ProjectedView = selectedView
		   projectedView1.Style.HiddenLines.HiddenlineFont = Preferences.Font.Invisible
		   workPart.DraftingViews.SuppressViewBreaks(projectedView1)
                   projectedView1.Commit()
		   workPart.DraftingViews.RestoreViewBreaks(projectedView1)
		end if 	

	Next
        Dim nErrs1 As Integer
        nErrs1 = theSession.UpdateManager.DoUpdate(markId3)


    End Sub

    Function SelectDraftingView(ByVal prompt As String, ByRef selView As Drawings.DraftingView) As 

Selection.Response

        Dim theUI As UI = UI.GetUI
        Dim title As String = "Select a drafting view"
        Dim includeFeatures As Boolean = False
        Dim keepHighlighted As Boolean = False
        Dim selAction As Selection.SelectionAction = Selection.SelectionAction.ClearAndEnableSpecific
        Dim cursor As Point3d
        Dim scope As Selection.SelectionScope = Selection.SelectionScope.WorkPart
        Dim selectionMask_array(0) As Selection.MaskTriple
        Dim selObj As TaggedObject

        With selectionMask_array(0)
            .Type = UFConstants.UF_view_type
            .Subtype = UFConstants.UF_all_subtype
        End With

        Dim resp As Selection.Response = theUI.SelectionManager.SelectTaggedObject(prompt, _
         title, scope, selAction, _
         includeFeatures, keepHighlighted, selectionMask_array, _
         selObj, cursor)
        If resp = Selection.Response.ObjectSelected OrElse resp = Selection.Response.ObjectSelectedByName Then
            selView = CType(selObj, Drawings.DraftingView)
            Return Selection.Response.Ok
        Else
            Return Selection.Response.Cancel
        End If

    End Function

    Public Function GetUnloadOption(ByVal dummy As String) As Integer

        'Unloads the image immediately after execution within NX
        GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Immediately

    End Function

End Module 
I receive an errors: (I translate it to english, so there maybe some misunderstanding)
  • line 28 - There is no arguments for selview
  • line 28 - You cannot convert from type nxopen.drawings.draftingview to string
  • line 41 - draftview is not declared

With best regards
Michael

RE: Journal to select drafting view

Your SelectDraftingView function requires two arguments to be passed in, you have only provided one argument. Fixing that should take care of the first two errors that you are getting.

For the second error, my guess is that you have misspelled the variable name in either line 41 or line 36; perhaps they should match?

www.nxjournaling.com

RE: Journal to select drafting view

(OP)
Thanks for help. I mixed Your code from Link and with some code I have to select dimensions and then apply tolerances to them. After fixing it I received another error:

line 41 - expresion is type of "NXOpen.Drawing.DraftingView" which is no the type of collection (sorry for translation :) )

With best regards
Michael

RE: Journal to select drafting view

(OP)
Ok, I made some changes, now I don't have any error until I select a view.

CODE

Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF
Imports NXOpen.UI

Module Module1

        Dim theSession As Session = Session.GetSession()
	Dim ui As UI = UI.GetUI()
	Dim ufs As UFSession = UFSession.GetUFSession()
	Dim workPart As Part = theSession.Parts.Work
        Dim lw As ListingWindow = theSession.ListingWindow

    Sub Main()

        If IsNothing(theSession.Parts.BaseWork) Then
            'active part required
            Return
        End If

        lw.Open()

        Dim theDrftView As Drawings.DraftingView
	Dim DRWVIEWS as Drawings.DraftingViewCollection
	Dim response1 as Selection.Response = Selection.Response.Cancel

start1:
        response1 = SelectDraftingView("select drafting view", theDrftView)

        EditView(theDrftView)
end1:
    End Sub



    Sub EditView(ByVal theDrftView as drawings.DraftingView)

	Dim markId3 As Session.UndoMarkId
	Dim dimname1 As String = Nothing
	Dim DRWVIEWS as Drawings.DraftingViewCollection

        For Each selectedView As View In DRWVIEWS

            dimname1 = selectedView.ToString()


		If dimname1.Contains("projected") = True Then
		   Dim projectedView1 As Drawings.ProjectedView = selectedView
		   projectedView1.Style.HiddenLines.HiddenlineFont = Preferences.Font.Invisible
		   workPart.DraftingViews.SuppressViewBreaks(projectedView1)
                   projectedView1.Commit()
		   workPart.DraftingViews.RestoreViewBreaks(projectedView1)
		end if 	

	Next
        Dim nErrs1 As Integer
        nErrs1 = theSession.UpdateManager.DoUpdate(markId3)


    End Sub

    Function SelectDraftingView(ByVal prompt As String, ByRef selView As Drawings.DraftingView) As Selection.Response

        Dim theUI As UI = UI.GetUI
        Dim title As String = "Select a drafting view"
        Dim includeFeatures As Boolean = False
        Dim keepHighlighted As Boolean = False
        Dim selAction As Selection.SelectionAction = Selection.SelectionAction.ClearAndEnableSpecific
        Dim cursor As Point3d
        Dim scope As Selection.SelectionScope = Selection.SelectionScope.WorkPart
        Dim selectionMask_array(0) As Selection.MaskTriple
        Dim selObj As TaggedObject

        With selectionMask_array(0)
            .Type = UFConstants.UF_view_type
            .Subtype = UFConstants.UF_all_subtype
        End With

        Dim resp As Selection.Response = theUI.SelectionManager.SelectTaggedObject(prompt, _
         title, scope, selAction, _
         includeFeatures, keepHighlighted, selectionMask_array, _
         selObj, cursor)
        If resp = Selection.Response.ObjectSelected OrElse resp = Selection.Response.ObjectSelectedByName Then
            selView = CType(selObj, Drawings.DraftingView)
            Return Selection.Response.Ok
        Else
            Return Selection.Response.Cancel
        End If

    End Function

    Public Function GetUnloadOption(ByVal dummy As String) As Integer

        'Unloads the image immediately after execution within NX
        GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Immediately

    End Function

End Module 

After I select view I receive an error:
  • System.nullreferenceexception: Object reference not set to an instance of an object (...) line 43


  • Also this selection method allow me to select only one view, but I wanna select multiple. How to fix it?

    With best regards
    Michael

    RE: Journal to select drafting view

    You get a null reference exception on line 43 because DRWVIEWS is declared as a drafting view collection object, but it needs to reference a specific instance. However, it isn't necessary at all in your code. Since you are passing in a reference to a view that you want to change, simply use the view reference that you pass in, there is no need to iterate through a view collection. Eliminate the 'for each' loop and the DRWVIEWS variable then just operate on the view that you pass in. Once you get it working for a single view, you can then change the code to work with multiple views.

    www.nxjournaling.com

    RE: Journal to select drafting view

    (OP)
    Ok, now the whole sub looks like this:

    CODE

    Sub EditView(ByVal theDrftView as drawings.DraftingView)
    
    	Dim markId3 As Session.UndoMarkId
    	Dim dimname1 As String = Nothing
            dim selectedView As View 
    
    
                dimname1 = selectedView.ToString()
    
    
    		If dimname1.Contains("projected") = True Then
    		   Dim projectedView1 As Drawings.ProjectedView = selectedView
    		   projectedView1.Style.HiddenLines.HiddenlineFont = Preferences.Font.Invisible
    		   workPart.DraftingViews.SuppressViewBreaks(projectedView1)
                       projectedView1.Commit()
    		   workPart.DraftingViews.RestoreViewBreaks(projectedView1)
    		end if 	
    
    	'Next
    
            Dim nErrs1 As Integer
            nErrs1 = theSession.UpdateManager.DoUpdate(markId3) 

    But I still get null reference error.

    With best regards
    Michael

    RE: Journal to select drafting view

    Change this

    CODE

    dimname1 = selectedView.ToString() 
    to this

    CODE

    dimname1 = theDrftView.ToString() 

    then you can get rid of the unnecessary selectedView variable.

    www.nxjournaling.com

    RE: Journal to select drafting view

    (OP)
    Thanks, that solved some problems, but how to rid of selectedview?

    With best regards
    Michael

    RE: Journal to select drafting view

    (OP)
    Ok, I solved it. Now I would like to select more than one view. How to do this?

    CODE

    Option Strict Off
    Imports System
    Imports NXOpen
    Imports NXOpen.UF
    Imports NXOpen.UI
    
    Module Module1
    
            Dim theSession As Session = Session.GetSession()
    	Dim ui As UI = UI.GetUI()
    	Dim ufs As UFSession = UFSession.GetUFSession()
    	Dim workPart As Part = theSession.Parts.Work
            Dim lw As ListingWindow = theSession.ListingWindow
    
        Sub Main()
    
            If IsNothing(theSession.Parts.BaseWork) Then
                'active part required
                Return
            End If
    
            lw.Open()
    
            Dim theDrftView As Drawings.DraftingView
    	Dim response1 as Selection.Response = Selection.Response.Cancel
    
    start1:
            response1 = SelectDraftingView("select drafting view", theDrftView)
    
            EditView(theDrftView)
    end1:
        End Sub
    
    
    
        Sub EditView(ByVal theDrftView as drawings.DraftingView)
    
    	Dim markId3 As Session.UndoMarkId
    	Dim dimname1 As String = Nothing
            dim selectedView As View 
    
    
    
    		dimname1 = theDrftView.ToString()
    
    
            'lw.WriteLine(dimname1)
            'lw.WriteLine("view selected: " & theDrftView.Name)
    
    		If dimname1.Contains("ProjectedView") = True Then
    		   Dim projectedView1 As Drawings.ProjectedView = thedrftview
    		   projectedView1.Style.HiddenLines.HiddenlineFont = Preferences.Font.Invisible
    		   workPart.DraftingViews.SuppressViewBreaks(projectedView1)
                       projectedView1.Commit()
    		   workPart.DraftingViews.RestoreViewBreaks(projectedView1)
    		end if 	
    
    		If dimname1.Contains("BaseView") = True Then
    		   Dim baseView1 As Drawings.BaseView = thedrftview
    		   baseView1.Style.HiddenLines.HiddenlineFont = Preferences.Font.Invisible
    		   workPart.DraftingViews.SuppressViewBreaks(baseView1)
     		   baseView1.Commit()
    		   workPart.DraftingViews.RestoreViewBreaks(baseView1)
    		end if 
    
    		If dimname1.Contains("SectionView") = True Then
    
    		   Dim sectionView1 As Drawings.SectionView = thedrftview
    		   sectionView1.Style.HiddenLines.HiddenlineFont = Preferences.Font.Invisible
    		   workPart.DraftingViews.SuppressViewBreaks(sectionView1)
    		   sectionView1.Commit()
    		   workPart.DraftingViews.RestoreViewBreaks(sectionView1)
    
    		end if 
    
    	'Next
    
    
    
            Dim nErrs1 As Integer
            nErrs1 = theSession.UpdateManager.DoUpdate(markId3)
    
    
        End Sub
    
        Function SelectDraftingView(ByVal prompt As String, ByRef selView As Drawings.DraftingView) As Selection.Response
    
            Dim theUI As UI = UI.GetUI
            Dim title As String = "Select a drafting view"
            Dim includeFeatures As Boolean = False
            Dim keepHighlighted As Boolean = False
            Dim selAction As Selection.SelectionAction = Selection.SelectionAction.ClearAndEnableSpecific
            Dim cursor As Point3d
            Dim scope As Selection.SelectionScope = Selection.SelectionScope.WorkPart
            Dim selectionMask_array(0) As Selection.MaskTriple
            Dim selObj As TaggedObject
    
            With selectionMask_array(0)
                .Type = UFConstants.UF_view_type
                .Subtype = UFConstants.UF_all_subtype
            End With
    
            Dim resp As Selection.Response = theUI.SelectionManager.SelectTaggedObject(prompt, _
             title, scope, selAction, _
             includeFeatures, keepHighlighted, selectionMask_array, _
             selObj, cursor)
            If resp = Selection.Response.ObjectSelected OrElse resp = Selection.Response.ObjectSelectedByName Then
                selView = CType(selObj, Drawings.DraftingView)
                Return Selection.Response.Ok
            Else
                Return Selection.Response.Cancel
            End If
    
        End Function
    
        Public Function GetUnloadOption(ByVal dummy As String) As Integer
    
            'Unloads the image immediately after execution within NX
            GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Immediately
    
        End Function
    
    End Module 

    With best regards
    Michael

    RE: Journal to select drafting view

    Quote (niedzviedz)

    Now I would like to select more than one view. How to do this?
    In the SelectDraftingView function you will need to use the .SelectTaggedObjects function rather than the .SelectTaggedObject function. This will require you to declare an array of objects and pass it in to your updated selection function. Then edit the EditView subroutine to accept and process an array of drafting views.


    p.s. your EditView subroutine can be simplified to this:

    CODE

    Sub EditView(ByVal theDrftView as drawings.DraftingView)
    
    	Dim markId3 As Session.UndoMarkId
    
    		   theDrftView.Style.HiddenLines.HiddenlineFont = Preferences.Font.Invisible
    		   workPart.DraftingViews.SuppressViewBreaks(theDrftView)
                       theDrftView.Commit()
    		   workPart.DraftingViews.RestoreViewBreaks(theDrftView)
    
            Dim nErrs1 As Integer
            nErrs1 = theSession.UpdateManager.DoUpdate(markId3)
    
    
        End Sub 

    www.nxjournaling.com

    RE: Journal to select drafting view

    (OP)
    Thank @Cowski.

    I changed the code to this:

    CODE

    Option Strict Off
    Imports System
    Imports NXOpen
    Imports NXOpen.UF
    Imports NXOpen.UI
    
    Module Module1
    
            Dim theSession As Session = Session.GetSession()
    	Dim ui As UI = UI.GetUI()
    	Dim ufs As UFSession = UFSession.GetUFSession()
    	Dim workPart As Part = theSession.Parts.Work
            Dim lw As ListingWindow = theSession.ListingWindow
    
        Sub Main()
    
            If IsNothing(theSession.Parts.BaseWork) Then
                'active part required
                Return
            End If
    
            lw.Open()
    
    	Dim selectedviews (-1) As TaggedObject
            Dim theDrftView As Drawings.DraftingView
    	Dim response1 as Selection.Response = Selection.Response.Cancel
    
    start1:
            response1 = SelectDraftingView(selectedviews)
    
            EditView(selectedviews)
    end1:
        End Sub
    
    
    
        Sub EditView(ByVal selectedviews () As TaggedObject)  
    
    
    	Dim markId3 As Session.UndoMarkId
    
            For Each selectedview as view in selectedviews
    
    		   Dim theDrftView As Drawings.DraftingView
    
    		   theDrftView.Style.HiddenLines.HiddenlineFont = Preferences.Font.Invisible
    		   workPart.DraftingViews.SuppressViewBreaks(theDrftView)
                       theDrftView.Commit()
    		   workPart.DraftingViews.RestoreViewBreaks(theDrftView)
    
    	next
    
            Dim nErrs1 As Integer
            nErrs1 = theSession.UpdateManager.DoUpdate(markId3)
    
    
        End Sub
    
        Function SelectDraftingView(ByRef selobj() As TaggedObject) As Selection.Response
    
            Dim theUI As UI = UI.GetUI
    
    	Dim resp As Selection.Response = Selection.Response.Cancel
            Dim prompt As String = "Select a drafting view"
            Dim message As String = "Select a drafting view"
            Dim title As String = "Selection"
            Dim scope As Selection.SelectionScope = Selection.SelectionScope.WorkPart
            Dim selAction As Selection.SelectionAction = Selection.SelectionAction.ClearAndEnableSpecific
            Dim cursor As Point3d
            Dim selectionMask_array(0) As Selection.MaskTriple
            Dim includeFeatures As Boolean = False
            Dim keepHighlighted As Boolean = False
    
            With selectionMask_array(0)
                .Type = UFConstants.UF_view_type
                .Subtype = UFConstants.UF_all_subtype
            End With
    
             resp = theUI.SelectionManager.SelectTaggedObjects(prompt, message, scope, _
                    selAction, includeFeatures, keepHighlighted, selectionMask_array, selObj)
    
    
            If resp = Selection.Response.ObjectSelected OrElse resp = Selection.Response.ObjectSelectedByName Then
     '           selView = CType(selObj, Drawings.DraftingView)
                Return Selection.Response.Ok
            Else
                Return Selection.Response.Cancel
            End If
    
        End Function
    
        Public Function GetUnloadOption(ByVal dummy As String) As Integer
    
            'Unloads the image immediately after execution within NX
            GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Immediately
    
        End Function
    
    End Module 

    But after I select the view and click OK i receive an error "null reference exception" line 46. I also commented line 84, because I get an error too. Any suggestions what I done wrong?

    With best regards
    Michael

    RE: Journal to select drafting view

    The signature of a "For Each" loop looks something like this:

    CODE

    For Each tempVariable as Type in Collection 

    A For Each loop processes each item in the specified collection; the tempVariable holds the current item from the collection. That means that inside the loop, we need to use the tempVariable to reference the current item. In the case of your code, you have named the temporary variable seledtedview; therefore, your code should look something like this:

    CODE

    For Each selectedview as view in selectedviews
    
       selectedview.Style.HiddenLines.HiddenlineFont = Preferences.Font.Invisible
       workPart.DraftingViews.SuppressViewBreaks(selectedview)
       selectedview.Commit()
       workPart.DraftingViews.RestoreViewBreaks(selectedview)
    
    next 

    www.nxjournaling.com

    RE: Journal to select drafting view

    (OP)
    I tried this, but I've got an error "element "style" is not a member of NXopen.view" and "element "commit" is not a member of NXopen.view" so I changed code to shown above.

    With best regards
    Michael

    RE: Journal to select drafting view

    You've specified selectedview as the wrong type. Instead of "view", it should be "Drawings.DraftingView" as in your previous code.

    www.nxjournaling.com

    RE: Journal to select drafting view

    (OP)
    Thanks @Cowski for your support. Below is my final code, maybe it will be useful for someone. It toggle between invisible / dashed lines.

    CODE

    Option Strict Off
    Imports System
    Imports NXOpen
    Imports NXOpen.UF
    Imports NXOpen.UI
    
    Module Module1
    
            Dim theSession As Session = Session.GetSession()
    	Dim ui As UI = UI.GetUI()
    	Dim ufs As UFSession = UFSession.GetUFSession()
    	Dim workPart As Part = theSession.Parts.Work
            Dim lw As ListingWindow = theSession.ListingWindow
    
        Sub Main()
    
            If IsNothing(theSession.Parts.BaseWork) Then
                'active part required
                Return
            End If
    
            lw.Open()
    
    	Dim selectedviews (-1) As TaggedObject
            Dim theDrftView As Drawings.DraftingView
    	Dim response1 as Selection.Response = Selection.Response.Cancel
    
    start1:
            response1 = SelectDraftingView(selectedviews)
    
            EditView(selectedviews)
    end1:
        End Sub
    
        Sub EditView(ByVal selectedviews () As TaggedObject)  
    
    	Dim markId3 As Session.UndoMarkId
    	Dim status as string	
    
            For Each selectedview as Drawings.DraftingView in selectedviews
    
    		   if selectedview.Style.HiddenLines.HiddenlineFont = Preferences.Font.Invisible then
    
    		   selectedview.Style.HiddenLines.HiddenlineFont = Preferences.Font.dashed
    		   workPart.DraftingViews.SuppressViewBreaks(selectedview)
                       selectedview.Commit()
    		   workPart.DraftingViews.RestoreViewBreaks(selectedview) 		
    
    		   elseif selectedview.Style.HiddenLines.HiddenlineFont = Preferences.Font.dashed then
    
    		   selectedview.Style.HiddenLines.HiddenlineFont = Preferences.Font.Invisible
    		   workPart.DraftingViews.SuppressViewBreaks(selectedview)
                       selectedview.Commit()
    		   workPart.DraftingViews.RestoreViewBreaks(selectedview)
    		   
    		   end if 	
    	next
    
            Dim nErrs1 As Integer
            nErrs1 = theSession.UpdateManager.DoUpdate(markId3)
    
        End Sub
    
        Function SelectDraftingView(ByRef selobj() As TaggedObject) As Selection.Response
    
            Dim theUI As UI = UI.GetUI
    
    	Dim resp As Selection.Response = Selection.Response.Cancel
            Dim prompt As String = "Select a drafting view"
            Dim message As String = "Select a drafting view"
            Dim title As String = "Selection"
            Dim scope As Selection.SelectionScope = Selection.SelectionScope.WorkPart
            Dim selAction As Selection.SelectionAction = Selection.SelectionAction.ClearAndEnableSpecific
            Dim cursor As Point3d
            Dim selectionMask_array(0) As Selection.MaskTriple
            Dim includeFeatures As Boolean = False
            Dim keepHighlighted As Boolean = False
    
            With selectionMask_array(0)
                .Type = UFConstants.UF_view_type
                .Subtype = UFConstants.UF_all_subtype
            End With
    
             resp = theUI.SelectionManager.SelectTaggedObjects(prompt, message, scope, _
                    selAction, includeFeatures, keepHighlighted, selectionMask_array, selObj)
    
            If resp = Selection.Response.ObjectSelected OrElse resp = Selection.Response.ObjectSelectedByName Then
                Return Selection.Response.Ok
            Else
                Return Selection.Response.Cancel
            End If
    
        End Function
    
        Public Function GetUnloadOption(ByVal dummy As String) As Integer
    
            'Unloads the image immediately after execution within NX
            GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Immediately
    
        End Function
    
    End Module 

    With best regards
    Michael

    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