Assemblies reference other assemblies and parts internally; a flat
single-level copy into raw/ left Creo unable to load models ("Dati di
input non completi"). AssemblyComponentScanner heuristically extracts
component codes embedded as readable strings inside the otherwise
binary .asm files; each candidate is validated against the index (which
filters out scan noise), copied into raw/, and if it's itself an
assembly, queued for the same treatment until the whole tree resolves
to PRT leaves. PrtMancantiForm reports what was found and copied.
Also ignore Creo Distributed Batch job files (*.dxc).
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
30 lines
1.1 KiB
C#
30 lines
1.1 KiB
C#
using System.Text;
|
|
using System.Text.RegularExpressions;
|
|
|
|
namespace CadSearchGui;
|
|
|
|
/// <summary>
|
|
/// Estrae i codici componente referenziati dentro un file .asm Pro-E/Creo.
|
|
/// Il formato è per lo più binario, ma i codici dei sotto-componenti compaiono
|
|
/// come stringhe ASCII leggibili al suo interno: si scansiona il file come testo
|
|
/// cercando pattern che assomigliano a un codice (stesso stile usato nei nomi file,
|
|
/// vedi Indexer.FilenameRegex) e si lascia poi al chiamante il compito di verificarli
|
|
/// contro l'indice DB, che scarta automaticamente i falsi positivi (numeri che non
|
|
/// corrispondono a nessun codice reale).
|
|
/// </summary>
|
|
static class AssemblyComponentScanner
|
|
{
|
|
private static readonly Regex CodiceRegex = new(@"\b\d{8,12}[A-Za-z]{0,2}\b", RegexOptions.Compiled);
|
|
|
|
public static HashSet<string> EstraiCodiciReferenziati(string percorsoAsm)
|
|
{
|
|
var testo = Encoding.Latin1.GetString(File.ReadAllBytes(percorsoAsm));
|
|
var codici = new HashSet<string>();
|
|
foreach (Match m in CodiceRegex.Matches(testo))
|
|
{
|
|
codici.Add(m.Value);
|
|
}
|
|
return codici;
|
|
}
|
|
}
|