Welcome to the Onshape forum! Ask questions and join in the discussions about everything Onshape.

First time visiting? Here are some places to start:
  1. Looking for a certain topic? Check out the categories filter or use Search (upper right).
  2. Need support? Ask a question to our Community Support category.
  3. Please submit support tickets for bugs but you can request improvements in the Product Feedback category.
  4. Be respectful, on topic and if you see a problem, Flag it.

If you would like to contact our Community Manager personally, feel free to send a private message or an email.

Creating a cylinder using API

hari_haran541hari_haran541 Member Posts: 7

Hello all,

I am trying to create a cylinder with API , but unfortunately i couldn't,
i can create a empty document to my account but, when i try to add a sketch in it it throws a error saying unsued filters ,
i tried removing filters from my code too but still facing the issue , Does someone already gone through this before..?
I would appreciate any solution or recommendation on This.

Thanks in advance.

Comments

  • hari_haran541hari_haran541 Member Posts: 7

    hi @Paul_J_Premakumar , Thanks for the input,
    I'm having trouble with the onshape-client for Python. I tried running the official documentation example to create a newSketch, but it fails with an Invalid input arguments... unused input data is {'filter': ...} error. The strange thing is, the official example for creating a simple cube works perfectl.
    Can you help me to overcome this ..?

  • Paul_J_PremakumarPaul_J_Premakumar Member, Onshape Employees Posts: 234

    @hari_haran541 : Can you share your code & the exact error message (line number etc..) you are getting. This will help in debugging the issue.

  • hari_haran541hari_haran541 Member Posts: 7

    Hi @Paul_J_Premakumar

    Thanks for getting back to me!

    Yes, of course. Here is Python script I am using to test for creating a newSketch, along with the full error message I'm receiving.

    The Python Code:

    The Python script authenticates correctly and successfully creates a new, empty document in my Onshape account. However, the script fails on the next step when it tries to add the newSketch feature.


    The Exact Error Message:
    The script successfully creates the document but fails on the add_part_studio_feature call with the following error:

    Failed to create sketch: Invalid input arguments input when making an instance of class BTMParameterQueryList148. Not all inputs were used. The unused input data is {'filter': {'btType': 'BTOrFilter-167', 'operand1': {'btType': 'BTOrFilter-167', 'operand1': {'btType': 'BTAndFilter-110', 'operand1': {'btType': 'BTGeometryFilter-130', 'geometryType': 'PLANE'}, 'operand2': {'btType': 'BTFlatSheetMetalFilter-3018', 'allows': 'MODEL_ONLY'}}, 'operand2': {'btType': 'BTAndFilter-110', 'operand1': {'btType': 'BTAndFilter-110', 'operand1': {'btType': 'BTSMDefinitionEntityTypeFilter-1651', 'smDefinitionEntityType': 'FACE'}, 'operand2': {'btType': 'BTFlatSheetMetalFilter-3018', 'allows': 'MODEL_AND_FLATTENED'}}, 'operand2': {'btType': 'BTGeometryFilter-130', 'geometryType': 'PLANE'}}}, 'operand2': {'btType': 'BTBodyTypeFilter-112', 'bodyType': 'MATE_CONNECTOR'}}}
    

    It seems like the Python client library is incorrectly rejecting the filter parameter when creating a BTMParameterQueryList148 object. I tried creating a simple cube from the example it works perfectly but this failed.

    Thanks in advance for your help in debugging this!

    import json
    from onshape_client.client import Client

    # --- 1. CONFIGURATION ---
    DOC_NAME = "Onshape Official Docs Test"
    print(DOC_NAME)

    # --- 2. AUTHENTICATION ---
    try:
    client
    print("Onshape client already configured.")
    except NameError:
    print("Configuring Onshape client...")
    try:
    access = input("Paste your Onshape Access Key: ")
    secret = input("Paste your Onshape Secret Key: ")
    client = Client(configuration={"base_url": "https://cad.onshape.com",
    "access_key": access,
    "secret_key": secret})
    print(" Onshape client configured and ready to go!")
    except Exception as e:
    print(f" Authentication failed: {e}")
    exit(1)

    # --- 3. CREATE A NEW ONSHAPE DOCUMENT ---
    print("\\nCreating new Onshape document...")
    try:
    doc_params = {"name": DOC_NAME, "isPublic": True}
    doc = client.documents_api.create_document(bt_document_params=doc_params)
    document_id = doc.id
    workspace_id = doc.default_workspace.id
    element_id = client.documents_api.get_elements_in_document(did=document_id, wvm='w', wvmid=workspace_id)[0].id
    print("Document created successfully.")
    except Exception as e:
    print(f"Failed to create document: {e}")
    if hasattr(e, 'body'): print(f"Error details: {e.body}")
    exit(1)

    # --- 4. HARDCODED DOCUMENTATION EXAMPLE ---
    print("\\nBuilding feature list based on official documentation...")

    # STEP 4A: Define the Sketch Feature (from docs)
    sketch_feature = {
    "bt_type": "BTMSketch-151",
    "feature_type": "newSketch",
    "name": "Docs Sketch",
    "parameters": [
    {
    "bt_type": "BTMParameterQueryList-148",
    "parameter_id": "sketchPlane",
    "queries": [
    {
    "bt_type": "BTMIndividualQuery-138",
    "query_string": "mateConnector(\"Front\")"
    }
    ]
    }
    ],
    "entities": [
    {
    "bt_type": "BTMSketchCurve-4",
    "entity_id": "circle-entity",
    "geometry": {
    "bt_type": "BTCurveGeometryCircle-115",
    "radius": 0.025,
    "xcenter": 0.05,
    "ycenter": 0.05,
    "xdir": 1.0,
    "ydir": 0.0,
    "clockwise": False
    }
    }
    ]
    }

    # STEP 4B: Add the Sketch and Get its featureId
    print("\\nAdding sketch feature...")
    sketch_payload = {"bt_type": "BTFeatureDefinitionCall-1406", "feature": sketch_feature}
    try:
    sketch_response = client.part_studios_api.add_part_studio_feature(
    did=document_id, wvm='w', wvmid=workspace_id, eid=element_id,
    bt_feature_definition_call_1406=sketch_payload)

    sketch_feature_id = sketch_response.feature.feature_id
    print(f"Sketch created successfully with featureId: {sketch_feature_id}")

    except Exception as e:
    print(f" Failed to create sketch: {e}")
    if hasattr(e, 'body'): print(f"Error details: {e.body}")
    exit(1)

    # STEP 4C: Define the Extrude Feature (from docs)
    extrude_feature = {
    "bt_type": "BTMFeature-134",
    "feature_type": "extrude",
    "name": "Docs Extrude",
    "parameters": [
    {
    "bt_type": "BTMParameterEnum-145",
    "value": "SOLID",
    "enum_name": "ExtendedToolBodyType",
    "parameter_id": "bodyType"
    },
    {
    "bt_type": "BTMParameterEnum-145",
    "value": "NEW",
    "enum_name": "NewBodyOperationType",
    "parameter_id": "operationType"
    },
    {
    "bt_type": "BTMParameterQueryList-148",
    "parameter_id": "entities",
    "queries": [
    {
    "bt_type": "BTMIndividualSketchRegionQuery-140",
    "feature_id": sketch_feature_id
    }
    ]
    },
    {
    "bt_type": "BTMParameterEnum-145",
    "value": "BLIND",
    "enum_name": "BoundingType",
    "parameter_id": "endBound"
    },
    {
    "bt_type": "BTMParameterQuantity-147",
    "expression": "1 in",
    "parameter_id": "depth"
    }
    ]
    }

    print("\\nAdding extrude feature...")
    extrude_payload = {"bt_type": "BTFeatureDefinitionCall-1406", "feature": extrude_feature}
    try:
    client.part_studios_api.add_part_studio_feature(
    did=document_id, wvm='w', wvmid=workspace_id, eid=element_id,
    bt_feature_definition_call_1406=extrude_payload)
    print(" Extrude added successfully!")
    except Exception as e:
    print(f" Error adding extrude: {e}")
    if hasattr(e, 'body'): print(f"Error details: {e.body}")
    exit(1)

    final_url = f"https://cad.onshape.com/documents/{document_id}/w/{workspace_id}/e/{element_id}"
    print("\n Process Complete!")
    print("View your new CAD model at:")
    print(final_url)
  • Paul_J_PremakumarPaul_J_Premakumar Member, Onshape Employees Posts: 234

    @hari_haran541 : The python client is no longer being updated. It can be used for authentication, but beyond that the other calls are not guaranteed to work.As a workaround instead of calling the part_studios_api.add_part_studio_feature you can construct the required params and call the GET/POST methods using the generic client.api_client.request or one of the python library REST api calls.

Sign In or Register to comment.