Hi AllI need help.I have a DGN file in the texts. Text format eg. 1421 1892/1, 14569, etc.These texts is very much. I need to convert these texts. I have a .txt file with texts on which I need to have texts in the DGN file. Annex sample txt file
1892/1, Jan Kowalski, Warszawa 25/1, 00-092 Warszawa, KS1K/00000121/1
Exactly my point such replying these texts.
Please Help
Hi Kamil,
at first I'd like to ask you to change the way how you post your questions. I am not sure how do it and what browser do you use, but in my browser (tested with Firefox, Edge, Chrome) it seems ugly and unreadable and it seems it breaks the page including Advanced Editor used for answering :-(
Can you share some details how you wrote the post? Did you e.g. copy-paste your text and picture from some other web page (translator or similar)? If yes, it's exactly what should never be done, it has to be cleaned through Notepad or some other simple text editor to remove all HTML content, because the editor used by Bentley is not able to do it.
Another problem is I am not sure from description if I understand your problem right: Do you want to analyze all texts in DGN model and if the same text exists in some text file, to replace DGN text by the text in file?
What help do you expect? You should specify if you are:
I am sure there are more ways how to solve your request (if I understand and describe it right), but because VBA does not offer complex tools to work with text files, my first idea is:
With regards,
Jan
Bentley Accredited Developer: iTwin Platform - AssociateLabyrinth Technology | dev.notes() | cad.point
I have a macro that reads a line of text in a txt file. And then looks for the text in the DGN file. How to find the text marks it on the selected color. As previously I wrote I have a txt file with the structure 1 Number1, name1, address1, KW1 2 Number2, name2, address2, KW2 3 Number3, name3, address3, KW3 4 Number4, name4, address4, KW4 5 Number5, name5, address5, KW5 .....e.t.c. And now this macra want to add options if the program finds in the DGN file e.g. number1 as in line txt file. This imports the rest of the line in place of the text in the DGN file.
Sub SzukajTXT() Dim TextLine As String Dim ee As ElementEnumerator Dim esc As ElementScanCriteria Set esc = New ElementScanCriteria esc.ExcludeAllLevels esc.ExcludeAllTypes esc.IncludeLevel ActiveModelReference.Levels("Default") esc.IncludeType msdElementTypeText Open "D:\test.txt" For Input As #1 Do While Not EOF(1) Line Input #1, TextLine Set ee = ActiveModelReference.Scan(esc) Do While ee.MoveNext If ee.Current.AsTextElement.Text = TextLine Then ee.Current.AsTextElement.Color = 4 ee.Current.AsTextElement.Rewrite Line Input #1, TextLine End If Loop Loop Close #1 End Sub
Please some tips and help
it's good that your post looks much better now. But if posting any code, use Syntaxhighlighter tool (yellow pencil icon) with correctly set language (VB in your case).
Unknown said:Please some tips and help
I will repeat myself: What tip do you expect? You did not write any information what is wrong, what work or not or what do you need. In such case it's hard to provide any advice :-(
I guess (but it's you responsibility, not readers!) the problem is that you read the whole line but you don't parse it. You should use e.g. Split mehtod to receive text line divided into separate chunks, where the first part is id and the rest are text line. There are plenty of similar discussions on Internet...
Another tip is "Never use nested loops." (one loop in another). It's fast way to troubles. Extract the second loop into separate method (probably more method), so the code will be cleaner. In your case, without any checking or testing, this refactorization (with very minor modifications) can be:
Public Sub MainMethod() Sub SzukajTXT() Dim TextLine As String Open "D:\test.txt" For Input As #1 Do While Not EOF(1) Line Input #1, TextLine SearchForText TextLine Loop Close #1 End Sub Private Sub SearchForText(searchedText As String) Dim esc As New ElementScanCriteria esc.ExcludeAllLevels esc.ExcludeAllTypes esc.IncludeLevel ActiveModelReference.Levels("Default") esc.IncludeType msdElementTypeText Dim ee As ElementEnumerator Set ee = ActiveModelReference.Scan(esc) Dim foundTextElement As TextElement Do While ee.MoveNext Set foundTextElement = ee.Current.AsTextElement If foundTextElement.Text = TextLine Then foundTextElement.Color = 4 foundTextElement.Rewrite End If Loop End Sub
Macro replaces the found text in dgn's one equivalent of a txt file. Everything ok just publish it in a form such as a txt file. ie
number, name, address, KW
How to make the text was converted in the form of
NumberNameAddressKW
Sub SzukajTXT() Dim TextLine As String Dim ee As ElementEnumerator Dim esc As ElementScanCriteria Dim Opis As String Set esc = New ElementScanCriteria esc.ExcludeAllLevels esc.ExcludeAllTypes esc.IncludeLevel ActiveModelReference.Levels("Default") esc.IncludeType msdElementTypeText Open "D:\test.txt" For Input As #1 Do While Not EOF(1) Line Input #1, TextLine Set ee = ActiveModelReference.Scan(esc) Do While ee.MoveNext Opis = Split(TextLine, ",")(0) If ee.Current.AsTextElement.Text = Opis Then ee.Current.AsTextElement.Text = Replace(TextLine, Opis & ",", "", 1, 1) ee.Current.AsTextElement.Rewrite End If Loop Loop Close #1 End Sub
Unknown said:How to make the text was converted in the form of..
Text element can hold one line of text only, so you have to "convert" it into TextNode element that is able to hold more text lines (and also one text line but with differently formatted text parts). The conversion means you have to delete existing text element and to create text node and add it to active model.
Be aware Text Node Element is complex element, so it's empty when it's created and you have to add text lines separately. It will probably look similar to this code:
' Create Text Node Element Dim textNodeElement As textNodeElement Set textNodeElement = CreateTextNodeElement1(Nothing, Origin, Rotation) ' Add a new line to Text Node textNodeElement.AddTextLine "New line" ' Add the element into model ActiveModelReference.AddElement textNodeElement
You will also probably have to take care about settings of text parameters. The preferred way is to define text style (in dgnlib) and to activate the text style before the text node element is created.
MDL application can text2node helped by me?Maybe someone I have and make available? In the download section no download option; /
Edit:I already found it. This application does not work the way I wanted.
Thank you for your help.Macro needs to be without conversion to text node. That I can no longer change. But anyway macro is very helpful in this form.
Unknown said:Macro needs to be without conversion to text node.
I don't understand this statement, because in such case there is a conflict between requirement (to replace text with multiline text) and conditions (to don't change text to text node). No code and no programmer can solve such situation.
An alternative can be to place text lines as separate text elements, but in my opinion it's ugly / dirty solution, because there will be no relation between texts. Maybe to use Named Groups or Graphic Groups to bind them together?