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.
Creating polygons with a for loop?
frederik_larsen108
Member Posts: 9 EDU
I would like to create multiple polygons with a for loop depending on some info from the user, right now i just create one at a time because i cant iterate an id name?
Now i go like:
Now i go like:
skRegularPolygon(sketch, "polygon2", {
"center" : pointArray[2],
"firstVertex" : vector(pointArray[2][0]+(4)*millimeter, pointArray[2][1]+(4)*millimeter),
"sides" : 4
});
skRegularPolygon(sketch, "polygon3", {
"center" : pointArray[3],
"firstVertex" : vector(pointArray[3][0]+(4)*millimeter, pointArray[3][1]+(4)*millimeter),
"sides" : 4
});
skRegularPolygon(sketch, "polygon4", {
"center" : pointArray[4],
"firstVertex" : vector(pointArray[4][0]+(4)*millimeter, pointArray[4][1]+(4)*millimeter),
"sides" : 4
});
BUT.. i would like to do something like
BUT.. i would like to do something like
for (var i = 0; i < count; i += 1)
{
skRegularPolygon(sketch, "polygon" + i, {
"center" : pointArray[i],
"firstVertex" : vector(pointArray[i][0]+(4)*millimeter, pointArray[i][1]+(4)*millimeter),
"sides" : 4
});
}
It is the ID that gives me an error because it needs to be unique..
It is the ID that gives me an error because it needs to be unique..
Tagged:
0
Best Answer
-
konstantin_shiriazdanov Member Posts: 1,221 ✭✭✭✭✭in this case id should be a string like "polygon"~i, because plus operator is overloaded for id type to create id hierarhy
5
Answers
PhD, Mechanical Engineering, Stanford University
That is a sketch entity id - it has to be a string, not Id. Sorry we made it confusing.