def __init__(self, obj, solids): """ Creates a new ship on active document. @param obj Part::FeaturePython created object. @param faces Ship solids components. """ # Add uniqueness property to identify Ship instances obj.addProperty( "App::PropertyBool", "IsShip", "Ship", str(Translator.translate( "True if is a valid ship instance"))).IsShip = True # Add main dimensions obj.addProperty( "App::PropertyLength", "Length", "Ship", str(Translator.translate("Ship length (Lpp) [m]"))).Length = 0.0 obj.addProperty( "App::PropertyLength", "Beam", "Ship", str(Translator.translate("Ship beam (B) [m]"))).Beam = 0.0 obj.addProperty( "App::PropertyLength", "Draft", "Ship", str(Translator.translate("Ship draft (T) [m]"))).Draft = 0.0 # Add shapes obj.Shape = Part.makeCompound(solids) obj.addProperty("Part::PropertyPartShape", "ExternalFaces", "Ship", str(Translator.translate("Ship only external faces"))) obj.Proxy = self
def __init__(self, obj, solids): """ Creates a new ship on active document. @param obj Part::FeaturePython created object. @param faces Ship solids components. """ # Add uniqueness property to identify Ship instances obj.addProperty("App::PropertyBool","IsShip","Ship", str(Translator.translate("True if is a valid ship instance"))).IsShip=True # Add main dimensions obj.addProperty("App::PropertyLength","Length","Ship", str(Translator.translate("Ship length (Lpp) [m]"))).Length=0.0 obj.addProperty("App::PropertyLength","Beam","Ship", str(Translator.translate("Ship beam (B) [m]"))).Beam=0.0 obj.addProperty("App::PropertyLength","Draft","Ship", str(Translator.translate("Ship draft (T) [m]"))).Draft=0.0 # Add shapes obj.Shape = Part.makeCompound(solids) obj.addProperty("Part::PropertyPartShape","ExternalFaces","Ship", str(Translator.translate("Ship only external faces"))) obj.Proxy = self
def execute(self, fp): """ Called when a recomputation is needed. @param fp Part::FeaturePython object. """ fp.Shape = Part.makeCompound(fp.Shape.Solids)
def SUBD_TO_NURBS(): import bpy, sys sys.path.append( bpy.path.abspath(bpy.context.scene.FreeCadBlender_props.fc_dir)) ex_dir = bpy.path.abspath(bpy.context.scene.FreeCadBlender_props.ex_dir) fname = bpy.context.scene.FreeCadBlender_props.fname import FreeCAD as F from FreeCAD import Part F.newDocument("freecad_temp") F.setActiveDocument('freecad_temp') import bpy, bmesh bpy.ops.object.editmode_toggle() bpy.ops.object.editmode_toggle() obj = bpy.context.edit_object me = obj.data bm = bmesh.from_edit_mesh(me) patches = [] stored = set() def get_verts(vert): verts = set() for e in vert.link_edges: for v in e.verts: verts.add(v) return verts count = 0 for f in bm.faces: bpy.ops.mesh.select_all(action='DESELECT') if f not in stored: print('PATCH:', count) count += 1 bsplines = [] f.select = True bpy.ops.mesh.select_linked(delimit={'SEAM'}) Fgroup = set([f for f in bm.faces if f.select]) Vgroup = set([v for v in bm.verts if v.select]) corners = set() borders = set() centers = set() for v in Vgroup: linkedVerts = get_verts(v) links = len(set(Vgroup) & linkedVerts) if links == 3: corners.add(v) elif links == 4: borders.add(v) else: centers.add(v) for b in borders: linkedVerts = get_verts(b) op = [v for v in linkedVerts if v in corners] triad = [op[0], b, op[1]] bsplines.append(triad) for f in bm.faces: if f.select: stored.add(f) s1 = bsplines.pop() c1 = s1[0] c2, c3 = None, None bspline_ord = [s1] print(s1) for s in bsplines: for v in s: if v == c1: bspline_ord.append(s) print(s) if s[0] == c1: c2 = s[2] elif s[2] == c1: c2 = s[0] break for s in bsplines: if s not in bspline_ord: for v in s: if v == c2 and s not in bspline_ord: bspline_ord.append(s) print(s) break break for s in bsplines: if s not in bspline_ord: print(s) bspline_ord.append(s) patches.append(bspline_ord) #patches.append(bsplines) for p in patches: curves = [] item = 0 for b in p: Points = [] Points.append(F.Vector(b[0].co.x, b[0].co.y, b[0].co.z)) Points.append(F.Vector(b[1].co.x, b[1].co.y, b[1].co.z)) Points.append(F.Vector(b[2].co.x, b[2].co.y, b[2].co.z)) curve = Part.BSplineCurve() curve.increaseDegree(1) curve.interpolate(Points) curves.append(curve) com = Part.makeCompound([x.toShape() for x in curves]) com_obj = F.ActiveDocument.addObject('Part::Feature', 'boundary_edges%s' % item) com_obj.Shape = com F.ActiveDocument.recompute() edge_names = ["Edge%d" % (n + 1) for n in range(len(com.Edges))] #edge_names = [n.name for n in com.Edges] patch = F.ActiveDocument.addObject("Surface::Filling", "Surface%s" % item) patch.BoundaryEdges = (com_obj, edge_names) F.ActiveDocument.recompute() item += 1 F.ActiveDocument.recompute() SURFS = [] for obj in F.ActiveDocument.Objects: if 'Surface' in obj.Name: SURFS.append(obj) if 'boundary' in obj.Name: F.ActiveDocument.removeObject(obj.Name) F.activeDocument().addObject("Part::Compound", "Compound") F.activeDocument().Compound.Links = SURFS F.ActiveDocument.recompute() print(ex_dir + fname + '.step') ex_dir = ex_dir + fname + '.step' F.ActiveDocument.getObject("Compound").Shape.exportStep(ex_dir) F.closeDocument("freecad_temp")