View Dependent Edit

Hi NX Journaling,

I'm trying to make a journal for doing View Dependent Edit in the drawing. I recorded a journal and modified the code so that the code would run the View Dependent Edit for any number of points in a particular sheet. However i'm unable to replace the point and the body name in the code. Could you please help with the modification of the code. Below is the code.

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

Module VDE
Sub Main (ByVal args() As String)

Dim theSession As Session = Session.GetSession()
Dim workPart As Part = theSession.Parts.Work
Dim displayPart As Part = theSession.Parts.Display

Dim startSheet As Drawings.DrawingSheet = theSession.Parts.Work.DrawingSheets.CurrentDrawingSheet
Dim viewsToSelect() As Drawings.DraftingView = startSheet.GetDraftingViews

For Each tempView as Drawings.DraftingView in viewsToSelect

Dim markId1 As Session.UndoMarkId = Nothing
markId1 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "VDE erase objects")
Dim objects1(0) As NXOpen.DisplayableObject
Dim draftingBody1 As NXOpen.Drawings.DraftingBody = CType(tempview.DraftingBodies.FindObject("COMPONENT ModelZ 1 0"), NXOpen.Drawings.DraftingBody)
Dim draftingPoint1 As NXOpen.Drawings.DraftingPoint = CType(draftingBody1.DraftingPoints.FindObject("(Extracted Point) HANDLE R-2770"), NXOpen.Drawings.DraftingPoint)
objects1(0) = draftingPoint1
tempView.DependentDisplay.Erase(objects1)
tempView.Commit()

next

End Sub
End Module

Hello NX JOurnaling, i have tried to do the view dependent edit for the drafting view points as below:

I'm encountering an error: Value of type 'NXOpen.Selection.Response' cannot be converted to 'NXOpen.Drawings.DraftingPoint'. I'm not sure if i have used the right object types in the selectionMask_array. Could you please help me out.

Option Strict Off
Imports System
Imports System.Collections.Generic
Imports NXOpen
Imports NXOpen.UF

Module VDE
Sub Main (ByVal args() As String)

Dim theSession As Session = Session.GetSession()
Dim workPart As Part = theSession.Parts.Work
Dim displayPart As Part = theSession.Parts.Display
Dim ptsPoints As New List(Of Point)

Dim startSheet As Drawings.DrawingSheet = theSession.Parts.Work.DrawingSheets.CurrentDrawingSheet
Dim viewsToSelect() As Drawings.DraftingView = startSheet.GetDraftingViews

Do Until SelectPoints("select point", ptsPoints) = Selection.Response.Cancel

For Each tempView as Drawings.DraftingView in viewsToSelect

Dim objects1(0) As NXOpen.DisplayableObject
Dim draftingPoint1 As NXOpen.Drawings.DraftingPoint = SelectPoints("select point", ptsPoints)
objects1(0) = draftingPoint1
tempView.DependentDisplay.Erase(objects1)
'tempView.Commit()

next
Loop

End Sub

Function SelectPoints(ByVal prompt As String, ByRef pointList As List(Of Point)) As Selection.Response

Dim theUI As UI = UI.GetUI
Dim title As String = "Select points"
Dim includeFeatures As Boolean = True
Dim keepHighlighted As Boolean = False
Dim selAction As Selection.SelectionAction = Selection.SelectionAction.ClearAndEnableSpecific
Dim selObj() As TaggedObject
'Dim scope As Selection.SelectionScope = Selection.SelectionScope.AnyInAssembly
Dim scope As Selection.SelectionScope = Selection.SelectionScope.WorkPart
Dim selectionMask_array(0) As Selection.MaskTriple

With selectionMask_array(0)
.Type = UFConstants.UF_drafting_entity_type
.Subtype = UFConstants. UF_draft_point_subtype
End With

