center path finder feature

yarin_amiras
yarin_amiras Member Posts: 2 ✭✭
edited January 2025 in FeatureScript

Hi I have a problem with my script.
I wrote a script that finds and adds the center path of a given body. So its the center between two given edge paths on the body as well.
However I encountered an error and it didn't work, would appreciate any help! thanks.

Screenshot 2025-01-23 112022.png

The blue body was created using a wiring feature.

Wiring feature:

https://cad.onshape.com/documents/27aba2c60b53c8cebd90a0dd/v/a0887e2f35b6f23864dc1019/e/9c64fc140ab1a8da57c854d0

My script:

https://cad.onshape.com/documents/ebb982f8a9ac390bb5b949e8/w/9b6c4186b0b6a1c246a0a040/e/083ee7edb8854b5f35fd8e40

Comments

  • NeilCooke
    NeilCooke Moderator, Onshape Employees Posts: 6,123 image
    edited January 2025

    I know this doesn't help fix your problem, but if you need centrelines, you can use this:

    https://cad.onshape.com/documents/cec835eb44a6b55666a42a85

    Senior Director, Technical Services, EMEA
  • jelte_steur_info
    jelte_steur_info Member Posts: 683 PRO

    I looked at your code shallowly and noticed a few things:

    you have two same for loops after each other. perhaps you could combine those actions into one. You won't even need the first arrays of points because you can just use the poinst to create the center point and store only that in an array. may provide better performance.

    you're making a sketch plane based on edge one. did you use a debug feature to show that sketch? because I'm not sure how it will be oriented.

    more fundamentally, your center points are not necessarily on a plane, so the sketch spline wouldn't be the best way to go. perhaps a 3d spline is a better option, disregarding the sketch (and plane) all together.

    I believe there's something about using variables in a for loop that requires them to be boxed. can't find the documentation quickly. must have been in the self-guided course on featurescript. https://cad.onshape.com/FsDoc/variables.html