FreeCAD Module Part List Generator: Difference between revisions

From Open Source Ecology
Jump to navigation Jump to search
(→‎Work in Progress: fixed link)
(Added List_All_Objects macro file)
 
(One intermediate revision by the same user not shown)
Line 6: Line 6:


=Work in Progress=
=Work in Progress=
Developing a script based off of [[https://wiki.freecadweb.org/Macro_Dump_Objects Macro Dump Objects Script]]
Developing a script based off of [https://wiki.freecadweb.org/Macro_Dump_Objects Macro Dump Objects Script]
 
[[File:List All Objects.FCMacro.zip]]
 
==List all objects==
Use the code listed at [https://wiki.freecadweb.org/Code_snippets FreeCAD Code Snippets] to simply list the objects and manipulate the labels to remove part totals.
 
<pre>
List all objects
# -*- coding: utf-8 -*-
import FreeCAD,Draft
# List all objects of the document
doc = FreeCAD.ActiveDocument
objs = FreeCAD.ActiveDocument.Objects
#App.Console.PrintMessage(str(objs) + "\n")
#App.Console.PrintMessage(str(len(FreeCAD.ActiveDocument.Objects)) + " Objects"  + "\n")
 
for obj in objs:
    a = obj.Name                                            # list the Name  of the object  (not modifiable)
    b = obj.Label                                            # list the Label of the object  (modifiable)
    try:
        c = obj.LabelText                                    # list the LabeText of the text (modifiable)
        App.Console.PrintMessage(str(a) +" "+ str(b) +" "+ str(c) + "\n") # Displays the Name the Label and the text
    except:
        App.Console.PrintMessage(str(a) +" "+ str(b) + "\n") # Displays the Name and the Label of the object
 
#doc.removeObject("Box") # Clears the designated object
</pre>

Latest revision as of 00:36, 15 February 2021

Goal

Create a macro that generates a parts list from the object list labels in a module file. Also, separate the module objects into individual, separate FCStd files with unique names based on the object list labels. This automation will significantly speed up the generation of module parts lists such as for File:8footwall.FCStd

Estimated Time Savings

Modules with a dozen parts might take 1-2 hours to separate into parts gallery and associated FCStd files on the wiki. With a macro to generate the parts, this time could be reduced by nearly half.

Work in Progress

Developing a script based off of Macro Dump Objects Script

File:List All Objects.FCMacro.zip

List all objects

Use the code listed at FreeCAD Code Snippets to simply list the objects and manipulate the labels to remove part totals.

List all objects
# -*- coding: utf-8 -*-
import FreeCAD,Draft
# List all objects of the document
doc = FreeCAD.ActiveDocument
objs = FreeCAD.ActiveDocument.Objects
#App.Console.PrintMessage(str(objs) + "\n")
#App.Console.PrintMessage(str(len(FreeCAD.ActiveDocument.Objects)) + " Objects"  + "\n")

for obj in objs:
    a = obj.Name                                             # list the Name  of the object  (not modifiable)
    b = obj.Label                                            # list the Label of the object  (modifiable)
    try:
        c = obj.LabelText                                    # list the LabeText of the text (modifiable)
        App.Console.PrintMessage(str(a) +" "+ str(b) +" "+ str(c) + "\n") # Displays the Name the Label and the text
    except:
        App.Console.PrintMessage(str(a) +" "+ str(b) + "\n") # Displays the Name and the Label of the object

#doc.removeObject("Box") # Clears the designated object