Macro merge duplicate materials/it: Difference between revisions

From FreeCAD Documentation
(Created page with "Macro Unisci i materiali duplicati")
 
(Created page with "Icona barra strumenti")
 
(17 intermediate revisions by 3 users not shown)
Line 1: Line 1:
<languages/>
{{Macro|Icon=Text-x-python|Name=Macro merge duplicate materials|Description=Merges materials that have the same base name|Author=yorik|Version=1.0}}

{{Macro/it
|Name=Macro merge duplicate materials
|Translate=Unisci materiali duplicati
|Icon=Macro_merge_duplicate_materials.png
|Description=Unisce i materiali che hanno lo stesso nome di base
|Author=yorik
|Version=2.0
|Date=20197-07-12
|FCVersion=All
|Download=[https://www.freecadweb.org/wiki/images/e/ed/Macro_merge_duplicate_materials.png ToolBar Icon]
}}

==Descrizione==

Fonde i materiali che hanno lo stesso nome di base (con differenti terminazioni numerali come 001, 002, ...) in uno solo. Viene mantenuto solo il primo, e tutti gli oggetti che puntano ai duplicati sono invece indirizzati al primo. Quindi, prima di utilizzare questa macro, assicurarsi che il primo materiale sia quello giusto (sia quello senza finale numerico o con il numero più basso presente).

==Script==


Icona barra strumenti
===Description===
[[Image:Macro_merge_duplicate_materials.png]]


'''Merge duplicate materials.FCMacro'''
Merges materials that have the same base name (with different numeral endings like 001, 002,...) into one. Only the first one will be kept, and all the objects that link to the duplicates will be linking to the first one instead. So before using this macro, make sure your first material (either the one without numerical ending or the lowest number found) is the right one.


{{MacroCode|code=
===Script===
Merge duplicate materials.FCMacro
{{Code|code=
import FreeCAD,FreeCADGui
import FreeCAD,FreeCADGui
mats = [o for o in FreeCAD.ActiveDocument.Objects if o.isDerivedFrom("App::MaterialObject")]
mats = [o for o in FreeCAD.ActiveDocument.Objects if o.isDerivedFrom("App::MaterialObject")]
Line 22: Line 39:
for prop in par.PropertiesList:
for prop in par.PropertiesList:
if getattr(par,prop) == mat:
if getattr(par,prop) == mat:
print "Changed property '"+prop+"' of object "+par.Label+" from "+mat.Label+" to "+orig.Label
print( "Changed property '"+prop+"' of object "+par.Label+" from "+mat.Label+" to "+orig.Label)
setattr(par,prop,orig)
setattr(par,prop,orig)
todelete.append(mat)
todelete.append(mat)
for tod in todelete:
for tod in todelete:
if not tod.InList:
if not tod.InList:
print "Deleting material "+tod.Label
print( "Deleting material "+tod.Label)
FreeCAD.ActiveDocument.removeObject(tod.Name)
FreeCAD.ActiveDocument.removeObject(tod.Name)
elif (len(tod.InList) == 1) and (tod.InList[0].isDerivedFrom("App::DocumentObjectGroup")):
elif (len(tod.InList) == 1) and (tod.InList[0].isDerivedFrom("App::DocumentObjectGroup")):
print "Deleting material "+tod.Label
print( "Deleting material "+tod.Label)
FreeCAD.ActiveDocument.removeObject(tod.Name)
FreeCAD.ActiveDocument.removeObject(tod.Name)
else:
else:
print "Unable to delete material "+tod.Label+": InList not empty"
print( "Unable to delete material "+tod.Label+": InList not empty")

}}
}}
{{clear}}
{{clear}}
<languages/>

Latest revision as of 18:24, 16 September 2022

Other languages:

Unisci materiali duplicati

Descrizione
Unisce i materiali che hanno lo stesso nome di base

Versione macro: 2.0
Ultima modifica: 20197-07-12
Versione FreeCAD: All
Download: ToolBar Icon
Autore: yorik
Autore
yorik
Download
ToolBar Icon
Link
Versione macro
2.0
Data ultima modifica
20197-07-12
Versioni di FreeCAD
All
Scorciatoia
Nessuna
Vedere anche
Nessuno

Descrizione

Fonde i materiali che hanno lo stesso nome di base (con differenti terminazioni numerali come 001, 002, ...) in uno solo. Viene mantenuto solo il primo, e tutti gli oggetti che puntano ai duplicati sono invece indirizzati al primo. Quindi, prima di utilizzare questa macro, assicurarsi che il primo materiale sia quello giusto (sia quello senza finale numerico o con il numero più basso presente).

Script

Icona barra strumenti

Merge duplicate materials.FCMacro

import FreeCAD,FreeCADGui
mats = [o for o in FreeCAD.ActiveDocument.Objects if o.isDerivedFrom("App::MaterialObject")]
todelete = []
for mat in mats:
    if mat.Label[-1].isdigit() and mat.Label[-2].isdigit() and mat.Label[-3].isdigit():
        orig = None
        for om in mats:
            if om.Label == mat.Label[:-3].strip():
                orig = om
                break
        if orig:
            for par in mat.InList:
                for prop in par.PropertiesList:
                    if getattr(par,prop) == mat:
                        print( "Changed property '"+prop+"' of object "+par.Label+" from "+mat.Label+" to "+orig.Label)
                        setattr(par,prop,orig)
            todelete.append(mat)
for tod in todelete:
    if not tod.InList:
        print( "Deleting material "+tod.Label)
        FreeCAD.ActiveDocument.removeObject(tod.Name)
    elif (len(tod.InList) == 1) and (tod.InList[0].isDerivedFrom("App::DocumentObjectGroup")):
        print( "Deleting material "+tod.Label)
        FreeCAD.ActiveDocument.removeObject(tod.Name)
    else:
        print( "Unable to delete material "+tod.Label+": InList not empty")