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!

Split multiple lines of string in separate string 2

Status
Not open for further replies.

iscariot

Mechanical
Oct 15, 2009
154
DE
Shortly, I want to make a spelling checker for text in drawings.
The problem that I have is that most of my text is made of multiple lines.
How can I split the multiple lines of text in separate strings (catscript)?
I was thinking that something like this should work, but it doesn't:
array = Split(text, ""vbcrlf")

I want to make from multiple lines of text, single lines of text and after that I will be able to compare the text from the drawings with some .txt files.

Any kind of help is highly appreciated.

PS
I use Catia V5.R16 on a Unix workstation.



 
Replies continue below

Recommended for you

why not just to copy a text from a verified txt file?
 
I did not explained it very good, sorry.
I have some text from a database that I can save it as .txt file. This is my master text that I know that is good.
I can read this text file using a V5 catscript and I made an array with all of this text.

Now I need to compare the text that is added manually in some V5 drawings with the master text from the array.
I can loop through all of the existing views and texts from V5 drawings, in order to compare it with my master array but I have a problem.
Some of the text from the V5 drawings is made from multiple lines of text and each line of text represent one element that I need to check.
For example I can see in the V5 drawing, a text line this:
text1
text2
When I read with the catscript above text, it gives me a single string with two lines.
I would like to make from this string with two lines, two separate strings that I can compare with my master array.
I was thinking that I can make from a string with two lines, two separate strings using the split function:
array = Split(text, ""vbcrlf"), using as separator the new line "vbcrlf". I do not understand why this does not work.
This is my question, probably it seems stupid, I do not know how to split a string with many lines.




 
By the way, the method that I use now is to export all the text from V5 drawing, to a text file and after that to manipulate with the excel in order to find differences with a master database. It works but it is a little bit stupid, I find the differences one time in excel and after that I need to search for the text manually in the V5 drawing :)
Now I want to do it it the other way around, to take the text from the database and manipulate it with the V5 catscript.
 
One more mention, the V5 drawing are actually V4 drawings imported into V5. This is how this multiple text with multiple line are generated. I tried to make directly in V5 a text that has many lines and I have no idea how, strange ...
 
Don't put quotes around vbcrlf...split should work.

array = Split(text, vbcrlf)
 
array = Split(text, vbcrlf) does not work :(

I attached a example drawing and this is the code that I had used:

Code:
Sub CATMain()
	Dim arrManyLines
	Set oDrwDocument = CATIA.ActiveDocument
	Set oDrwView = oDrwDocument.Sheets.Item(1).views 
	For i = 1 To oDrwView.Count
		Set CurrentView = oDrwView.Item(i)
		'Skip the background view (Title block)
		If CurrentView.Name <> "ZR" Then         
			For j = 1 To oDrwView.Item(i).Texts.Count 'Scan all the Texts of the Views
				strText = oDrwView.Item(i).Texts.Item(j).Text    
				 strTextNoSpace= replace(strText," ","")            
				 arrManyLines = Split(strTextNoSpace , vbcrlf)
				 msgbox arrManyLines(0)
			Next
		End If                
	Next
End Sub

Please, take a look and help me :)
By using this code I need to see two message box with this text: 5285VB/1M and 3397VC1-A.
What am I doing wrong?
 
 http://files.engineering.com/getfile.aspx?folder=dca400c6-a89c-41f4-8d0a-f4ad4b839bb6&file=zQuestion.CATDrawing
Salut,

Not a simple solution but is working [bigsmile] ...you have to "clean" the code of all annoying messages.

Code:
Sub CATMain()
	Dim arrManyLines
	Set oDrwDocument = CATIA.ActiveDocument
	Set oDrwView = oDrwDocument.Sheets.Item(1).views 
	For i = 1 To oDrwView.Count
		Set CurrentView = oDrwView.Item(i)
		'Skip the background view (Title block)
		If CurrentView.Name <> "ZR" Then         
			For j = 1 To oDrwView.Item(i).Texts.Count 'Scan all the Texts of the Views
				strText = oDrwView.Item(i).Texts.Item(j).Text    
                MsgBox strText
   ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''  
  ' Create temporary file 
    Dim fso : Set fso = CreateObject("Scripting.FileSystemObject")
    Dim sTemp : sTemp = fso.GetSpecialFolder(2) & "\" & fso.GetTempName
    MsgBox sTemp
       ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    ''Write in temporary file    
    Dim oFile : Set oFile = fso.CreateTextFile(sTemp, True)
    oFile.Write strText
    oFile.Close
   ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
   ''Read lines in temporary file  
    Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile(sTemp, 1)
Do Until objFile.AtEndOfStream
 strLine = objFile.ReadLine
MsgBox strLine
Loop
objFile.Close
   ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    ' Clean up
    fso.DeleteFile sTemp
    Set fso = Nothing
     Set objFSO = Nothing
			Next
		End If                
	Next
End Sub

Regards
Fernando

- Romania
- EU
 
Actually, I am happy that it is not a simple solution :)
I lost a few hours in order to find a solution and I didn't.
Thank you for your solution, it is exactly what I need.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Top