Hmmm
... Pewien... Ale bądź ostrożny, nadal są podatne.
A potem... Jest tylko jeden sposób, aby się tego dowiedzieć.

Zamierzam sprawić, że będzie to na granicy nie na temat...
Perplexity oferuje mi skrypt w Pythonie (z biblioteką ezdxf), który rzekomo byłby w stanie przekonwertować plik DXF na symbol, który może być używany z biblioteką Solidworks *.sym:
import ezdxf
# Fonction pour normaliser une valeur selon l'étendue min-max à l'intervalle [0,1]
def normalize(value, min_val, max_val):
return (value - min_val) / (max_val - min_val) if max_val > min_val else 0.0
# Fonction principale de conversion DXF -> fichier .sym
def dxf_to_sym(dxf_path, sym_path):
# Charger le fichier DXF
dwg = ezdxf.readfile(dxf_path)
msp = dwg.modelspace()
# Récupérer toutes les coordonnées (x,y) pour une normalisation correcte
coords_x = []
coords_y = []
for e in msp:
if e.dxftype() == 'LINE':
coords_x.extend([e.dxf.start.x, e.dxf.end.x])
coords_y.extend([e.dxf.start.y, e.dxf.end.y])
elif e.dxftype() in ('CIRCLE', 'ARC'):
coords_x.append(e.dxf.center.x)
coords_y.append(e.dxf.center.y)
elif e.dxftype() == 'TEXT':
coords_x.append(e.dxf.insert.x)
coords_y.append(e.dxf.insert.y)
# Définir les bornes min et max
min_x, max_x = min(coords_x), max(coords_x)
min_y, max_y = min(coords_y), max(coords_y)
with open(sym_path, 'w', encoding='utf-8') as file:
file.write(";; Bibliothèque de symboles générée automatiquement\n")
file.write("#MySymbols, Bibliothèque personnelle\n")
# Parcourir les entités pour exporter en format .sym
for e in msp:
if e.dxftype() == 'LINE':
x1 = normalize(e.dxf.start.x, min_x, max_x)
y1 = normalize(e.dxf.start.y, min_y, max_y)
x2 = normalize(e.dxf.end.x, min_x, max_x)
y2 = normalize(e.dxf.end.y, min_y, max_y)
file.write(f"*LineSymbol,Ligne simple\n")
file.write(f"A,LINE {x1:.3f},{y1:.3f},{x2:.3f},{y2:.3f}\n")
elif e.dxftype() == 'CIRCLE':
cx = normalize(e.dxf.center.x, min_x, max_x)
cy = normalize(e.dxf.center.y, min_y, max_y)
# Normalisation du rayon approximative selon largeur (ajustable)
r = e.dxf.radius / (max_x - min_x) if max_x != min_x else 0
file.write(f"*CircleSymbol,Cercle simple\n")
file.write(f"A,CIRCLE {cx:.3f},{cy:.3f},{r:.3f}\n")
elif e.dxftype() == 'ARC':
cx = normalize(e.dxf.center.x, min_x, max_x)
cy = normalize(e.dxf.center.y, min_y, max_y)
r = e.dxf.radius / (max_x - min_x) if max_x != min_x else 0
start_angle = int(e.dxf.start_angle)
end_angle = int(e.dxf.end_angle)
file.write(f"*ArcSymbol,Arc simple\n")
file.write(f"A,ARC {cx:.3f},{cy:.3f},{r:.3f},{start_angle},{end_angle}\n")
elif e.dxftype() == 'TEXT':
x = normalize(e.dxf.insert.x, min_x, max_x)
y = normalize(e.dxf.insert.y, min_y, max_y)
text = e.text.replace(',', '') # enlever virgules
file.write(f"*TextSymbol,Texte simple\n")
file.write(f"A,TEXT {x:.3f},{y:.3f},<{text}>\n")
if __name__ == "__main__":
dxf_to_sym('votre_fichier.dxf', 'symboles.sym')
Wyjaśnienia:
ezdxf charge et lit les entités 2D du fichier DXF à partir du "modelspace".
On collecte toutes les coordonnées X et Y de toutes les entités pour calculer les bornes min/max, ce qui permet de normaliser chaque coordonnée entre 0 et 1. Cette normalisation est nécessaire car SolidWorks attend des coordonnées relatives dans la grille de symbole.
On traite les types essentiels : LINE, CIRCLE, ARC, TEXT ; pour chacun, on écrit une ligne dans le format lisible par SolidWorks.
Le rayon d’un cercle ou d’un arc est normalisé aussi, approximativement selon la largeur du dessin.
Le texte est nettoyé pour éviter les virgules incompatibles.
Le fichier .sym produit peut être ajouté à la bibliothèque de SolidWorks et utilisé directement.
I na tym się zatrzymuję... do tej pory nigdy nie używałem/nie stworzyłem skryptu w Pythonie i na razie nie jestem w stanie zinterpretować ani ocenić znaczenia tego skryptu.
Co więcej, jest to " bezpośrednio od AI (Zakłopotanie) " ze wszystkimi problemami nieodłącznie związanymi z tym postulatem.
Jeśli bardziej żądny przygód niż ja chcesz przetestować ten skrypt dobrze... Dziękuję i życzę powodzenia...