Help me not ragequit on this Altium script - Page 1
Forum section: electronics / projects

author: swglabs
author_rank: Newbie
timestamp: August 18, 2018, 06:07:41 am
content: Help me EEVfam, you're my only hope. I'm about to flip my laptop.I opened another thread recently looking for a solution to a library management issue I'm having in Altium; commenters suggested that I write a script to solve my problem, as no built-in solution exists. Given that I have a programming background, I thought it would be fairly straightforward to write, and I chose Delphiscript since Altium has lots of example scripts.I quickly found out, however, that Altium's version of a subset of Delphiscript that doesn't have many functions in the standard language.Here's my problem: I'm trying to write a function that iterates through files in a given directory. Every resource online that I can find suggests calling FindFirst(), and its implementation is very straightforward -- but it doesn't index the files!I've tried everything -- changing the working directory to the one I'm trying to iterate, printing the return value of FindFirst() (it returns 0, which means that it was successful, but the TSearchRec object doesn't store any result), etc etcAny help is appreciated, thanks yall

author: ebclr
author_rank: Super Contributor
timestamp: August 18, 2018, 08:09:44 pm
content: Check thishttp://www.delphibasics.co.uk/RTL.asp?Name=findfirst

author: swglabs
author_rank: Newbie
timestamp: August 19, 2018, 04:07:45 am
content: I appreciate the response... that was the first thing I tried, no dice

author: SlimEddie
author_rank: Newbie
timestamp: October 01, 2025, 08:44:39 am
content: Have you found solution in the end? I am facing same issue 7 years later.

author: moffy
author_rank: Super Contributor
timestamp: October 01, 2025, 09:56:48 am
content: Could it be a permissions issue? Can you run the script as admin?

author: SlimEddie
author_rank: Newbie
timestamp: October 01, 2025, 10:18:08 am
content: Solved it by coercing chat gpt, since it also suggested FindFirst as solution. What I ended up with was getting project documents via DM_LogicalDocuments since all I needed was to find schematic and pcb that don't include specific keywords in their name to automatically generate bed of nails.Here's the solution:.Code:procedure CollectProjectDesignFilesFiltered(SchOut, PcbOut: TStringList);varProj : IProject;i, count : Integer;Doc : IDocument;fullPath : WideString;extU : WideString;baseU : WideString;kindU : WideString;addStr : String;beginif (SchOut = nil) or (PcbOut = nil) then Exit;SchOut.Clear; PcbOut.Clear;Proj := GetFocusedProject;if Proj = nil thenbeginShowMessage('No focused project.');Exit;end;// Determine document count safelycount := 0;try count := Proj.DM_LogicalDocumentCount; except end;if count = 0 thenbegin// fallback: some builds expose DM_LogicalDocumentsCounttry count := Proj.DM_LogicalDocumentsCount; except end;end;for i := 0 to count - 1 dobeginDoc := nil;try Doc := Proj.DM_LogicalDocuments(i); except end;if Doc = nil then Continue;fullPath := GetDocFullPathSafe(Doc);if fullPath = '' then Continue;// prefer the document kind when availablekindU := UpperCase(GetDocKindSafe(Doc));extU := UpperCase(FileExtW(fullPath));baseU := UpperCase(FileNameNoExtW(fullPath));// --- schematic docs ---if ((kindU = 'SCH') or (extU = UpperCase('.SchDoc'))) and(Pos('COVER', baseU) = 0) and(Pos('CHANGE', baseU) = 0) thenbeginaddStr := fullPath; // implicit WideString -> StringSchOut.Add(addStr);end;// --- pcb docs ---if ((kindU = 'PCB') or (extU = UpperCase('.PcbDoc'))) and(Pos('PANEL', baseU) = 0) thenbeginaddStr := fullPath;PcbOut.Add(addStr);end;end;end;