mirror of
https://github.com/nophead/NopSCADlib.git
synced 2025-07-31 12:40:10 +02:00
The assembly module now has a big parameter to force large or small views.
This commit is contained in:
10
readme.md
10
readme.md
@@ -5174,8 +5174,12 @@ Simple tube or ring
|
|||||||
Bill Of Materials generation via echo and the ```bom.py``` script. Also handles exploded assembly views and posing. Assembly instructions can precede the module
|
Bill Of Materials generation via echo and the ```bom.py``` script. Also handles exploded assembly views and posing. Assembly instructions can precede the module
|
||||||
definition that makes the assembly.
|
definition that makes the assembly.
|
||||||
|
|
||||||
The example below shows how to define a vitamin and incorporate it into an assembly with sub-assemblies and make an exploded view. The resulting flat BOM is shown but
|
Assembly views shown in the instructions can be large or small and this is deduced by looking at the size of the printed parts involved and if any routed
|
||||||
heirachical BOMs are also generated for real projects.
|
parts are used.
|
||||||
|
This heuristic isn't always correct, so the default can be overridden by setting the ```big``` parameter of ```assembly``` to ```true``` or ```false```.
|
||||||
|
|
||||||
|
The example below shows how to define a vitamin and incorporate it into an assembly with sub-assemblies and make an exploded view.
|
||||||
|
The resulting flat BOM is shown but heirachical BOMs are also generated for real projects.
|
||||||
|
|
||||||
|
|
||||||
[utils/core/bom.scad](utils/core/bom.scad) Implementation.
|
[utils/core/bom.scad](utils/core/bom.scad) Implementation.
|
||||||
@@ -5194,7 +5198,7 @@ heirachical BOMs are also generated for real projects.
|
|||||||
### Modules
|
### Modules
|
||||||
| Module | Description |
|
| Module | Description |
|
||||||
|:--- |:--- |
|
|:--- |:--- |
|
||||||
| ```assembly(name)``` | Name an assembly that will appear on the BOM, there needs to a module named ```<name>_assembly``` to make it |
|
| ```assembly(name, big = undef)``` | Name an assembly that will appear on the BOM, there needs to a module named ```<name>_assembly``` to make it. ```big``` can force big or small assembly diagrams. |
|
||||||
| ```dxf(name)``` | Name a dxf that will appear on the BOM, there needs to a module named ```<name>_dxf``` to make it |
|
| ```dxf(name)``` | Name a dxf that will appear on the BOM, there needs to a module named ```<name>_dxf``` to make it |
|
||||||
| ```explode(d, explode_children = false, offset = [0,0,0])``` | Explode children by specified Z distance or vector ```d```, option to explode grand children |
|
| ```explode(d, explode_children = false, offset = [0,0,0])``` | Explode children by specified Z distance or vector ```d```, option to explode grand children |
|
||||||
| ```hidden()``` | Make item invisible, except on the BOM |
|
| ```hidden()``` | Make item invisible, except on the BOM |
|
||||||
|
@@ -29,6 +29,7 @@ import openscad
|
|||||||
from time import *
|
from time import *
|
||||||
from set_config import *
|
from set_config import *
|
||||||
import json
|
import json
|
||||||
|
import re
|
||||||
|
|
||||||
def find_scad_file(mname):
|
def find_scad_file(mname):
|
||||||
for filename in os.listdir(source_dir):
|
for filename in os.listdir(source_dir):
|
||||||
@@ -48,6 +49,7 @@ def find_scad_file(mname):
|
|||||||
class BOM:
|
class BOM:
|
||||||
def __init__(self, name):
|
def __init__(self, name):
|
||||||
self.name = name
|
self.name = name
|
||||||
|
self.big = None
|
||||||
self.count = 1
|
self.count = 1
|
||||||
self.vitamins = {}
|
self.vitamins = {}
|
||||||
self.printed = {}
|
self.printed = {}
|
||||||
@@ -60,6 +62,7 @@ class BOM:
|
|||||||
assemblies[ass] = self.assemblies[ass].count
|
assemblies[ass] = self.assemblies[ass].count
|
||||||
return {
|
return {
|
||||||
"name" : self.name,
|
"name" : self.name,
|
||||||
|
"big" : self.big,
|
||||||
"count" : self.count,
|
"count" : self.count,
|
||||||
"assemblies" : assemblies,
|
"assemblies" : assemblies,
|
||||||
"vitamins" : self.vitamins,
|
"vitamins" : self.vitamins,
|
||||||
@@ -80,11 +83,15 @@ class BOM:
|
|||||||
else:
|
else:
|
||||||
parts[s] = 1
|
parts[s] = 1
|
||||||
|
|
||||||
def add_assembly(self, ass):
|
def add_assembly(self, ass, args = []):
|
||||||
if ass in self.assemblies:
|
if ass in self.assemblies:
|
||||||
self.assemblies[ass].count += 1
|
self.assemblies[ass].count += 1
|
||||||
else:
|
else:
|
||||||
self.assemblies[ass] = BOM(ass)
|
bom = BOM(ass)
|
||||||
|
for arg in args:
|
||||||
|
arg = arg.replace('true', 'True').replace('false', 'False').replace('undef', 'None')
|
||||||
|
exec('bom.' + arg, locals())
|
||||||
|
self.assemblies[ass] = bom
|
||||||
|
|
||||||
def make_name(self, ass):
|
def make_name(self, ass):
|
||||||
if self.count == 1:
|
if self.count == 1:
|
||||||
@@ -161,17 +168,22 @@ def parse_bom(file = "openscad.log", name = None):
|
|||||||
main = BOM(name)
|
main = BOM(name)
|
||||||
main.ordered_assemblies = []
|
main.ordered_assemblies = []
|
||||||
stack = []
|
stack = []
|
||||||
|
prog = re.compile(r'^(.*)\((.*)\)$')
|
||||||
for line in open(file):
|
for line in open(file):
|
||||||
pos = line.find('ECHO: "~')
|
pos = line.find('ECHO: "~')
|
||||||
if pos > -1:
|
if pos > -1:
|
||||||
s = line[pos + 8 : line.rfind('"')]
|
s = line[pos + 8 : line.rfind('"')]
|
||||||
if s[-1] == '{':
|
if s[-1] == '{':
|
||||||
ass = s[:-1]
|
ass = s[:-1]
|
||||||
|
args = []
|
||||||
|
match = prog.match(ass) #look for (...)
|
||||||
|
if match:
|
||||||
|
ass = match.group(1)
|
||||||
|
args = match.group(2).split(',')
|
||||||
if stack:
|
if stack:
|
||||||
main.assemblies[stack[-1]].add_assembly(ass) #add to nested BOM
|
main.assemblies[stack[-1]].add_assembly(ass) #add to nested BOM
|
||||||
stack.append(ass)
|
stack.append(ass)
|
||||||
main.add_assembly(ass) #add to flat BOM
|
main.add_assembly(ass, args) #add to flat BOM
|
||||||
if ass in main.ordered_assemblies:
|
if ass in main.ordered_assemblies:
|
||||||
main.ordered_assemblies.remove(ass)
|
main.ordered_assemblies.remove(ass)
|
||||||
main.ordered_assemblies.insert(0, ass)
|
main.ordered_assemblies.insert(0, ass)
|
||||||
|
@@ -52,22 +52,23 @@ def bom_to_assemblies(bom_dir, bounds_map):
|
|||||||
# Decide if we need big or small assembly pictures
|
# Decide if we need big or small assembly pictures
|
||||||
#
|
#
|
||||||
for bom in flat_bom:
|
for bom in flat_bom:
|
||||||
big = False
|
if bom["big"] == None:
|
||||||
for ass in bom["assemblies"]:
|
big = False
|
||||||
for b in flat_bom:
|
for ass in bom["assemblies"]:
|
||||||
if b["name"] == ass:
|
for b in flat_bom:
|
||||||
if b["big"]:
|
if b["name"] == ass:
|
||||||
|
if b["big"]:
|
||||||
|
big = True
|
||||||
|
break
|
||||||
|
if not big:
|
||||||
|
for stl in bom["printed"]:
|
||||||
|
bounds = bounds_map[stl]
|
||||||
|
width = bounds[1][0] - bounds[0][0]
|
||||||
|
depth = bounds[1][1] - bounds[0][1]
|
||||||
|
if max(width, depth) > 80:
|
||||||
big = True
|
big = True
|
||||||
break
|
break
|
||||||
if not big:
|
bom["big"] = big or bom["routed"]
|
||||||
for stl in bom["printed"]:
|
|
||||||
bounds = bounds_map[stl]
|
|
||||||
width = bounds[1][0] - bounds[0][0]
|
|
||||||
depth = bounds[1][1] - bounds[0][1]
|
|
||||||
if max(width, depth) > 80:
|
|
||||||
big = True
|
|
||||||
break
|
|
||||||
bom["big"] = big or bom["routed"]
|
|
||||||
#
|
#
|
||||||
# Remove the main assembly if it is a shell
|
# Remove the main assembly if it is a shell
|
||||||
#
|
#
|
||||||
|
@@ -21,8 +21,12 @@
|
|||||||
//! Bill Of Materials generation via echo and the ```bom.py``` script. Also handles exploded assembly views and posing. Assembly instructions can precede the module
|
//! Bill Of Materials generation via echo and the ```bom.py``` script. Also handles exploded assembly views and posing. Assembly instructions can precede the module
|
||||||
//! definition that makes the assembly.
|
//! definition that makes the assembly.
|
||||||
//!
|
//!
|
||||||
//! The example below shows how to define a vitamin and incorporate it into an assembly with sub-assemblies and make an exploded view. The resulting flat BOM is shown but
|
//! Assembly views shown in the instructions can be large or small and this is deduced by looking at the size of the printed parts involved and if any routed
|
||||||
//! heirachical BOMs are also generated for real projects.
|
//! parts are used.
|
||||||
|
//! This heuristic isn't always correct, so the default can be overridden by setting the ```big``` parameter of ```assembly``` to ```true``` or ```false```.
|
||||||
|
//!
|
||||||
|
//! The example below shows how to define a vitamin and incorporate it into an assembly with sub-assemblies and make an exploded view.
|
||||||
|
//! The resulting flat BOM is shown but heirachical BOMs are also generated for real projects.
|
||||||
//
|
//
|
||||||
function bom_mode(n = 1) = $_bom >= n && (is_undef($on_bom) || $on_bom); //! Current BOM mode, 0 = none, 1 = printed and routed parts and assemblies, 2 includes vitamins as well
|
function bom_mode(n = 1) = $_bom >= n && (is_undef($on_bom) || $on_bom); //! Current BOM mode, 0 = none, 1 = printed and routed parts and assemblies, 2 includes vitamins as well
|
||||||
function exploded() = is_undef($exploded_parent) ? $exploded : 0; //! Returns the value of ```$exploded``` if it is defined, else ```0```
|
function exploded() = is_undef($exploded_parent) ? $exploded : 0; //! Returns the value of ```$exploded``` if it is defined, else ```0```
|
||||||
@@ -80,10 +84,11 @@ module pose_vflip(exploded = undef) //! Pose an STL or assembly for render
|
|||||||
children();
|
children();
|
||||||
|
|
||||||
|
|
||||||
module assembly(name) { //! Name an assembly that will appear on the BOM, there needs to a module named ```<name>_assembly``` to make it
|
module assembly(name, big = undef) { //! Name an assembly that will appear on the BOM, there needs to a module named ```<name>_assembly``` to make it. ```big``` can force big or small assembly diagrams.
|
||||||
if(bom_mode())
|
if(bom_mode()) {
|
||||||
echo(str("~", name, "_assembly{"));
|
args = is_undef(big) ? "" : str("(big=", big, ")");
|
||||||
|
echo(str("~", name, "_assembly", args, "{"));
|
||||||
|
}
|
||||||
no_pose()
|
no_pose()
|
||||||
if(is_undef($child_assembly))
|
if(is_undef($child_assembly))
|
||||||
let($child_assembly = true)
|
let($child_assembly = true)
|
||||||
|
Reference in New Issue
Block a user