Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

Delete specific drafting curves with Journal

Status
Not open for further replies.

hurley710

Automotive
Feb 4, 2009
59
I can get this to work with the majority of files, but the occassional one does not work and I'm not sure why.

I have a simple if/then statement that if a part attribute has a certain value, then to delete three curves and four notes from two separate sheets within a drawing. These curves and notes are in the exact location in every file.

Any ideas on how to do this 100% of the time? Thanks in advance.
 
Replies continue below

Recommended for you

Do you get an error or it just doesn't work on some files? Either the attribute value isn't what you think it is, or the journal can't find the specified objects.

What does your attribute value test look like, what values don't work that you think should?
How are you currently specifying which curves/notes to delete?

You might consider giving these objects custom names or attributes that you could search for when the journal runs. Another option would be to put all the objects of interest into a named group, then delete the objects in the group depending on the part attribute value.

www.nxjournaling.com
 
cowski,

I get an error saying No object found with this name.

What I did was recorded a journal, selected the lines and notes, deleted, and stopped recording. I'm pretty sure it just can't find the specified objects in every file.

The if/then statement is simple...

strDWG_STATUS = workPart.GetStringAttribute("DWG_STATUS")
if strDWG_STATUS = "PRELIMINARY" then

'''''NX AUTOMATED CODE'''''

I like the idea of giving a custom name to the lines/notes or grouping them together into a custom named group and deleting that. Could you elaborate further on direction?
 
Clarification... I know how to group them together, just not sure how to call out the delete.

Let's say I combined them into a group called "DWG_STATUS_TAB", how would I delete?
 
Code:
[COLOR=green]'[URL unfurl="true"]http://www.eng-tips.com/viewthread.cfm?qid=359903[/URL][/color]
[COLOR=green]'find a group with a given name[/color]
[COLOR=green]'  delete the members and the group[/color]

[COLOR=green]'February 14, 2014[/color]

[COLOR=blue]Option Strict Off[/color]  
[COLOR=blue]Imports[/color] System  
[COLOR=blue]Imports[/color] NXOpen  
[COLOR=blue]Imports[/color] NXOpen.UF  

[COLOR=blue]Module[/color] group_delete  

    [COLOR=blue]Sub[/color] Main()  

        [COLOR=blue]Dim[/color] theSession [COLOR=blue]As[/color] Session [COLOR=blue]=[/color] Session.GetSession()  
        [COLOR=blue]Dim[/color] theUfSession [COLOR=blue]As[/color] UFSession [COLOR=blue]=[/color] UFSession.GetUFSession  
        [COLOR=blue]Dim[/color] workPart [COLOR=blue]As[/color] Part [COLOR=blue]=[/color] theSession.Parts.Work  

        [COLOR=blue]Const[/color] targetGroup [COLOR=blue]As String =[/color] "DWG_STATUS_TAB"  

        [COLOR=blue]Dim[/color] groupTag [COLOR=blue]As[/color] NXOpen.Tag [COLOR=blue]=[/color] NXOpen.Tag.Null  
        [COLOR=blue]Dim[/color] myGroup [COLOR=blue]As[/color] Group  

        [COLOR=blue]Do[/color]  
            theUfSession.Obj.CycleObjsInPart(workPart.Tag, UFConstants.UF_group_type, groupTag)  
 [COLOR=green]'skip the initial null tag[/color]
            [COLOR=blue]If[/color] groupTag [COLOR=blue]=[/color] NXOpen.Tag.Null [COLOR=blue]Then[/color]  
                [COLOR=blue]Continue Do[/color]  
            End [COLOR=blue]If[/color]  

            myGroup [COLOR=blue]=[/color] Utilities.NXObjectManager.Get(groupTag)  

            [COLOR=blue]If[/color] myGroup.Name.ToUpper [COLOR=blue]=[/color] targetGroup [COLOR=blue]Then[/color]  

                theSession.UpdateManager.ClearErrorList()  

                [COLOR=blue]Dim[/color] markId1 [COLOR=blue]As[/color] Session.UndoMarkId  
                markId1 [COLOR=blue]=[/color] theSession.SetUndoMark(Session.MarkVisibility.Visible, "Delete group")  

                [COLOR=blue]Dim[/color] objects1(0) [COLOR=blue]As[/color] NXObject  
                objects1(0) [COLOR=blue]=[/color] myGroup  

                [COLOR=blue]Dim[/color] nErrs1 [COLOR=blue]As Integer[/color]  
                nErrs1 [COLOR=blue]=[/color] theSession.UpdateManager.AddToDeleteList(objects1)  

                [COLOR=blue]Dim[/color] nErrs2 [COLOR=blue]As Integer[/color]  
                nErrs2 [COLOR=blue]=[/color] theSession.UpdateManager.DoUpdate(markId1)  

                [COLOR=blue]Exit Do[/color]  

            End [COLOR=blue]If[/color]  

        [COLOR=blue]Loop Until[/color] groupTag [COLOR=blue]=[/color] NXOpen.Tag.Null  

    End [COLOR=blue]Sub[/color]  

