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.

I'm gong crazy trying to just edit an array of point locations in featurescript.

joshtargojoshtargo Member Posts: 238 EDU

I want to be able to edit the point locations of a spline using numerical input, but I can't figure out how to make it work.

I can take "movement distance" and a "selected point" as an input, but when I change to a different point, the old point reverts to 0 movement, and the new point assumes the movement distance.

code is here.

https://cad.onshape.com/documents/ae241e6c005a050e3bf6cc17/w/c15c3ae6c2edef30e0160ce2/e/f0a14ae8c213135935525862

Answers

  • GregBrownGregBrown Member, Onshape Employees, csevp Posts: 195

    @josh_targo I think this is going to need to be a few levels more complex than your current approach. You'll probably want to keep a map of all the control points and the displaced positions, the index in the map is probably going to be the index of the CP. Also, it will be much easier to to via selection than typing in a CP index. That's what manipulators are for. This is a non-trivial step…

    One example to look at, and it is a complex one is the Freeform spline

    https://cad.onshape.com/documents/cd51f29c6937305f86a9df95/v/f84a5282d4d42e13b923e492/e/44de484ba0acba52f99fcfc5

    A really old one (Sculpt face) uses similar techniques but its probably pretty hard to follow, and is a bit out of date https://cad.onshape.com/documents/b8730d44070bc0466ad80444/v/77aba03fc0bf992a7e4f44c8/e/4d25c05bc32c9ea6f74209d6

    I have created a cutdown version to demonstrate in vastly simplified way some of the theory. This is not public but I'll share you into a version to examine.

  • joshtargojoshtargo Member Posts: 238 EDU
    edited October 20

    I am able to use manipulators to select points, and use manipulators to move points. I can make the arrays too, and probably a map, though i havent tried that. the problem is that I don't know how to record those movements for each point and not have the movements reapply when the next point is selected. i think part of my issue is establishing the array or map in the first place. if i do it in the main code body, the array gets re-zero'd each time the code is run (i imagine this happens every time user input changes). and I can't figure out how to automatically create an array in the annotation section. If what I want to do is possible, I would love to see how.

  • Jed_YeiserJed_Yeiser Member Posts: 37 PRO

    @josh_targo - if you store the point data in a map, you can keep these offsets mapped to each point. So one key : value pair in the point map could look a little something like: (controlPointIndex) : {"x" : (controlpointOrigin[0]), "y" : (controlPointOrigin[1]), "z" (controlPointOrigin[2]), "dx" : (totalXOffsetFromPoint), "dy" : (totalYOffsetFromPoint), "dz" : (totalZOffsetFromPoint)}

    Those offsets can be a combination of offsets from manipulators and/or logic.

  • joshtargojoshtargo Member Posts: 238 EDU
    edited October 20

    does that function any differently than using an array of movements and locations for each point?

    The issue isn't recording that data in a structure, it's keeping the data properly assigned to each point when I change the point number or movement distance in the UI window

  • Jed_YeiserJed_Yeiser Member Posts: 37 PRO

    I very well may have missed something, but isn't what you're looking for exactly what that structure provides? If you maintain a map that contains data for each point on a curve, you have all of the information about every point's location and transformations. If you're changing point data - either in moving it's origin or in updating its transformation vector, you can interact with the data stored in the map.

    It sounds like you're well ahead of me re: Mutators, but you should be able to define a Mutator using a point origin. If you're taking that information from your point map to define that Mutator's location, you should be able to assign the Mutator offset(s) to the 'dx, dy and dz' fields in the map, right?

    Why us a map over an array? You really could use both. The 'things' I like about using a map in this instance is point sorting and data transparency. By using the control point index (or Parameter, if that makes more sense in your case) as a key, you don't need to worry about what order you're inserting information into an array - you simply reference the key. I find it a bit easier to interact with a 'data property' (key in a map) than an index in an array. For instance, point.X, or point.deltaX seems a clearer way to get the data you're looking for over pointDataArray[0] or pointDataArray[4]. They retrieve the same data, but one approach lets you interact with a 'property'.

  • joshtargojoshtargo Member Posts: 238 EDU

    I have working code now, based on another script, but I still feel like I need to understand this aspect a little better.

    I wish it was as simple as you stated it, but the issue is that (I think) featurescripts run each time user input is entered or changes.

    Lets say I have an array or map of the existing curve point coordinates. Now I put in a point number and a movement into fields in the UI. The point moves. Now I enter a different point number. The script runs from the beginning again applies the transformation to the new point. How do you make the code remember the. Values of it re-runs every time you change something?

Sign In or Register to comment.