Jump to content

Batch conversion challenge


Recommended Posts

Hi all,

Is anyone willing to help me with a small program?

It needs to convert a folder of CAD files into JGW files.

The .CAD files have 3 lines like the following, with only the 1st line different in each file.

2675170000.000,6022050000.000

125000.000

0

I need .JGW output for this example that has 6 lines as follows:

.2

0.00000000

0.00000000

-.2

2675170

6022175

The first 4 lines in the output will always be the same.

The 5th line is one-thousandth of the first value from the first line.

The 6th line is one-thousandth of the second value from the first line PLUS one-thousandth of the 2nd line (i.e. 125)

I do have AutoIt3, but am not experienced enough to do this yet. Source au3 file would be useful as an example.

Thanks in anticipation!

Link to comment
Share on other sites

HI,

Global $old = '2675170000.000,6022050000.000' & @CRLF & '125000.000' & @CRLF & '0'

MsgBox(64, "", _createNewFileStructur($old))

Func _createNewFileStructur($old)
    Local $splitted = StringSplit($old, ',')
    Local $lines = StringSplit($old, @CRLF)
    Return '.2' & @CRLF & '0.00000000' & @CRLF & '-.2' & @CRLF & _
    $splitted[1] / 1000 & @CRLF & (($splitted[2] / 1000) + ($lines[3] / 1000))
EndFunc   ;==>_createNewFileStructur

So long,

Mega

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Link to comment
Share on other sites

Hi, I think Mega missed a crucial part of your post, so I posted another set of code that I think will do the job a bit better :)

Dim $firstLineSplit
$fileHandle = FileOpen("yourFilePathHere.CAD",0)
$firstLineSplit = StringSplit(FileReadLine($fileHandle,1),",")
FileClose($fileHandle)
$fileHandle = FileOpen("newFilePathHere.JGW",2)
FileWriteLine($fileHandle,.2)
FileWriteLine($fileHandle,0.00000000)
FileWriteLine($fileHandle,0.00000000)
FileWriteLine($fileHandle,-.2)
FileWriteLine($fileHandle,0.001 * $firstLineSplit[1])
FileWriteLine($fileHandle,0.001 * $firstLineSplit[2] + 125)
FileClose($fileHandle)
Exit

Dave

Edited by Davo

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------"I don't need to know everything, I just need to know where to find it when I need it"....EinsteinAnd in our case... That's the AutoIT helpfile ;) Please read before posting!!!

Link to comment
Share on other sites

Not tested

#Include <File.au3>

Const $header = '.2' & @CRLF & '0.00000000' & @CRLF & '0.00000000' & @CRLF & '-.2'  & @CRLF

$FileList=_FileListToArray(@ScriptDir, '*.CAD',1)
If @Error=1 Then
    MsgBox (0,"","No Files Found.")
    Exit
EndIf

For $i = 1 To $FileList[0]
   ProcessFile($FileList[$i])
Next

Func ProcessFile($name)
  $text = StringSplit(FileRead($name),@CRLF,1)
  $text2 = $header
   
  $line1 = StringSplit($text[1],',')
  $line2 = $text[2]

  $text2 &= $line1[1] / 1000 & @CRLF
  $text2 &= $line1[2] / 1000 + $line2 / 1000

  $name_out = StringReplace($name, '.CAD','.JGW')
  FileWrite($name_out, $text2)
EndFunc
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...