End [COLOR=blue]Module[/color]


www.nxjournaling.com
 
cowski,

That worked great. I appreciate it.

One thing I failed to mention though is that the "DWG_STATUS_TAB" I'm trying to delete actually exists on multiple drawing sheets. When I run this, it only deletes the tab on the first sheet. I have to run it again for it to delete it on the next. Is there a way for it to A) look for it on all sheets and then delete all or B) loop until the Group name can no longer be found?
 
In that case, we'll take a slightly different approach. It is generally bad practice to delete an object that belongs to a collection that you are iterating through. Doing so can introduce errors and undesirable side effects. We got away with it in the previous code because I assumed we were only looking for one group. Once we found the group, we'd delete it an immediately exit the loop.

In the new version, we'll keep track of the groups that we want to delete (by way of a list object); then after the loop has completed cycling through all the group objects, we'll delete the ones we found.

Code:
'[URL unfurl="true"]http://www.eng-tips.com/viewthread.cfm?qid=359903[/URL]
'find a group with a given name
'  delete the members and the group

'February 14, 2014

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

Module group_delete

    Sub Main()

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

        Const targetGroup As String = "DWG_STATUS_TAB"

        Dim groupsToDelete As New List(Of Group)

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

        'use Do loop to find all groups with the given name
        Do
            theUfSession.Obj.CycleObjsInPart(workPart.Tag, UFConstants.UF_group_type, groupTag)
            'skip the initial null tag
            If groupTag = NXOpen.Tag.Null Then
                Continue Do
            End If

            myGroup = Utilities.NXObjectManager.Get(groupTag)

            If myGroup.Name.ToUpper = targetGroup Then

                groupsToDelete.Add(myGroup)

            End If

        Loop Until groupTag = NXOpen.Tag.Null

        'delete all the groups that we found
        theSession.UpdateManager.ClearErrorList()

        Dim markId1 As Session.UndoMarkId
        markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Delete group")

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

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

    End Sub

End Module

www.nxjournaling.com
 
cowski,

Works like a charm... Thanks a million!

You've never left me hanging. Do appreciate it. If you're ever in Chicago, I owe you a beer!
 
Hi, I was going to modify this journal file to delete any groups with a name that includes MD, but it doesn't work.

I modified the below journal line:
Const targetGroup As String = "DWG_STATUS_TAB"

to say:
Const targetGroup As String = "MD*"

but it doesn't work. It gives no errors. If I change it to something like:

Const targetGroup As String = "MD.2000.0055-1"

it will delete the group with that name. Why doesn't the wildcard take care of this?

Thanks for any help you can give me,

Matt
 
MattBaumann said:
Why doesn't the wildcard take care of this?

In this context, the '*' character doesn't act as a wildcard, it is simply another character in the string. If you want to delete any group that includes MD, you could change the following lines of code as follows:

Code:
[COLOR=#4E9A06]'Const targetGroup As String = "DWG_STATUS_TAB"[/color]
Const targetGroup As String = "MD"
.
.
[COLOR=#4E9A06]'If myGroup.Name.ToUpper = targetGroup Then[/color]
If myGroup.Name.ToUpper.Contains(targetGroup) Then
.
.

However, if the'*' character did act as a wildcard, your code would only delete the groups whose names started with "MD". If this is what you want, use the .StartsWith method rather than the .Contains method.

If needed, you can use regular expressions in the code which would allow you to get really specific. For instance, delete all the groups that start with MD followed by a 4 digit number less than 2000.

www.nxjournaling.com
 
cowski you are a lifesaver. That worked perfectly. They all start with MD fyi.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor