Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations SDETERS on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Journal to select drafting view 2

Status
Not open for further replies.

niedzviedz

Mechanical
Apr 1, 2012
307
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)
[ul]
[li]line 28 - There is no arguments for selview [/li]
[li]line 28 - You cannot convert from type nxopen.drawings.draftingview to string [/li]
[li]line 41 - draftview is not declared [/li]
[/ul]




With best regards
Michael
 
Replies continue below

Recommended for you

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
 
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
 
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:
[li]System.nullreferenceexception: Object reference not set to an instance of an object (...) line 43 [/li]

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

With best regards
Michael
 
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
 
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
 
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
 
Thanks, that solved some problems, but how to rid of selectedview?

With best regards
Michael
 
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
 
niedzviedz said:
Now I would like to select more than one view. How to do this?
In the SelectDraftingView function you will need to use the .SelectTaggedObject[highlight #FCE94F]s[/highlight] 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
 
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
 
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
 
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
 
You've specified selectedview as the wrong type. Instead of "view", it should be "Drawings.DraftingView" as in your previous code.

www.nxjournaling.com
 
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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor