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!

Remove Text Formatting? 1

Status
Not open for further replies.

Kenja824

Automotive
Nov 5, 2014
949
Someone made us a journal to add text for weldspots. We didnt realize it at first that they didnt change the settings for the text but just added formatting to the text. So "296X698" looks like "<F4>296X698<F>" when you double click it. Which messes up a program we use to search for spot numbers. It doesnt find the name if it has other text with it.

I understand we need to improve the search button we have for the spot numbers, but right now we need to remove the formatting from all of the spot number notes on the sheet.

Is there a way to clear all the formatting from selected notes in drafting?

Ken
My brain is like a sponge. A sopping wet sponge. When I use it, I seem to lose more than I soak in.
 
Replies continue below

Recommended for you

I don't know of a standard command that will find & remove the text control characters. What tool are you using for search? Does it allow "extended" or "regular expression" style searching? If so, we might be able to craft a search string to work with your existing text.

Beyond that, I think you'll need to "fight journals with journals", so to speak.

Also, I'd suggest editing your existing journal so that it doesn't add the control characters, if they are not needed.

www.nxjournaling.com
 
Currently the original journal is being edited to change drafting settings before placing the text rather than adding formatting to the text. I was just checking to see if there was something I was not aware of where I can select a bunch of notes and just remove all formatting from them. Then I would just change the settings and we would be good.

There is not really enough of it to do to make it worth creating a new journal to do it. If I was really good with VB, I would do it, but its not worth the struggles I would go through or requesting someones help to do it.

Looks like its just gonna be a little bit of doing something the hard way for a little bit of work. No big deal. Like I said. I was just hoping there was an easy way already in the system. lol

Thanks

Ken
My brain is like a sponge. A sopping wet sponge. When I use it, I seem to lose more than I soak in.
 
Well, just because I don't know a way to do it doesn't mean that it doesn't exist in NX. It might depend on the version you are currently using (I'm currently stuck on an older version). The tools for working with text in NX have been underwhelming for years; I'd be pleasantly surprised to learn of a built-in spellcheck or search/replace.

www.nxjournaling.com
 
Totally agree. It sometimes baffles me that a program so in depth does not have certain functions available to it.

We are currently in NX2027 (I think?) Typically I add that to the subject line. Cant believe it slipped my mind this time. lol


Ken
My brain is like a sponge. A sopping wet sponge. When I use it, I seem to lose more than I soak in.
 
You can use code journal vb to get format letters from text and replace
Code:
Option Strict Off
Imports System  
Imports NXOpen  
Imports NXOpen.UF
Imports NXOpenUI
Imports System.Drawing

Module NXJournal
Sub Main()


    Dim theSession As Session = Session.GetSession()
    Dim theUfSession As UFSession = UFSession.GetUFSession
    Dim ufs As UFSession = UFSession.GetUFSession()
    Dim lw As ListingWindow = theSession.ListingWindow
    Dim workPart As Part = theSession.Parts.Work
    lw.Open()
	For Each tempNote As Annotations.Note In workPart.Notes
		Dim myNoteBuilder As Annotations.DraftingNoteBuilder = workPart.Annotations.CreateDraftingNoteBuilder(tempNote)
		Dim editorText() As String = myNoteBuilder.Text.GetEditorText

		For Each Line As String In editorText
		    Dim text2(0) As String
    	    text2(0) = Line
        	myNoteBuilder.Text.TextBlock.SetText(text2)
            text2 = myNoteBuilder.Text.TextBlock.getText
            If text2(0).Contains("<F4")
                lw.writeline("TEST: " & text2(0))
                text2(0) = Replace(text2(0), "<F4$>", "")
                myNoteBuilder.Text.TextBlock.SetText(text2)
               myNoteBuilder.Commit

            End If
		Next
    myNoteBuilder.Destroy
    Next
    lw.Close()
End Sub

End Module
 
is that program that creates those texts compiled or running non- compiled ?
if non-compiled i imagine that formatting should be "relatively" easy to remove.

Regards, Tomas

The more you know about a subject, the more you know how little you know about that subject.
 
Equilibriu

Im not that good with VB code myself. I ran this code to test it and it seems to just make a list on the info window of all the notes that are formatted. Is that all it is supposed to do or was it supposed to remove formatting or replace something?


Toost

It is someone else who works from home who is creating this. I have no idea how he goes about it. My guess is that it is non-compiled.

Unfortunately the file he gave us is a .dll file and I cannot manipulate it to stop it from creating formatted text. The good news is he is updating it and will fix that. I was just looking to remove formatting from notes already created by windowing around a bunch of notes and removing it from them all.


Ken
My brain is like a sponge. A sopping wet sponge. When I use it, I seem to lose more than I soak in.
 
Kenja824,
Please try this version.
Code:
Option Strict Off
Imports System
Imports System.Text.RegularExpressions
Imports NXOpen

Module Module2

    Sub Main()

        Dim theSession As Session = Session.GetSession()
        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()

        Const undoMarkName As String = "strip note font formatting"
        Dim markId1 As Session.UndoMarkId
        markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, undoMarkName)

        For Each tempNote As Annotations.Note In workPart.Notes

            Dim draftingNoteBuilder1 As Annotations.DraftingNoteBuilder
            draftingNoteBuilder1 = workPart.Annotations.CreateDraftingNoteBuilder(tempNote)
            Dim editorText() As String = draftingNoteBuilder1.Text.GetEditorText

            'look for font formatting codes such as "<F4>", the "F" can be followed by zero or more digits
            Dim pattern As String = "<F\d*>"
            Dim replacement As String = ""

            For i As Integer = 0 To editorText.GetUpperBound(0)
                editorText(i) = Regex.Replace(editorText(i), pattern, replacement)
            Next

            draftingNoteBuilder1.Text.TextBlock.SetText(editorText)

            Dim nXObject1 As NXObject
            nXObject1 = draftingNoteBuilder1.Commit()

            draftingNoteBuilder1.Destroy()

        Next

            lw.Close()

    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

www.nxjournaling.com
 
Sorry cowski

Ive been pretty busy today and just had a chance to see this.

When I ran it, it just gives me a spinning wheel. When I hit stop, it gave me this error....

pic_ki4vbs.jpg



I noticed that line has "Basework" used but I dont see any other reference to that anywhere else in the code. Would that be the reason?

Outside of code, the only notes left that have formatting are already transferred inside the views. Perhaps it is only looking outside the views and just doesnt find anything?

I truly have no idea. Just taking shots in the dark here. lol

Ken
My brain is like a sponge. A sopping wet sponge. When I use it, I seem to lose more than I soak in.
 
The error message is "user abort" which is just telling us that you stopped the process. It is strange that it highlighted line 11; that line is just checking to see if you have a part file open. The journal won't run the rest of the code if there is no active part file. Maybe they changed something in the API and Parts.BaseWork isn't the preferred option any more; I'll look into the NX 2312 help files. As long as you have a file open, you can comment out lines 11-14 and try it without the "active part" check.

I tested the code on NX 2206 with a drawing that had a handful of notes, only 2 of which had text formatting. It worked whether the notes were created in an expanded view or on the drawing sheet itself.

How many notes are in your file? Perhaps it is just running slowly because of a large number of note objects?

www.nxjournaling.com
 
Your are correct cowski

It was just running slow it seems. I ran it and let it go and after a minute I caught a change in a note that lost its formatting. Another minute went by and it completed.

I think what fooled me is that there is no window that pops up or anything. So it looked as if it was stuck with the spinning blue wheel and it didnt do anything right away.

Overall it seems to work perfect.

Thank you.

Ken
My brain is like a sponge. A sopping wet sponge. When I use it, I seem to lose more than I soak in.
 
It changed text formatting. I didn't removed text in the informations windows. You don't get informations about used <F4> for second use journal beacuse was removed on first use.
Cowski upgraded the code. IT is working so I am happy. I AM using this code for get custom symbol to.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor