Delete a named group on a specific sheet

I need to delete a named groud on a specific sheet
I manage to delete a named object:
ufs.Obj.CycleByName(theName, aTag)

But like this I delete all objects with that name on all the sheets.
I need to limit this to a specific sheet.

Who can help me with this?

What version of NX?

What if the members of a given group are located on different sheets? Do you want to delete only the members on the given sheet?

Thanks for the quick response!
Sloppy:(
It is in VB for NX7.5 and up!
All the members of the group are on the same sheet.

Once you find the group by name, test one of the members to see what sheet it is on. If it is on the sheet of interest, delete the group (including members).




The code below is taken from the GTAC solution site, and it written by Amy Webster. The code will return the drawing sheet that a given object resides on.



' This function will work for:
' an object which "Resides on drawing" or is "View Dependent In" a DraftingView
' a DraftingView
' a DrawingSheet.View
' Returns Nothing for all other (ie. model mode) objects
Function AskDrawingSheet(ByVal theObject As TaggedObject) As Drawings.DrawingSheet

Dim theView As View = TryCast(theObject, View)
If Not theView Is Nothing Then
Dim sheetTag As Tag = Nothing
Try
theUFSession.Draw.AskDrawingOfView(theView.Tag, sheetTag)
Return NXObjectManager.Get(sheetTag) ' the drawing it is on
Catch ex As NXException
Return Nothing ' it is a model view
End Try
End If

Dim viewName As String = Nothing
Dim status As Integer = Nothing
Try
theUFSession.View.AskViewDependentStatus(theObject.Tag, status, viewName)
Catch ex As NXException
Return Nothing
End Try
If status = 0 Then Return Nothing ' it is a model mode object

Dim viewTag As Tag = Nothing
theUFSession.View.AskTagOfViewName(viewName, viewTag)
Dim viewType As Integer = Nothing
Dim viewSubtype As Integer = Nothing
theUFSession.View.AskType(viewTag, viewType, viewSubtype)
If viewType = 0 Then Return Nothing ' it is view dependent in a modeling view

Dim drawingTag As Tag = Nothing
theUFSession.Draw.AskDrawingOfView(viewTag, drawingTag)
Return NXObjectManager.Get(drawingTag) ' the drawing it is on!

End Function

I'm trying to test some member of group to see what sheet is it on (using previously posted function which works on me). But I don't know how to get that member of group (actually drawing group). I thought of trying something like members=myGroup.Members.Get, but even if that would work, I don't know what class whould be the variable members, because Drafting Group consists of various types.

Thanks for help.


'NXJournaling.com
'tested with NX 7.5
'May 31, 2012
'When run, the journal will highlight all dimensions in the part that have manually entered text.
'The listing window will report the dimension text, view, and sheet for each dimension
'with manually entered text.

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

Module dimensions_to_standard
Dim theSession As Session = Session.GetSession()
Dim ufs As UFSession = UFSession.GetUFSession()
Dim theUfSession As UFSession = UFSession.GetUFSession

Sub Main()

Dim workPart As Part = theSession.Parts.Work
Dim displayPart As Part = theSession.Parts.Display
Dim lw As ListingWindow = theSession.ListingWindow

Dim markId1 As NXOpen.Session.UndoMarkId = Nothing
markId1 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "Start")

'Dim smazani Groups
Dim tmpGrp As NXOpen.Tag = NXOpen.Tag.Null
Dim myGroup As Group
Dim groupsToDelete As New List(Of Group)

'CURRENT SHEET
Dim currentSheet As Drawings.DrawingSheet = theSession.Parts.Work.DrawingSheets.CurrentDrawingSheet

'nacteni drafting standards
Dim loadDraftingStandardBuilder1 As NXOpen.Preferences.LoadDraftingStandardBuilder = Nothing
loadDraftingStandardBuilder1 = workPart.Preferences.DraftingPreference.CreateLoadDraftingStandardBuilder()
loadDraftingStandardBuilder1.WelcomeMode = False
loadDraftingStandardBuilder1.Level = NXOpen.Preferences.LoadDraftingStandardBuilder.LoadLevel.Site
loadDraftingStandardBuilder1.Name = "ISO_NX11_LDM"
Dim nXObject1 As NXOpen.NXObject = Nothing
nXObject1 = loadDraftingStandardBuilder1.Commit()
loadDraftingStandardBuilder1.Destroy()

'smazani GROUPS
Do
theUfSession.Obj.CycleObjsInPart(workPart.Tag, UFConstants.UF_group_type, tmpGrp)
'skip the initial null tag
If tmpGrp = NXOpen.Tag.Null Then
Continue Do
End If