Dim resp As Selection.Response = theUI.SelectionManager.SelectTaggedObjects(prompt, _
title, 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

Thanks, B

Balaji

I think this code shares some of the same issues as the other code that you recently posted.
http://nxjournaling.com/comment/5778#comment-5778

i tried other way around for view dependent edit and fixed few things which you have mentioned in the other code.but i couldn't fix the error 'Value of type NXOpen.Selection.Response' cannot be converted to 'NXOpen.Drawings.Drafting point'. Could you please help me to update the code.

Option Strict Off
Imports System
Imports System.Collections.Generic
Imports NXOpen
Imports NXOpen.UF

Module VDE

Sub Main (ByVal args() As String)

Dim theSession As Session = Session.GetSession()
Dim workPart As Part = theSession.Parts.Work
Dim displayPart As Part = theSession.Parts.Display
Dim theDraftView As Drawings.DraftingView
Dim ptsPoints As New List(Of Point)

Dim lw As ListingWindow = theSession.ListingWindow

Do Until SelDraftingView("select drafting view", theDraftView) = Selection.Response.Cancel
lw.Open()
lw.WriteLine("view selected: " & theDraftView.Name)
Do Until SelectPoints("select point", ptsPoints) = Selection.Response.Cancel
Dim objects1(0) As NXOpen.DisplayableObject
Dim draftingPoint1 As NXOpen.Drawings.DraftingPoint = SelectPoints("select point", ptsPoints)
objects1(0) = draftingPoint1
theDraftView.DependentDisplay.Erase(objects1)
theDraftView.DependentDisplay.RemoveErasureOnObjectAndSubobjects(objects1, True)
theDraftView.Commit()
Loop
'theDraftView.Clear
'lw.WriteLine("No of points Deleted: " & ptsPoints.Count)
Loop
lw.Close()

End Sub

Function SelectPoints(ByVal prompt As String, ByRef pointList As List(Of Point)) As Selection.Response

pointList.Clear()
Dim selObj() As TaggedObject
Dim theUI As UI = UI.GetUI
Dim title As String = "Select points"
Dim includeFeatures As Boolean = False
Dim keepHighlighted As Boolean = False
Dim selAction As Selection.SelectionAction = Selection.SelectionAction.ClearAndEnableSpecific
Dim scope As Selection.SelectionScope = Selection.SelectionScope.AnyInAssembly
'Dim scope As Selection.SelectionScope = Selection.SelectionScope.WorkPart
Dim selectionMask_array(0) As Selection.MaskTriple

With selectionMask_array(0)
.Type = UFConstants.UF_drafting_entity_type
.Subtype = UFConstants. UF_draft_point_subtype
End With

Dim resp As Selection.Response = theUI.SelectionManager.SelectTaggedObjects(prompt, _
title, scope, selAction, _
includeFeatures, keepHighlighted, selectionMask_array, _
selObj)

If resp = Selection.Response.Ok Then
For Each pt As Point In selObj
pointList.Add(pt)
Next
Return Selection.Response.Ok
Else
Return Selection.Response.Cancel
End If

End Function

Function SelDraftingView(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 = True
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 when the NX session terminates
'GetUnloadOption = NXOpen.Session.LibraryUnloadOption.AtTermination

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

'Unloads the image explicitly, via an unload dialog
'GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Explicitly

End Function

End Module

Balaji

Dim draftingPoint1 As NXOpen.Drawings.DraftingPoint = SelectPoints("select point", ptsPoints)

The "SelectPoints" function returns a 'selection response', which results in a mismatch in the line above.

Hi, I have managed to do the view dependent edit for the drafting view points. this macro would delete all visible points in the drafting view without any user selection input.I would like to extend this macro to allow user selection as well. Could you please help to make this macro run through manual selection....
Option Strict Off
Imports System
Imports System.Collections.Generic
Imports NXOpen
Imports NXOpen.UF

Module ViewDepEdit

Sub Main (ByVal args() As String)

Dim theSession As Session = Session.GetSession()
Dim theUfSession As UFSession = UFSession.GetUFSession()
Dim workPart As Part = theSession.Parts.Work
Dim displayPart As Part = theSession.Parts.Display
Dim theDraftView As Drawings.DraftingView
Dim ptsPoints As New List(Of Point)
Dim ptsNames As New List(Of String)
Dim ptsCount As Integer = "0"
Dim tempName As String = Nothing

Dim lw As ListingWindow = theSession.ListingWindow

Do Until SelDraftingView("select drafting view", theDraftView) = Selection.Response.Cancel
lw.Open()
lw.WriteLine("view selected: " & theDraftView.Name)

For Each tempObj As DisplayableObject In theDraftView.AskVisibleObjects
If TypeOf tempObj Is Point Then
ptsPoints.Add(tempObj)
tempName = tempObj.Name
ptsNames.Add(tempName)
tempObj.Highlight
End If
Next

'lw.WriteLine("Total Points Selected: " & ptsPoints.Count)

For i As Integer = 0 to ptsPoints.Count -1
ptsCount += 1
lw.WriteLine("Point Name: " & ptsNames.Item(i))
'lw.WriteLine("")
'Next
'Do Until SelectPoints("Select points", ptsPoints) = Selection.Response.Cancel
Dim objects1(0) As NXOpen.DisplayableObject
'Dim draftingPoint1 As NXOpen.Drawings.DraftingPoint = SelectPoints("select point", ptsPoints)
objects1(0) = ptsPoints.Item(i)
theDraftView.DependentDisplay.Erase(objects1)
'theDraftView.DependentDisplay.RemoveErasureOnObjectAndSubobjects(objects1, True)
'theDraftView.Commit()
'Loop
Next
lw.WriteLine("No of points Deleted: " & ptsPoints.Count)
lw.WriteLine("")
ptsPoints.Clear()
ptsNames.Clear()

Loop
lw.Close()

End Sub

Function SelectPoints(ByVal prompt As String, ByRef pointList As List(Of Point)) As Selection.Response

pointList.Clear()
Dim selObj() As TaggedObject
Dim theUI As UI = UI.GetUI
Dim title As String = "Select points"
Dim includeFeatures As Boolean = False
Dim keepHighlighted As Boolean = False
Dim selAction As Selection.SelectionAction = Selection.SelectionAction.ClearAndEnableSpecific
'Dim scope As Selection.SelectionScope = Selection.SelectionScope.AnyInAssembly
Dim scope As Selection.SelectionScope = Selection.SelectionScope.WorkPart
Dim selectionMask_array(0) As Selection.MaskTriple

With selectionMask_array(0)
.Type = UFConstants.UF_point_type
.Subtype = UFConstants.UF_point_subtype
' .Type = UFConstants.UF_drafting_entity_type
' .Subtype = UFConstants.UF_draft_target_point_subtype
End With

Dim resp As Selection.Response = theUI.SelectionManager.SelectTaggedObjects(prompt, _
title, scope, selAction, _
includeFeatures, keepHighlighted, selectionMask_array, _
selObj)

If resp = Selection.Response.Ok Then
For Each pt As Point In selObj 'NXOpen.Drawings.Drafting
pointList.Add(pt)
Next
Return Selection.Response.Ok
Else
Return Selection.Response.Cancel
End If

End Function

Function SelDraftingView(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 when the NX session terminates
'GetUnloadOption = NXOpen.Session.LibraryUnloadOption.AtTermination

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

'Unloads the image explicitly, via an unload dialog
'GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Explicitly

End Function

End Module

Balaji