Community Tip - Have a PTC product question you need answered fast? Chances are someone has asked it before. Learn about the community search. X
This will be my first script in ACL and I am having struggle finding examples that can be used to understand the language with respect to accessing the filesystem and performing processes on files.
No matter what I do - the below code I created and execute multiple times appears to perform different behaviors. Sometimes it has performed a replace on the Currently Open Document in arbortext, sometimes it does nothing, and sometimes it presents a message saying "0 new objects scanned and processed." but have gotten to the point where I know how to create ACL code which won't produce errors. Its just not doing what I think it should.
In my example the ultimate goal will be to replace all Unicode characters (en dash, em dash, curly quotes) with ascii characters (hyphen, straight quotes).
$EnDashChr = chr(8211)
$EmDashChr = chr(8212)
$LeftDoubleCurlyQuote = chr(8220)
$RightDoubleCurlyQuote = chr(8221)
$filepath = "C:\\Users\\MyDirectory\\Desktop\\TestXML.xml"
$isAccess = access($filepath, "rw")
if ($isAccess = true) {
message "RW Access TRUE For: $filepath"
$documentID = doc_open($filepath, 0x80000)
$currentDocID = current_doc($documentID)
$isEnDashFound = find($EnDashChr, $currentDocID)
$isEnDashReplaced = replace($EnDashChr, chr(45), 0x2000, $currentDocID)
$isEmDashReplaced = replace($EmDashChr, chr(45), 0x2000, $currentDocID)
message "[DocID: $currentDocID, EnDashFound: $isEnDashFound, EnDashReplaced: $isReplaced]"
doc_save($currentDocID)
doc_close($currentDocID)
} else {
message "RW Access FALSE for: $filepath"
}
The way its structured above is to ultimately run a loop on a directory full of xml file paths to batch process.
My question is: What is the correct code flow to perform string manipulation on a file provided a filepath. Am I using the right functions doc_open, doc_save, doc_close to programmatically perform string manipulation on files?
Also, i don't see anywhere in the documentation how to "ignore" optional values in a built in functions parameters.
Example: this is replace() in the documentation
Solved! Go to Solution.
The following ACL code works as I'd expect. It replaces instances of "ZZ" with "ZX" in the file at c:\src\test\test1.xml. I just used a blank string to skip the "element" parameter of replace().
$dd = doc_open('c:/src/test/test1.xml')
replace('ZZ', 'ZX', 0x2000, '', $dd)
doc_save($dd)
doc_close($dd)
The following ACL code works as I'd expect. It replaces instances of "ZZ" with "ZX" in the file at c:\src\test\test1.xml. I just used a blank string to skip the "element" parameter of replace().
$dd = doc_open('c:/src/test/test1.xml')
replace('ZZ', 'ZX', 0x2000, '', $dd)
doc_save($dd)
doc_close($dd)
Thank you, this was a perfect example to get me on the right track!
Wonderful! Glad to have helped 🙂