コード例 #1
0
def test_create_circle(client, part_studio):
    FEATURE_NAME = "My New Circle"
    PLANE_ID = "JDC"  # The plane deterministic ID for the sketch
    plane_query = BTMParameterQueryList148(
        parameter_id="sketchPlane",
        queries=[BTMIndividualQuery138(deterministic_ids=[PLANE_ID])],
    )
    CIRCLE_ID = "myCircle"

    circle_geometry = BTCurveGeometryCircle115(
        radius=0.5, xcenter=0.0, ycenter=0.0, xdir=1.0, ydir=0.0, clockwise=False
    )
    circle = BTMSketchCurve4(
        center_id=f"{CIRCLE_ID}.center", entity_id=CIRCLE_ID, geometry=circle_geometry
    )
    sketch = BTMSketch151(
        entities=[circle], name=FEATURE_NAME, parameters=[plane_query]
    )
    feature_definition = BTFeatureDefinitionCall1406(
        feature=sketch, bt_type="BTFeatureDefinitionCall-1406"
    )
    client.part_studios_api.add_part_studio_feature(
        did=part_studio.did,
        wvm=part_studio.wvm,
        wvmid=part_studio.wvmid,
        eid=part_studio.eid,
        bt_feature_definition_call_1406=feature_definition,
        _preload_content=False,
    )
コード例 #2
0
def test_insert_line_sketch(client, part_studio):
    FEATURE_NAME = "My New Line"
    PLANE_ID = "JDC"  # The plane deterministic ID for the sketch
    plane_query = BTMParameterQueryList148(
        parameter_id="sketchPlane",
        queries=[BTMIndividualQuery138(deterministic_ids=[PLANE_ID])])
    LINE_ID = "myLine"
    START = "start"
    END = "end"
    POINT_ID = "myPoint"

    point_string_param = BTMParameterString149(
        value=POINT_ID,
        parameter_id="localFirst",
        bt_type="BTMParameterString-149")
    line_end_string_param = BTMParameterString149(
        value=f"{LINE_ID}.{START}",
        parameter_id="localSecond",
        bt_type="BTMParameterString-149")
    coincident_constraint = BTMSketchConstraint2(
        constraint_type="COINCIDENT",
        parameters=[point_string_param, line_end_string_param],
        entity_id="constrainId",
        bt_type="BTMSketchConstraint-2")
    point = BTMSketchPoint158(y=-0.071735,
                              x=-0.0564367610245,
                              entity_id=POINT_ID,
                              bt_type="BTMSketchPoint-158")
    line_geometry = BTCurveGeometryLine117(pnt_x=0.,
                                           pnt_y=0.,
                                           dir_x=0.5,
                                           dir_y=0.5,
                                           bt_type="BTCurveGeometryLine-117")
    line = BTMSketchCurveSegment155(start_point_id=f"{LINE_ID}.{START}",
                                    end_point_id=f"{LINE_ID}.{END}",
                                    start_param=0.,
                                    end_param=1.,
                                    geometry=line_geometry,
                                    entity_id=LINE_ID,
                                    bt_type="BTMSketchCurveSegment-155")
    sketch = BTMSketch151(entities=[line, point],
                          name="My New Line",
                          parameters=[plane_query],
                          constraints=[coincident_constraint],
                          bt_type="BTMSketch-151")
    feature_definition = BTFeatureDefinitionCall1406(feature=sketch)
    client.part_studios_api.add_feature1(
        did=part_studio.did,
        wvm=part_studio.wvm,
        wvmid=part_studio.wvmid,
        eid=part_studio.eid,
        bt_feature_definition_call_1406=feature_definition)
    features = client.part_studios_api.get_part_studio_features(
        did=part_studio.did,
        wvm=part_studio.wvm,
        wvmid=part_studio.wvmid,
        eid=part_studio.eid)
    assert features.features[0].name == FEATURE_NAME
コード例 #3
0
def test_insert_point_sketch(client, part_studio):
    PLANE_ID = "JDC"  # The plane deterministic ID for the sketch
    plane_query = BTMParameterQueryList148(
        parameter_id="sketchPlane",
        queries=[BTMIndividualQuery138(deterministic_ids=[PLANE_ID])])
    point = BTMSketchPoint158(y=-0.071735,
                              x=-0.0564367610245,
                              is_user_point=True,
                              is_construction=False)
    sketch = BTMSketch151(entities=[point],
                          name="My New Point",
                          parameters=[plane_query])
    feature_definition = BTFeatureDefinitionCall1406(
        feature=sketch, bt_type="BTFeatureDefinitionCall-1406")
    client.part_studios_api.add_part_studio_feature(
        did=part_studio.did,
        wvm=part_studio.wvm,
        wvmid=part_studio.wvmid,
        eid=part_studio.eid,
        bt_feature_definition_call_1406=feature_definition,
        _preload_content=False)
