def create_rib(dist_from_root, thickness): rootPlane = rootSketch.referencePlane tipPlane = tipSketch.referencePlane # Create 2 construction planes: # 1) offset from root sketch plane # 2) offset from the first planes = ribs.constructionPlanes plane1Input = planes.createInput() plane1Input.setByOffset(rootPlane, ValueInput.createByString(dist_from_root)) plane1 = planes.add(plane1Input) plane2Input = planes.createInput() plane2Input.setByOffset(plane1, ValueInput.createByString(thickness)) plane2 = planes.add(plane2Input) # Create rib as using boundary fill, between the 2 construction planes, and the wing body boundaryFills = ribs.features.boundaryFillFeatures tools = ObjectCollection.create() tools.add(wingBody) tools.add(plane1) tools.add(plane2) boundaryFillInput = boundaryFills.createInput( tools, FeatureOperations.NewBodyFeatureOperation) try: # Boundary fill will be created in sub component boundaryFillInput.creationOccurrence = ribsOcc # Specify which cell is kept assert boundaryFillInput.bRepCells.count == 3, "expected 3 cells" # volumes = [cell.cellBody.volume for cell in boundaryFillInput.bRepCells] # log('Volumes: {}'.format(volumes)) cell = cell_in_the_middle(boundaryFillInput.bRepCells) cell.isSelected = True # Create the boundary fill, based on the input data object boundaryFills.add(boundaryFillInput) except: # rollback the boundary fill transaction boundaryFillInput.cancel() raise
def _get_param(self, input_, name, comment, save=True): all_parameters = self.app.activeProduct.allParameters user_parameters = self.app.activeProduct.userParameters formula = 'abs({})' param = all_parameters.itemByName(getattr(input_, 'expression', '')) value = abs(input_.value) if param: expression = formula.format(param.name) else: if self.parametric and save: expression = user_parameters.add( self._name(name), vi.createByString( formula.format( getattr(input_, 'expression', input_.value))), getattr(input_, 'unitType', ''), 'TabGen: {}'.format(comment)).name elif save: expression = formula.format( getattr(input_, 'expression', input_.value)) else: expression = formula.format( getattr(input_, 'expression', self._name(name))) return Property(self._name(name), value, expression, comment, getattr(input_, 'unitType', ''))
def set_param(self, dim: Dim): curVal = self.user_params.itemByName(dim.dist_label) if curVal: curVal.expression = "{} mm".format(dim.dist) return curVal else: val = ValueInput.createByString("{} mm".format(dim.dist)) return self.user_params.add(dim.dist_label, val, "mm", "")
def create_spar_from_line(component, component_occurrence, wing_body, spar_lines_sketch, line, spar_width): log(line) start_point = spar_lines_sketch.sketchToModelSpace( line.startSketchPoint.geometry) end_point = spar_lines_sketch.sketchToModelSpace( line.endSketchPoint.geometry) log(start_point, end_point) # create construction plane, centered on line, at 90 degrees to horizontal plan planes = component.constructionPlanes plane_input = planes.createInput() angle = ValueInput.createByString('90.0 deg') plane_input.setByAngle(line, angle, horizontal_plane(component)) center_plane = planes.add(plane_input) # create offset planes one either side of the center plane plane_input = planes.createInput() offset = ValueInput.createByReal(spar_width / 2) plane_input.setByOffset(center_plane, offset) plane1 = planes.add(plane_input) plane_input = planes.createInput() offset = ValueInput.createByReal(-1 * spar_width / 2) plane_input.setByOffset(center_plane, offset) plane2 = planes.add(plane_input) for p in [center_plane, plane1, plane2]: p.isLightBulbOn = False # now use boundary fill to create spar between construction planes and wing body spar = boundary_fill_between_planes(component, component_occurrence, wing_body, plane1, plane2) # now get bounding box of spar and find min an max spanwise dimensions min_point = spar.boundingBox.minPoint max_point = spar.boundingBox.maxPoint sw1 = project_coord(min_point.asArray(), SPANWISE_DIRECTION.asArray()) sw2 = project_coord(max_point.asArray(), SPANWISE_DIRECTION.asArray()) min_spanwise = min(sw1, sw2) max_spanwise = max(sw1, sw2) v1 = project_coord(min_point.asArray(), VERTICAL_UP_DIRECTION.asArray()) v2 = project_coord(max_point.asArray(), VERTICAL_UP_DIRECTION.asArray()) min_vertical = min(v1, v2) max_vertical = max(v1, v2) log("Spanwise range = {} to {}".format(min_spanwise, max_spanwise)) log("Vertical range = {} to {}".format(min_vertical, max_vertical)) # create sketch and draw circles in a row spanwise spar_face_sketch = component.sketches.add(center_plane) circle_locs = [] loc = min_spanwise + settings.SPAR_CIRCLE_SPACING_CM while loc + settings.SPAR_CIRCLE_DIAMETER_CM / 2 < max_spanwise: circle_locs.append(loc) loc = loc + settings.SPAR_CIRCLE_SPACING_CM log('Circle locs:', circle_locs) vertical_center = 0 # sketch origin seems to be centered on the body. x seems to be spanwise # TODO: formalise this, for different part orientations. Need a way to deduce sketch orientation x_offset = (max_spanwise - min_spanwise) / 2 # create circles for loc in circle_locs: spar_face_sketch.sketchCurves.sketchCircles.addByCenterRadius( Point3D.create(loc - x_offset, vertical_center, 0), settings.SPAR_CIRCLE_DIAMETER_CM / 2) profiles = ObjectCollection.create() for c in spar_face_sketch.profiles: profiles.add(c) # now extrude the circles to cut the spar extrudes = component.features.extrudeFeatures extrude_input = extrudes.createInput(profiles, FeatureOperations.CutFeatureOperation) # extrude_input.setAllExtent(ExtentDirections.SymmetricExtentDirection) distanceForCut = ValueInput.createByString( '2 cm') # some distance > we need. extrude_input.setSymmetricExtent(distanceForCut, True) extrude_input.participantBodies = [spar] extrudes.add(extrude_input) return spar