cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community email notifications are disrupted. While we are working to resolve, please check on your favorite boards regularly to keep up with your conversations and new topics.

Assistance Required for Accessing CAD Document Parts Information via API

ozclkonur
8-Gravel

Assistance Required for Accessing CAD Document Parts Information via API

I can retrieve the reference information of the CAD document using CADDocuments('OR:wt.epm.EPMDocument:XXXX')?$expand=References, but I cannot access the parts information of the CAD document when I use CADDocuments('OR:wt.epm.EPMDocument:XXXX')?$expand=Parts. The CAD document has a relationship with parts, and I am trying to access the related parts. I tried using the EPMBuildRule table, but it does not accept the ID of the drawing data. I believe it needs to be the owner, but I cannot access its ID via the API. Can you help me with this?

2 REPLIES 2

Accessing the related parts of a CAD document in Windchill through the REST API can be tricky due to the specific relationships and tables involved. Since you're able to expand the References but not the Parts, let's break down the steps and make sure you're using the correct approach and endpoint.

 

Understanding the Relationships
In Windchill, CAD documents (EPMDocuments) are often related to parts (WTParts) through an EPMBuildRule. The EPMBuildRule establishes a link between the CAD document and the part.

Steps to Access Related Parts
Ensure Correct Usage of $expand
Make sure that the endpoint you're using actually supports the Parts relationship directly. The $expand option is used to include related entities inline with the response.

 

Use the Correct API Endpoint


The direct relationship might not be available in a straightforward way via $expand. You might need to perform an additional query to fetch the related parts.

 

Example Workflow to Access Related Parts
Retrieve the CAD Document ID
First, ensure you have the correct CAD document ID (which you seem to already have).

Fetch Related Parts using EPMBuildRule
Since the direct $expand=Parts is not working, you may need to retrieve the parts using the EPMBuildRule relationship.

Detailed API Calls
Step 1: Fetch CAD Document References


You mentioned this works:

http


Copy code


GET /Windchill/servlet/odata/ProdMgmt/CADDocuments('OR:wt.epm.EPMDocument:XXXX')?$expand=References
Step 2: Fetch EPMBuildRule
Retrieve the EPMBuildRule where the CAD document is the source. This typically involves querying the EPMBuildRule table and using the CAD document ID.

http
Copy code
GET /Windchill/servlet/odata/ProdMgmt/EPMBuildRules?$filter=source eq 'OR:wt.epm.EPMDocument:XXXX'
This should return the EPMBuildRule entries that link the CAD document to the parts.

Step 3: Retrieve Parts from EPMBuildRule
Once you have the EPMBuildRule entries, extract the part references (target). You may need to loop through the returned EPMBuildRule entries and collect the related parts.

Example Script (Pseudocode)
Here’s a simplified workflow in pseudocode to illustrate:

python


Copy code


import requests

# Set up the base URL and headers for authentication
base_url = 'http://your-windchill-server/Windchill/servlet/odata/ProdMgmt/'
headers = {'Authorization': 'Bearer your_access_token'}

# Step 1: Get the CAD document references
cad_document_id = 'OR:wt.epm.EPMDocument:XXXX'
cad_url = f"{base_url}CADDocuments('{cad_document_id}')?$expand=References"
cad_response = requests.get(cad_url, headers=headers)
cad_data = cad_response.json()

# Step 2: Get the EPMBuildRule entries for the CAD document
epm_build_rule_url = f"{base_url}EPMBuildRules?$filter=source eq '{cad_document_id}'"
epm_response = requests.get(epm_build_rule_url, headers=headers)
epm_data = epm_response.json()

# Step 3: Extract the part IDs from EPMBuildRule
part_ids = [entry['target'] for entry in epm_data['value']]

# Step 4: Fetch part details (if needed)
parts = []
for part_id in part_ids:
part_url = f"{base_url}Parts('{part_id}')"
part_response = requests.get(part_url, headers=headers)
parts.append(part_response.json())

# parts now contain detailed information about the related parts
print(parts)


Notes:


Authorization: Ensure you handle authentication correctly with appropriate tokens or session management.
Error Handling: Add error handling for API responses.
Performance: Be mindful of the number of API calls; batch requests if possible.
By following this workflow, you should be able to retrieve the related parts of a CAD document in Windchill. If direct $expand=Parts support is not available, querying through intermediate tables like EPMBuildRule is a reliable alternative.

avillanueva
22-Sapphire II
(To:ozclkonur)

Did @RM_11009726 response help you or solve your issue? Please provide some feedback for thread.

Top Tags