Jump to content
Stacker

Parse cad text file

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

 

Share this post


Link to post
Share on other sites

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 Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
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 (2018-12-03 - Version 1.4.11.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2019-03-02 - Version 1.3.5.0) - Download - General Help & Support - Example Scripts - Wiki
Outlook Tools (2019-01-22 - Version 0.1.0.0) - Download - General Help & Support
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites

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 Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

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 Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

I try your code, work great but i have to ask 2 things.

the first is: you set array $data to [100][3] but if i don't know the dimension of row " [100] "

another things is possible to have prompt to select the file

thxs so much

Share this post


Link to post
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

×
×
  • Create New...