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.
I receive an errors: (I translate it to english, so there maybe some misunderstanding)
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 - 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
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
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
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 ModuleAfter I select view I receive an error:
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
www.nxjournaling.com
RE: Journal to select drafting view
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
CODE
CODE
then you can get rid of the unnecessary selectedView variable.
www.nxjournaling.com
RE: Journal to select drafting view
With best regards
Michael
RE: Journal to select drafting 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 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 ModuleWith best regards
Michael
RE: Journal to select drafting view
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 Subwww.nxjournaling.com
RE: Journal to select drafting view
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 ModuleBut 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
CODE
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
www.nxjournaling.com
RE: Journal to select drafting view
With best regards
Michael
RE: Journal to select drafting view
www.nxjournaling.com
RE: Journal to select drafting 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 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 ModuleWith best regards
Michael