def sketch_profiles(profiles):
    data = {}
    for profile in profiles:
        if profile is not None:
            uuid = name.get_uuid(profile)
            data[uuid] = sketch_profile(profile)
    return data
 def get_regraph_uuid(self, entity):
     """Get a uuid or a tempid depending on a flag"""
     is_face = isinstance(entity, adsk.fusion.BRepFace)
     is_edge = isinstance(entity, adsk.fusion.BRepEdge)
     if self.use_temp_id and (is_face or is_edge):
         return str(entity.tempId)
     else:
         return name.get_uuid(entity)
示例#3
0
def sketch_by_id(sketch_id, sketches=None):
    """Return a sketch with a given sketch id"""
    app = adsk.core.Application.get()
    design = adsk.fusion.Design.cast(app.activeProduct)
    if sketches is None:
        sketches = design.rootComponent.sketches
    for sketch in sketches:
        uuid = name.get_uuid(sketch)
        if uuid is not None and uuid == sketch_id:
            return sketch
    return None
def sketch_profile_loop(loop):
    data = {}
    data["is_outer"] = loop.isOuter
    profile_curves = []
    for curve in loop.profileCurves:
        if curve is not None:
            curve_data = sketch_profile_curve(curve)
            curve_data["curve"] = curve_uuid = name.get_uuid(
                curve.sketchEntity)
            profile_curves.append(curve_data)
    data["profile_curves"] = profile_curves
    return data
 def add_circle(self, data):
     """Add a circle to an existing sketch"""
     if (data is None or "sketch_name" not in data or "pt" not in data
             or "radius" not in data):
         return self.runner.return_failure("add_circle data not specified")
     sketch = match.sketch_by_name(
         data["sketch_name"],
         sketches=self.design_state.reconstruction.component.sketches)
     if sketch is None:
         return self.runner.return_failure("sketch not found")
     sketch_uuid = name.get_uuid(sketch)
     transform = data["transform"] if "transform" in data else None
     return self.__add_circle(sketch, sketch_uuid, data["pt"],
                              data["radius"], transform)
示例#6
0
def sketch_profiles_by_curve_id(sketch_curve_id, sketches=None):
    """Return the sketch profiles that contain the given curve id"""
    app = adsk.core.Application.get()
    design = adsk.fusion.Design.cast(app.activeProduct)
    matches = []
    if sketches is None:
        sketches = design.rootComponent.sketches
    for sketch in sketches:
        for profile in sketch.profiles:
            for loop in profile.profileLoops:
                for curve in loop.profileCurves:
                    sketch_ent = curve.sketchEntity
                    curve_uuid = name.get_uuid(sketch_ent)
                    if curve_uuid is not None and curve_uuid == sketch_curve_id:
                        matches.append(profile)
    return matches
 def add_point(self, data):
     """Add a point to create a new sequential line in the given sketch"""
     if (data is None or "sketch_name" not in data or "pt" not in data):
         return self.runner.return_failure("add_point data not specified")
     sketch = match.sketch_by_name(
         data["sketch_name"],
         sketches=self.design_state.reconstruction.component.sketches)
     if sketch is None:
         return self.runner.return_failure("sketch not found")
     sketch_uuid = name.get_uuid(sketch)
     # If this is the first point, store it and return
     if sketch.name not in self.state:
         self.__init_sketch_state(sketch.name, data["pt"], data["pt"])
         profile_data = serialize.sketch_profiles(sketch.profiles)
         return self.runner.return_success({
             "sketch_id": sketch_uuid,
             "sketch_name": sketch.name,
             "profiles": profile_data
         })
     state = self.state[sketch.name]
     transform = data["transform"] if "transform" in data else None
     return self.__add_line(sketch, sketch_uuid, state["last_pt"],
                            data["pt"], transform)
 def close_profile(self, data):
     """Close the current set of lines to create one or more profiles
        by joining the first point to the last"""
     if data is None or "sketch_name" not in data:
         return self.runner.return_failure(
             "close_profile data not specified")
     sketch = match.sketch_by_name(
         data["sketch_name"],
         sketches=self.design_state.reconstruction.component.sketches)
     if sketch is None:
         return self.runner.return_failure("sketch not found")
     sketch_uuid = name.get_uuid(sketch)
     if sketch.name not in self.state:
         return self.runner.return_failure("sketch state not found")
     state = self.state[sketch.name]
     # We need at least 4 points (2 lines with 2 points each)
     if state["pt_count"] < 4:
         return self.runner.return_failure("sketch has too few points")
     if state["last_pt"] is None or state["first_pt"] is None:
         return self.runner.return_failure("sketch end points invalid")
     transform = state["transform"]
     return self.__add_line(sketch, sketch_uuid, state["last_pt"],
                            state["first_pt"], transform)