myGroup = Utilities.NXObjectManager.Get(tmpGrp)
If (myGroup.Name="A4_LDM") or (myGroup.Name="A3_LDM") or (myGroup.Name="A2_LDM") or (myGroup.Name="A1_LDM") or (myGroup.Name="A0_LDM") or (myGroup.Name="RAZITKO_LDM") Then
Dim symbolSheet As Drawings.DrawingSheet = AskDrawingSheet(myGroup)
lw.WriteLine("" & symbolSheet.Tag)
'If currentSheet.Tag=symbolSheet.Tag Then
' groupsToDelete.Add(myGroup)
'End If
End If

Loop Until tmpGrp = NXOpen.Tag.Null

Dim nErrs1 As Integer
nErrs1 = theSession.UpdateManager.AddToDeleteList(groupsToDelete.ToArray)

Dim nErrs2 As Integer
nErrs2 = theSession.UpdateManager.DoUpdate(markId1)

End Sub

' This function will work for:
' an object which "Resides on drawing" or is "View Dependent In" a DraftingView
' a DraftingView
' a DrawingSheet.View
' Returns Nothing for all other (ie. model mode) objects
'code by Amy Webster of GTAC,
'GTAC document: nx_api4936 or nx_api4937
Function AskDrawingSheet(ByVal theObject As TaggedObject) As Drawings.DrawingSheet

Dim theView As View = TryCast(theObject, View)
If Not theView Is Nothing Then
Dim sheetTag As Tag = Nothing
Try
theUFSession.Draw.AskDrawingOfView(theView.Tag, sheetTag)
Return Utilities.NXObjectManager.Get(sheetTag) ' the drawing it is on
Catch ex As NXException
Return Nothing ' it is a model view
End Try
End If

Dim viewName As String = Nothing
Dim status As Integer = Nothing
Try
theUFSession.View.AskViewDependentStatus(theObject.Tag, status, viewName)
Catch ex As NXException
Return Nothing
End Try
If status = 0 Then Return Nothing ' it is a model mode object

Dim viewTag As Tag = Nothing
theUFSession.View.AskTagOfViewName(viewName, viewTag)
Dim viewType As Integer = Nothing
Dim viewSubtype As Integer = Nothing
theUFSession.View.AskType(viewTag, viewType, viewSubtype)
If viewType = 0 Then Return Nothing ' it is view dependent in a modeling view

Dim drawingTag As Tag = Nothing
theUFSession.Draw.AskDrawingOfView(viewTag, drawingTag)
Return Utilities.NXObjectManager.Get(drawingTag) ' the drawing it is on!

End Function

End Module


I test the sheet it belongs to it like this, but it doesn't work for sole groups...

Dim symbolSheet As Drawings.DrawingSheet = AskDrawingSheet(partObject)
If currentSheet.Tag=symbolSheet.Tag Then
Dim objects1(0) As NXOpen.DisplayableObject
objects1(0)=partObject
Dim editSettingsBuilder1 As NXOpen.Annotations.EditSettingsBuilder = Nothing
editSettingsBuilder1 = workPart.SettingsManager.CreateAnnotationEditSettingsBuilder(objects1)
editSettingsBuilder1.InheritSettingsFromPreferences()
Dim nXObject2 As NXOpen.NXObject = Nothing
nXObject2 = editSettingsBuilder1.Commit()
editSettingsBuilder1.Destroy()

End If
Next

I have some code that reports all the groups in the work part and how many members are in each group. The .AskGroupData method returns an array of tags that represent the group members. You can use the NXObject manager to get the objects as an NXObject or TaggedObject; from there you can query the underlying object type with .GetType and cast it to a more specific object type if needed.

Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF

Module Module1

Sub Main()

Dim theSession As Session = Session.GetSession()
Dim theUfSession As UFSession = UFSession.GetUFSession
Dim workPart As Part = theSession.Parts.Work

Dim lw As ListingWindow = theSession.ListingWindow
lw.Open()

Dim tmpGrp As NXOpen.Tag = NXOpen.Tag.Null
Dim myGroup As Group

Dim numMembers As Integer
Dim memberTags() As Tag

Dim numOwningGroups As Integer
Dim owningGroups() As Tag

Do
theUfSession.Obj.CycleObjsInPart(workPart.Tag, UFConstants.UF_group_type, tmpGrp)
'skip the initial null tag
If tmpGrp = NXOpen.Tag.Null Then
Continue Do
End If

myGroup = Utilities.NXObjectManager.Get(tmpGrp)
lw.WriteLine("group name: " & myGroup.Name)

theUfSession.Group.AskGroupData(myGroup.Tag, memberTags, numMembers)
lw.WriteLine(" group contains: " & numMembers.ToString & " members")

theUfSession.Group.AskAllOwningGroups(myGroup.Tag, numOwningGroups, owningGroups)
If numOwningGroups > 0 Then
lw.WriteLine(" owned by: " & numOwningGroups.ToString & " other group(s)")
End If

lw.WriteLine("")
Loop Until tmpGrp = NXOpen.Tag.Null

End Sub

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 worked with your advice and finished the code with .AskGroupData method and made it work.

Cheers.