Welcome to the Onshape forum! Ask questions and join in the discussions about everything Onshape.
First time visiting? Here are some places to start:- Looking for a certain topic? Check out the categories filter or use Search (upper right).
- Need support? Ask a question to our Community Support category.
- Please submit support tickets for bugs but you can request improvements in the Product Feedback category.
- 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.
Transform in "for" loop strange behavior
I've made a featurescript that spaces parts with an exact gap away from each other along a plane No mater what their shape or orientation (yes I am fishing for brownie points).
HOWEVER! The last transform in the last loop seems to change it's vector despite the debug tool showing the vector is correct:
var moveVector = spaceDist.sides[0].point - spaceDist.sides[1].point; //Distance result points to get a vector
var clusterTransform = transform(moveVector / 2);
var nonClusterTransform = transform(-moveVector / 2);
opTransform(context, id + "2ndLoop" + m + "moveCluster", {
"bodies" : clusterBodies,
"transform" : clusterTransform
});
opTransform(context, id + "2ndLoop" + m + "moveNonCluster", {
"bodies" : nonClusterBodies,
"transform" : nonClusterTransform
});
var partBodies = qUnion([partMap.part, partMap.gapPath, partMap.spiralPath]);
clusterBodies = qUnion(clusterBodies, partBodies);
nonClusterBodies = qSubtraction(nonClusterBodies, partBodies);
This is supposed to be equally spaced and the vectors confirm that:
This is debug of the "moveVector" and I have drawn the equivalent transforms.
My script essentially loops through the selected parts one by one and once the part is "spaced" its added to a query called "clusterBodies" and removed from "nonClusterBodies" so that the cluster is spaced from non cluster part by part until all have been spaced. So in theory those 3 square parts should be equally spaced but the top one aligns with one side for some dumb reason. I have already confirmed that the parts are being looped through in the correct order. Please help:
The part studio I'm testing in
The Feature Studio
Best Answer
-
Never mind I figured it out. Such an idiot hahaha, I was transforming all remaining parts rather then just the next part in question
0
Answers
-
If you want some explanation on how the spacing itself is calculated it's pretty strange and complicated so I'm happy to elaborate here. Just ask
0 -
Just tried rewriting everything to simplify it and reduce the number of variables to no avail
0 -
Never mind I figured it out. Such an idiot hahaha, I was transforming all remaining parts rather then just the next part in question
0


