Jump to content

Parse cad text file


Stacker
 Share

Recommended Posts

Hi all,
i'm new


i have cad file like this:
......

# *** COMPONENTS ***
C00 CAP233   'Code
C01 1206         'Size
C02 1uF 10% 50V SMD 1206 X7R    'Description
#
C00 CAP32
C01 0805
C02 330nF 20% 50V SMD 0805 Y5V

So i need to search for "# *** COMPONENTS ***"  then read C00/C01/C02 and put  in array like  a[0][0] = C00, a[0][1]=C01 a[0][2] = C02.

Read file not to EOF but when string # *** REFERENCEPOINTS *** occur

next step is to organize data and write new file ( but is next step)   :)

 

Thx all for suggestions

 

Link to comment
Share on other sites

  • Developers

Welcome: That shouldn't be too hard.  :)
Anything you already tried that you have question about?

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

What to do depends on the filesize.
For smaller files I suggest you have a look at FileReadToArray. Then loop through the resulting array.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

  • Developers

Here is a very basic script to get you going:

#include <array.au3>
$fh = FileOpen("test.txt")
$FndData = False
$Cnt = 0
Global $Data[100][3]

While 1
    $rec = FileReadLine($fh)
    If @error Then ExitLoop ; EOF encountered
    If StringInStr($rec, "# *** COMPONENTS ***") Then
        $FndData = True
    EndIf
    ; only process when start string encountered
    If $FndData Then
        If StringLeft($rec, 3) = "C00" Then
            $Cnt += 1
            $Data[$Cnt][0] = StringMid($rec, 4)
        ElseIf StringLeft($rec, 3) = "C01" Then
            $Data[$Cnt][1] = StringMid($rec, 4)
        ElseIf StringLeft($rec, 3) = "C02" Then
            $Data[$Cnt][2] = StringMid($rec, 4)
        EndIf
    EndIf
WEnd
_ArrayDisplay($Data)

 

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

  • Developers

Saw I missed the test for the end marker:

#include <array.au3>
$fh = FileOpen("test.txt")
$FndData = False
$Cnt = 0
Global $Data[100][3]

While 1
    $rec = FileReadLine($fh)
    If @error Then ExitLoop ; EOF encountered
    ; Start processing when End marker encountered
    If StringInStr($rec, "# *** COMPONENTS ***") Then
        $FndData = True
    EndIf
    ; Stop processing when End marker encountered
    If StringInStr($rec, "# *** REFERENCEPOINTS **") Then
        ExitLoop
    EndIf
    ; Only process when start string encountered
    If $FndData Then
        If StringLeft($rec, 3) = "C00" Then
            $Cnt += 1
            $Data[$Cnt][0] = StringMid($rec, 4)
        ElseIf StringLeft($rec, 3) = "C01" Then
            $Data[$Cnt][1] = StringMid($rec, 4)
        ElseIf StringLeft($rec, 3) = "C02" Then
            $Data[$Cnt][2] = StringMid($rec, 4)
        EndIf
    EndIf
WEnd
_ArrayDisplay($Data)

Enjoy,

Jos :)

 

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...