def __init__(self, bface, params=None, pface=None): design = Design.cast(app.activeProduct) self._ui = ui self.__bface = bface self.__evaluator = bface.geometry.evaluator pRange = self.evaluator.parametricRange() self.__xlen = pRange.maxPoint.x - pRange.minPoint.x self.__ylen = pRange.maxPoint.y - pRange.minPoint.y self.__vertices = [ bface.vertices.item(j).geometry for j in range(bface.vertices.count) ] self.__width = min(self.__xlen, self.__ylen) self.__length = max(self.__xlen, self.__ylen) self.__tab_params = params self.__xy = False self.__xz = False self.__yz = False self._timeline = design.timeline self._edges = [ self.body.edges.item(j) for j in range(0, self.body.edges.count) ]
def run(context): global ui try: app = Application.get() des = Design.cast(app.activeProduct) ui = app.userInterface log('--------------------------------') log(dt.datetime.now(), __file__) log() root = Component.cast(des.rootComponent) # locate the spars sketch & wing body sketch = item_by_name(root.sketches, settings.SPARS_SKETCH) wing_body = item_by_name(root.bRepBodies, settings.WING_BODY) # create new component component_occurrence = root.occurrences.addNewComponent( Matrix3D.create()) component = Component.cast(component_occurrence.component) component.name = settings.SPARS_COMPONENT_NAME # now create the spars, one for each line on the sketch. lines = sketch.sketchCurves.sketchLines log('num lines:', lines.count) for i, line in enumerate(lines): spar = create_spar_from_line(component, component_occurrence, wing_body, sketch, line, settings.SPAR_THICKNESS_CM) spar.name = "spar_{}".format(i + 1) log('Created spar', spar.name) ui.messageBox('done') except Exception as ex: msg = 'Failed:\n{}'.format(traceback.format_exc()) log(msg) if ui: ui.messageBox(str(ex))
def __init__(self, prefix, name, expression, units='cm', favorite=False, comment=''): des = Design.cast(app.activeProduct) self.user_params = des.userParameters self.prefix = prefix if isinstance(prefix, str) else str(prefix) self._expression = expression.format(prefix) if isinstance( expression, str) else expression self._name = name if isinstance(name, str) else str(name) self._units = units if isinstance(units, str) else '' self._comment = comment self._favorite = favorite self._param = self.user_params.itemByName(self.name) if not (self._param): self._param = self.create()
def run(context): try: # Fusion data global app, ui app = core.Application.get() ui = app.userInterface product = app.activeProduct design = Design.cast(product) if not design: ui.messageBox( 'This is not supported in the current workspace, please change to Design and try again.' ) return # Data protection document = design.parentDocument if not document.isSaved: ui.messageBox( 'This is not supported for unsaved documents, please save and try again.' ) return if document.isModified: document.save('Auto save because of RunSimulations.py') # Logging data home_folder = os.path.expanduser('~') filepath = os.path.join(home_folder, "Desktop", "CollisionDetection.csv") rootComp = design.rootComponent results = checkAssemblyForInterference(rootComp) logInterferenceData(filepath, results) except: if ui: ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
from adsk.core import Application, Matrix3D, ValueInput, Point3D, ObjectCollection from adsk.fusion import Design, Component, FeatureOperations from .f360lib.orientation import VERTICAL_UP_DIRECTION, SPANWISE_DIRECTION from .f360lib.utils import boundary_fill_between_planes, project_coord, load_settings, item_by_name from .f360lib.utils import log_func """ Creates 3DLabprint-like spars on a wing solid. Inputs: name of wing body sketch - assumed solid at this stage - use shell-tool on it later if required name of spars sketch """ app = Application.get() design = Design.cast(app.activeProduct) ui = app.userInterface settings = load_settings(design.userParameters, 'ribSettings', ui) log = partial(log_func, settings.LOGFILE) def horizontal_plane(component): return component.xYConstructionPlane 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(
def run(context): global ui try: log('--------------------------------') log(dt.datetime.now(), __file__) log() app = Application.get() des = Design.cast(app.activeProduct) ui = app.userInterface root = Component.cast(des.rootComponent) # locate the root and tip sketches rootSketch = root.sketches.itemByName(ROOT_SKETCH) if rootSketch is None: raise ValueError('Root sketch "{}" not found'.format(ROOT_SKETCH)) tipSketch = root.sketches.itemByName(TIP_SKETCH) if tipSketch is None: raise ValueError('Tip sketch "{}" not found'.format(TIP_SKETCH)) # locate the wing body wingBody = root.bRepBodies.itemByName(WING_BODY) if wingBody is None: raise ValueError('Wing body "{}" not found'.format(WING_BODY)) # create new component = 'ribs' ribsOcc = root.occurrences.addNewComponent(Matrix3D.create()) ribs = Component.cast(ribsOcc.component) ribs.name = 'ribs' 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 # end of create_rib # ---------------------------------- # now create the ribs for rs in RIB_STATIONS: create_rib('{} mm'.format(rs), RIB_THICKNESS) except: msg = 'Failed:\n{}'.format(traceback.format_exc()) log(msg) if ui: ui.messageBox(msg)