예제 #1
0
 def reconstruct_line(self, sketch_lines, curve_data, transform):
     start_point = deserialize.point3d(curve_data["start_point"])
     start_point.transformBy(transform)
     end_point = deserialize.point3d(curve_data["end_point"])
     end_point.transformBy(transform)
     line = sketch_lines.addByTwoPoints(start_point, end_point)
     self.set_uuid(line, curve_data["curve"])
     return line
예제 #2
0
 def reconstruct_arc(self, sketch_arcs, curve_data, transform):
     start_point = deserialize.point3d(curve_data["start_point"])
     start_point.transformBy(transform)
     center_point = deserialize.point3d(curve_data["center_point"])
     center_point.transformBy(transform)
     sweep_angle = curve_data["end_angle"] - curve_data["start_angle"]
     arc = sketch_arcs.addByCenterStartSweep(center_point, start_point,
                                             sweep_angle)
     self.set_uuid(arc, curve_data["curve"])
     return arc
    def __add_circle(self, sketch, sketch_uuid, pt1, radius, transform=None):
        center_point = deserialize.point3d(pt1)
        if transform is not None:
            if isinstance(transform, str):
                # Transform world coords to sketch coords
                if transform.lower() == "world":
                    center_point = sketch.modelToSketchSpace(center_point)
            elif isinstance(transform, dict):
                # For mapping Fusion exported data back correctly
                xform = deserialize.matrix3d(transform)
                sketch_transform = sketch.transform
                sketch_transform.invert()
                xform.transformBy(sketch_transform)
                center_point.transformBy(xform)

        circle = sketch.sketchCurves.sketchCircles.addByCenterRadius(
            center_point, radius)
        curve_uuid = name.set_uuid(circle)
        name.set_uuids_for_sketch(sketch)
        profile_data = serialize.sketch_profiles(sketch.profiles)
        return self.runner.return_success({
            "sketch_id": sketch_uuid,
            "sketch_name": sketch.name,
            "curve_id": curve_uuid,
            "profiles": profile_data
        })
예제 #4
0
 def reconstruct_circle(self, sketch_circles, curve_data, transform):
     center_point = deserialize.point3d(curve_data["center_point"])
     center_point.transformBy(transform)
     radius = curve_data["radius"]
     circle = sketch_circles.addByCenterRadius(center_point, radius)
     self.set_uuid(circle, curve_data["curve"])
     return circle
예제 #5
0
 def are_profile_properties_identical(self, profile, profile_data,
                                      transform):
     profile_props = profile.areaProperties(
         adsk.fusion.CalculationAccuracy.HighCalculationAccuracy)
     tolerance = 0.000001
     if not math.isclose(profile_props.area,
                         profile_data["properties"]["area"],
                         abs_tol=tolerance):
         # print("Profile area doesn't match")
         return False
     if not math.isclose(profile_props.perimeter,
                         profile_data["properties"]["perimeter"],
                         abs_tol=tolerance):
         # print("Profile perimeter doesn't match")
         return False
     centroid_point = deserialize.point3d(
         profile_data["properties"]["centroid"])
     centroid_point.transformBy(transform)
     if not math.isclose(
             profile_props.centroid.x, centroid_point.x, abs_tol=tolerance):
         # print("Centroid.x doesn't match")
         return False
     if not math.isclose(
             profile_props.centroid.y, centroid_point.y, abs_tol=tolerance):
         # print("Centroid.y doesn't match")
         return False
     if not math.isclose(
             profile_props.centroid.z, centroid_point.z, abs_tol=tolerance):
         # print("Centroid.z doesn't match")
         return False
     return True