コード例 #4
0
element = OnshapeElement(
	'https://rogers.onshape.com/documents/b7c65d78bde731408815188e/w/09daa8ec5418b4d1e583d4b3/e/96d39b57bfcc8cca0d96c2b5'
)

key = ""
secret = ""

with open('../scripts/api-key', "r") as f: 
	key = f.readline().rstrip()
	secret = f.readline().rstrip()

base_url = 'https://rogers.onshape.com'

client = Client(configuration={"base_url": base_url, "access_key": key, "secret_key": secret})

Square0 = BTMSketch151(entities=[BTMSketchCurveSegment155(start_point="LINE1.start", end_point_id="LINE1.end", start_param=0.0, end_param=1.0, geometry=BTCurveGeometryLine117(pnt_x=0.0, pnt_y=0.0, dir_x=0.0, dir_y=0.0254, bt_type="BTCurveGeometryLine-117"), entity_id="LINE1", bt_type="BTMSketchCurveSegment-155"),BTMSketchCurveSegment155(start_point="LINE2.start", end_point_id="LINE2.end", start_param=0.0, end_param=1.0, geometry=BTCurveGeometryLine117(pnt_x=0.0, pnt_y=0.0254, dir_x=0.0254, dir_y=0.0, bt_type="BTCurveGeometryLine-117"), entity_id="LINE2", bt_type="BTMSketchCurveSegment-155"),BTMSketchCurveSegment155(start_point="LINE3.start", end_point_id="LINE3.end", start_param=0.0, end_param=1.0, geometry=BTCurveGeometryLine117(pnt_x=0.0254, pnt_y=0.0254, dir_x=0.0, dir_y=-0.0254, bt_type="BTCurveGeometryLine-117"), entity_id="LINE3", bt_type="BTMSketchCurveSegment-155"),BTMSketchCurveSegment155(start_point="LINE4.start", end_point_id="LINE4.end", start_param=0.0, end_param=1.0, geometry=BTCurveGeometryLine117(pnt_x=0.0254, pnt_y=0.0, dir_x=-0.0254, dir_y=0.0, bt_type="BTCurveGeometryLine-117"), entity_id="LINE4", bt_type="BTMSketchCurveSegment-155"),], name="Square", parameters=[BTMParameterQueryList148(parameter_id="sketchPlane", queries=[BTMIndividualQuery138(deterministic_ids=['JDC'])]),BTMParameterQuantity147(expression="1*in", parameter_id="length", bt_type="BTMParameterQuantity-147"),], constraints=[BTMSketchConstraint2(constraint_type="COINCIDENT",parameters=[BTMParameterString149(value="point1", parameter_id="localFirst", bt_type="BTMParameterString-149"),BTMParameterString149(value="'LINE1.start", parameter_id="localSecond", bt_type="BTMParameterString-149"),],entity_id="constrainId",bt_type="BTMSketchConstraint-2"),BTMSketchConstraint2(constraint_type="LENGTH",parameters=[BTMParameterString149(value="point1", parameter_id="localFirst", bt_type="BTMParameterString-149"),BTMParameterString149(value="'LINE1.start", parameter_id="localSecond", bt_type="BTMParameterString-149"),BTMParameterQuantity147(expression="1*in", parameter_id="length", bt_type="BTMParameterQuantity-147"),],entity_id="constrainId",bt_type="BTMSketchConstraint-2"),], bt_type="BTMSketch-151")

