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.

Transformation of a surface in a loop fails

j_j406j_j406 Member Posts: 6
I am running the following sequence
1. transform+copy an existing surface 5 times
2. Add the new surfaces an attribute "Slicer"
3. Delete all surfaces with an attribute "Slicer"
4. Got back to step 1.

During the first iteration everything works fine, however during the second iteration transform fails with "Cannot Resolve Entities". I checked that my delete operation does not delete the original surface, only copies. Does anyone have an idea what the problem might be?

     var distance=0;
        for ( var i=1;i<5;i=i+1)
        {
          println(i);
          distance=0;
          
          for ( var count=1;count<5;count=count+1)
          {
            distance = distance+2+6;
            print("-");
            println(count);
            //print("---");
            //println(definition.xslicer);
            
            transform(context, id + i+count+"transformx"+i+count, {
                                "entities" : definition.xslicer,
                                "transformType" : TransformType.TRANSLATION_3D,
                                "dx" : distance*millimeter,
                                "dy" : 0*millimeter,
                                "dz" : 0*millimeter,
                                "makeCopy" : true
                        });
                      
            setAttribute(context, {
                    "entities" : qMatching(definition.xslicer),
                    "name" : "Slicer",
                    "attribute" : "Slicer"
            });
            
          }  
          
        try
        {
        opDeleteBodies(context, id + "deleteBodies", {
                "entities" : qHasAttribute("Slicer")
        });
        }
        catch
        {
        println("Error - opDeleteBodies");
        }
    }




Comments

  • NeilCookeNeilCooke Moderator, Onshape Employees Posts: 5,310
    What does this script do? Hard to tell without access to the full thing, but your id construct in transform is a little odd and I’m not sure I would rely on qMatching. 
    Senior Director, Technical Services, EMEAI
  • j_j406j_j406 Member Posts: 6
    Hi Neil,
    The overall goal to create a surface texture.
    1. Split all faces along Z
    2. Split all faces along X
    3. Split all faces along Y
    4. Move faces randomly

    For splitting purposes, I create several, temporary copies of a pre-defined surface. The temporary copies are then deleted and the process starts again.
    The problem is that the process works for only one iteration. transform() fails during second iteration.

    I created a simplified FS to debug this issue (see the "Sandbox" FS - https://cad.onshape.com/documents/3cfff268f3889341b02464a8/w/85e63e5bbddd5c2dace86f37/e/feb92511a4af3a77e2661137), however I struggle with root causing the issue.

  • NeilCookeNeilCooke Moderator, Onshape Employees Posts: 5,310
    This will fix your script so far, but I can't help but think this will not work as you expect. Using qMatching and setAttributes is not the best strategy IMO.

    var distance=0;
            for ( var i=1;i<5;i=i+1)
            {
              println(i);
              distance=0;
              
              for ( var count=1;count<5;count=count+1)
              {
                distance = distance+2+6;
                print("-");
                println(count);
                
                transform(context, id + i+count+"transformx", {
                                    "entities" : definition.xslicer,
                                    "transformType" : TransformType.TRANSLATION_3D,
                                    "dx" : distance*millimeter,
                                    "dy" : 0*millimeter,
                                    "dz" : 0*millimeter,
                                    "makeCopy" : true
                            });
                                              
                setAttribute(context, {
                        "entities" : qCreatedBy(id + i+count+"transformx"),
                        "name" : "Slicer",
                        "attribute" : "Slicer"
                });
                
              }  
              
        }
            try
            {
            opDeleteBodies(context, id + "deleteBodies", {
                    "entities" : qHasAttribute("Slicer") 
            });
            }
            catch
            {
            println("Error - opDeleteBodies");
            }
    


    Senior Director, Technical Services, EMEAI
  • j_j406j_j406 Member Posts: 6
    Thanks :)
    What strategy would you suggest?

  • NeilCookeNeilCooke Moderator, Onshape Employees Posts: 5,310
    Hard to say - I'm trying to picture in my mind what a part would look like after applying this script. The loop seems to do the same thing each time?
    Senior Director, Technical Services, EMEAI
Sign In or Register to comment.