Stacker

Parse cad text file

10 posts in this topic

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



For moment only this

Can you explain me how ?

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 (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

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


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

Thank you jos.

now i'm at work. When i have one moment i try your code

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 :)

 


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          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

File open dialog SOLVED :)

 

Share this post


Link to post
Share on other sites

Solved

i Redim array by $cnt at the end......

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