Square_Extrude1 = BTMFeature134(bt_type="BTMParameterQuantity-147", name="Square Extrude", feature_type="extrude", parameters=[BTMParameterEnum145(enum_name="ToolBodyType",value="SURFACE",parameter_id="bodyType"),BTMParameterEnum145(enum_name="OperationDomain",value="MODEL",parameter_id="domain"),BTMParameterEnum145(enum_name="SecondDirectionBoundingType",value="BLIND",parameter_id="secondDirectionBound"),BTMParameterEnum145(enum_name="BoundingType",value="BLIND",parameter_id="endBound"),BTMParameterQueryList148(parameter_id="endBoundEntityFace", queries=[]),BTMParameterQueryList148(parameter_id="endBoundEntityBody", queries=[]),BTMParameterQueryList148(parameter_id="endBoundEntityVertex", queries=[]),BTMParameterEnum145(enum_name="NewBodyOperationType",value="NEW",parameter_id="operationType"),BTMParameterEnum145(enum_name="NewSurfaceOperationType",value="NEW",parameter_id="surfaceOperationType"),BTMParameterEnum145(enum_name="FlatOperationType",value="REMOVE",parameter_id="flatOperationType"),BTMParameterQueryList148(parameter_id="surfaceEntities", queries=[BTMIndividualQuery138(deterministic_ids=['JGC'])]),BTMParameterQuantity147(expression="1*in",parameter_id="depth"),])

Circle_On_a_Face2 = BTMSketch151(entities=[BTMSketchCurve4(center_id="Circle.center", entity_id="Circle", geometry=BTCurveGeometryCircle115(radius=0.00635, xcenter=0.0127, ycenter=0.0127, xdir=0.0127, ydir=0.0, clockwise=False)),], name="Circle On a Face", parameters=[BTMParameterQueryList148(parameter_id="sketchPlane", queries=[BTMIndividualQuery138(deterministic_ids=['JGC'])]),], constraints=[], bt_type="BTMSketch-151")

Extrude_Remove_Circle3 = BTMFeature134(bt_type="BTMParameterQuantity-147", name="Extrude Remove Circle", feature_type="extrude", parameters=[BTMParameterEnum145(enum_name="OperationDomain",value="MODEL",parameter_id="domain"),BTMParameterEnum145(enum_name="ToolBodyType",value="SOLID",parameter_id="bodyType"),BTMParameterEnum145(enum_name="NewBodyOperationType",value="REMOVE",parameter_id="operationType"),BTMParameterEnum145(enum_name="BoundingType",value="BLIND",parameter_id="endBound"),BTMParameterQueryList148(parameter_id="booleanScope", queries=[BTMIndividualQuery138(deterministic_ids=['JHD'])]),BTMParameterQueryList148(parameter_id="booleanSurfaceScope", queries=[]),BTMParameterQuantity147(expression="1 in",parameter_id="offsetDistance"),BTMParameterQuantity147(expression="1 in",parameter_id="secondDirectionDepth"),BTMParameterQueryList148(parameter_id="surfaceEntities", queries=[]),BTMParameterEnum145(enum_name="NewSurfaceOperationType",value="NEW",parameter_id="surfaceOperationType"),BTMParameterEnum145(enum_name="FlatOperationType",value="REMOVE",parameter_id="flatOperationType"),BTMParameterQueryList148(parameter_id="entities", queries=[BTMIndividualQuery138(deterministic_ids=['JJC'])]),BTMParameterQuantity147(expression="1 in",parameter_id="depth"),])