예제 #6
0
def sketch_plane(sketch_plane_data):
    """
    Return the sketch plane to create a sketch
    Can be passed either of:
        - Construction plane axes: XY, XZ, YZ
        - BRep temp id
        - Point3d on the BRep face
    """
    app = adsk.core.Application.get()
    design = adsk.fusion.Design.cast(app.activeProduct)
    # String for brepface or construction plane
    if isinstance(sketch_plane_data, str):
        # Look for construction plane first
        construction_plane = deserialize.construction_plane(sketch_plane_data)
        if construction_plane is not None:
            return construction_plane
    elif isinstance(sketch_plane_data, dict):
        point_on_face = deserialize.point3d(sketch_plane_data)
        brep_face = face_by_point3d(point_on_face)
        if brep_face is not None:
            return brep_face
    elif isinstance(sketch_plane_data, int):
        # Now lets see if it is a brep tempid
        brep_face = face_by_id(sketch_plane_data)
        if brep_face is not None:
            return brep_face
    return None
    def __add_arc(self,
                  sketch,
                  sketch_uuid,
                  pt1,
                  pt2,
                  angle_degrees,
                  transform=None):
        start_point = deserialize.point3d(pt1)
        center_point = deserialize.point3d(pt2)
        angle_radians = math.radians(angle_degrees)
        if transform is not None:
            if isinstance(transform, str):
                # Transform world coords to sketch coords
                if transform.lower() == "world":
                    start_point = sketch.modelToSketchSpace(start_point)
                    center_point = sketch.modelToSketchSpace(center_point)
            elif isinstance(transform, dict):
                # For mapping Fusion exported data back correctly
                xform = deserialize.matrix3d(transform)
                sketch_transform = sketch.transform
                sketch_transform.invert()
                xform.transformBy(sketch_transform)
                start_point.transformBy(xform)
                center_point.transformBy(xform)

        arc = sketch.sketchCurves.sketchArcs.addByCenterStartSweep(
            center_point, start_point, angle_radians)
        end_point = serialize.point3d(arc.endSketchPoint.geometry)
        curve_uuid = name.set_uuid(arc)
        name.set_uuids_for_sketch(sketch)
        profile_data = serialize.sketch_profiles(sketch.profiles)
        if sketch.name not in self.state:
            self.__init_sketch_state(sketch.name,
                                     pt1,
                                     end_point,
                                     transform=transform)
        else:
            self.__inc_sketch_state(sketch.name,
                                    end_point,
                                    transform=transform)
        return self.runner.return_success({
            "sketch_id": sketch_uuid,
            "sketch_name": sketch.name,
            "curve_id": curve_uuid,
            "profiles": profile_data
        })
예제 #8
0
    def reconstruct_sketch_ellipse(self, sketch_ellipses, curve_data,
                                   curve_uuid, points_data, transform):
        # Ellipse reconstruction requires us to provide 3 points:
        # - Center point
        # - Major axis point
        # - (Minor axis) point that the ellipse will pass through

        # Center point
        center_point_uuid = curve_data["center_point"]
        center_point = deserialize.point3d(points_data[center_point_uuid])
        center_point_vector = center_point.asVector()

        # Major axis point
        # Take the vector for the major axis
        # then normalize it
        # then scale it to the radius of the major axis
        # and offset by the center point
        major_axis = deserialize.vector3d(curve_data["major_axis"])
        major_axis_radius = curve_data["major_axis_radius"]
        major_axis.normalize()
        major_axis_vector = major_axis.copy()
        major_axis_vector.scaleBy(major_axis_radius)
        major_axis_point = major_axis_vector.asPoint()
        major_axis_point.translateBy(center_point_vector)

        # Minor axis point
        # Rotate 90 deg around z from the major axis
        # then scale and offset by the center point
        minor_axis_radius = curve_data["minor_axis_radius"]
        rot_matrix = adsk.core.Matrix3D.create()
        origin = adsk.core.Point3D.create()
        axis = adsk.core.Vector3D.create(0.0, 0.0, 1.0)
        rot_matrix.setToRotation(math.radians(90), axis, origin)
        minor_axis = major_axis.copy()
        minor_axis.transformBy(rot_matrix)
        minor_axis_vector = minor_axis.copy()
        minor_axis_vector.scaleBy(minor_axis_radius)
        minor_axis_point = minor_axis_vector.asPoint()
        minor_axis_point.translateBy(center_point_vector)

        # Finally apply the sketch alignment matrix
        major_axis_point.transformBy(transform)
        minor_axis_point.transformBy(transform)
        center_point.transformBy(transform)

        ellipse = sketch_ellipses.add(center_point, major_axis_point,
                                      minor_axis_point)
        self.set_uuid(ellipse, curve_uuid)
        return ellipse
    def __add_line(self, sketch, sketch_uuid, pt1, pt2, transform=None):
        start_point = deserialize.point3d(pt1)
        end_point = deserialize.point3d(pt2)
        if transform is not None:
            if isinstance(transform, str):
                # Transform world coords to sketch coords
                if transform.lower() == "world":
                    start_point = sketch.modelToSketchSpace(start_point)
                    end_point = sketch.modelToSketchSpace(end_point)
            elif isinstance(transform, dict):
                # For mapping Fusion exported data back correctly
                xform = deserialize.matrix3d(transform)
                sketch_transform = sketch.transform
                sketch_transform.invert()
                xform.transformBy(sketch_transform)
                start_point.transformBy(xform)
                end_point.transformBy(xform)

        line = sketch.sketchCurves.sketchLines.addByTwoPoints(
            start_point, end_point)
        curve_uuid = name.set_uuid(line)
        name.set_uuids_for_sketch(sketch)
        profile_data = serialize.sketch_profiles(sketch.profiles)
        if sketch.name not in self.state:
            self.__init_sketch_state(sketch.name,
                                     pt1,
                                     pt2,
                                     transform=transform)
        else:
            self.__inc_sketch_state(sketch.name, pt2, transform=transform)
        return self.runner.return_success({
            "sketch_id": sketch_uuid,
            "sketch_name": sketch.name,
            "curve_id": curve_uuid,
            "profiles": profile_data
        })