def funcTester(func_string, part_studio, client):
	feature_definition = BTFeatureDefinitionCall1406(feature=func_string)
	client.part_studios_api.add_part_studio_feature(
	    did=part_studio.did,
	    wvm=part_studio.wvm,
	    wvmid=part_studio.wvmid,
	    eid=part_studio.eid,
	    bt_feature_definition_call_1406=feature_definition,
コード例 #5
0
def create_square(client, part_studio):
    FEATURE_NAME = "Square"
    PLANE_ID = "JDC"  # The plane deterministic ID for the sketch
    plane_query = BTMParameterQueryList148(
        parameter_id="sketchPlane",
        queries=[BTMIndividualQuery138(deterministic_ids=[PLANE_ID])],
    )
    LINE_ID = "myLine"
    START = "start"
    END = "end"
    POINT_ID = "myPoint"

    point_string_param = BTMParameterString149(
        value='point1', parameter_id="localFirst", bt_type="BTMParameterString-149"
    )
    point_string_param2 = BTMParameterString149(
        value='point2', parameter_id="localFirst", bt_type="BTMParameterString-149"
    )
    point_string_param3 = BTMParameterString149(
        value='point3', parameter_id="localFirst", bt_type="BTMParameterString-149"
    )
    point_string_param4 = BTMParameterString149(
        value='point4', parameter_id="localFirst", bt_type="BTMParameterString-149"
    )
    line_end_string_param = BTMParameterString149(
        value=f"LINE1.start",
        parameter_id="localSecond",
        bt_type="BTMParameterString-149",
    )
    line_end_string_param2 = BTMParameterString149(
        value=f"LINE2.start",
        parameter_id="localSecond",
        bt_type="BTMParameterString-149",
    )
    line_end_string_param3 = BTMParameterString149(
        value=f"LINE3.start",
        parameter_id="localSecond",
        bt_type="BTMParameterString-149",
    )
    line_end_string_param4 = BTMParameterString149(
        value=f"LINE4.start",
        parameter_id="localSecond",
        bt_type="BTMParameterString-149",
    )
    length = BTMParameterQuantity147(expression="1*in", parameter_id="length")
    coincident_constraint1 = BTMSketchConstraint2(
        constraint_type="COINCIDENT",
        parameters=[point_string_param, line_end_string_param],
        entity_id="constrainId",
        bt_type="BTMSketchConstraint-2",
    )
    coincident_constraint2 = BTMSketchConstraint2(
        constraint_type="LENGTH",
        parameters=[point_string_param, line_end_string_param, length],
        entity_id="constrainId",
        bt_type="BTMSketchConstraint-2",
    )
    point = BTMSketchPoint158(
        y=0.0, x=0.0, is_user_point=True, is_construction=False
    )
    point2 = BTMSketchPoint158(
        y=.0254, x=0.0, is_user_point=True, is_construction=False
    )
    point3 = BTMSketchPoint158(
        y=.0254, x=.0254, is_user_point=True, is_construction=False
    )
    point4 = BTMSketchPoint158(
        y=0.0, x=.0254, is_user_point=True, is_construction=False
    )
    line_geometry1 = BTCurveGeometryLine117(
        pnt_x=0.0, pnt_y=0.0, dir_x=0.0, dir_y=.0254, bt_type="BTCurveGeometryLine-117"
    )
    line_geometry2 = BTCurveGeometryLine117(
        pnt_x=0.0, pnt_y=.0254, dir_x=.0254, dir_y=0.0, bt_type="BTCurveGeometryLine-117"
    )
    line_geometry3 = BTCurveGeometryLine117(
        pnt_x=.0254, pnt_y=.0254, dir_x=0.0, dir_y=-.0254, bt_type="BTCurveGeometryLine-117"
    )
    line_geometry4 = BTCurveGeometryLine117(
        pnt_x=.0254, pnt_y=0.0, dir_x=-.0254, dir_y=0.0, bt_type="BTCurveGeometryLine-117"
    )
    line = BTMSketchCurveSegment155(
        start_point_id=f"LINE1.start",
        end_point_id=f"LINE1.end",
        start_param=0.0,
        end_param=1.0,
        geometry=line_geometry1,
        entity_id='LINE1',
        bt_type="BTMSketchCurveSegment-155",
    )
    line2 = BTMSketchCurveSegment155(
        start_point_id=f"LINE2.start",
        end_point_id=f"LINE2.end",
        start_param=0.0,
        end_param=1.0,
        geometry=line_geometry2,
        entity_id='LINE2',
        bt_type="BTMSketchCurveSegment-155",
    )
    line3 = BTMSketchCurveSegment155(
        start_point_id=f"LINE3.start",
        end_point_id=f"LINE3.end",
        start_param=0.0,
        end_param=1.0,
        geometry=line_geometry3,
        entity_id='LINE3',
        bt_type="BTMSketchCurveSegment-155",
    )
    line4 = BTMSketchCurveSegment155(
        start_point_id=f"LINE4.start",
        end_point_id=f"LINE4.end",
        start_param=0.0,
        end_param=1.0,
        geometry=line_geometry4,
        entity_id='LINE4',
        bt_type="BTMSketchCurveSegment-155",
    )
  
    sketch = BTMSketch151(
        entities=[line, line2, line3, line4],
        name="Square",
        parameters=[plane_query, length],
        constraints=[coincident_constraint1, coincident_constraint2],
        bt_type="BTMSketch-151",
    )
    feature_definition = BTFeatureDefinitionCall1406(feature=sketch)
    client.part_studios_api.add_part_studio_feature(
        did=part_studio.did,
        wvm=part_studio.wvm,
        wvmid=part_studio.wvmid,
        eid=part_studio.eid,
        bt_feature_definition_call_1406=feature_definition,
        _preload_content=False,
    )