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.

Why are my variables not working when set for feature driven pattern

brad_phelanbrad_phelan Member Posts: 80 ✭✭
I have the following profile designed using a variable width



In my custom feature I have tried the following

      annotation { "Name" : "Profile", "Filter" : SketchObject.YES, "MaxNumberOfPicks" : 1 }
      def.profile is FeatureList;

       ...



        setVariable(context, "width", 115 * millimeter);
        applyPattern(context, id + "sk0", {
                    "patternType" : PatternType.FEATURE,
                    "instanceFunction" : valuesSortedById(context, def.profile),
                    "transforms" : [transform(vector(50, 0, 0) * millimeter)],
                    "instanceNames" : ["a"]
                }, identityTransform());

        setVariable(context, "width", 315 * millimeter);
        applyPattern(context, id + "sk1", {
                    "patternType" : PatternType.FEATURE,
                    "instanceFunction" : valuesSortedById(context, def.profile),
                    "transforms" : [transform(vector(100, 0, 0) * millimeter)],
                    "instanceNames" : ["a"]
                }, identityTransform());

       
The profiles are patterned



but the two new sketches don't accept the width variable. Any idea what I am doing wrong?


Tagged:

Best Answers

  • brad_phelanbrad_phelan Posts: 80 ✭✭
    Accepted Answer
    Ok. That did the trick. 


Answers

  • brad_phelanbrad_phelan Member Posts: 80 ✭✭
     I have a lot of constraints to the origin. Ok I'll try your fix. Thanks
  • brad_phelanbrad_phelan Member Posts: 80 ✭✭
    Accepted Answer
    Ok. That did the trick. 


  • brad_phelanbrad_phelan Member Posts: 80 ✭✭
    @ilya_baran When doing this I would suggest an improvement to applyPattern. Currently I think I have to do a loop

       for(;;;){
           setVariable(context,...);
           applyPattern(context,...);
       }

    it would be nice if applyPattern had an extraparameter

    variables of type array of map where variables for each instance could be set. 
  • konstantin_shiriazdanovkonstantin_shiriazdanov Member Posts: 1,002 ✭✭✭✭✭
    I would even request an option of feature pattern to not to drop external sketch references
  • brad_phelanbrad_phelan Member Posts: 80 ✭✭
    Note the 220 calls to generate the below take about 5 seconds. And yes +1 to not dropping the external refs. 

  • david_gregorydavid_gregory Member Posts: 9 PRO
    Hi-

    Does anyone have a link to a FS that does this setVariable inside a for loop with a pattern?  I want to do essentially the same thing and I'm not getting the array syntax.
  • david_gregorydavid_gregory Member Posts: 9 PRO
    Perhaps this is a bit beginner, but I don't quite understand the array syntax in FS.   This is not quite working:


            definition.entities = definition.bodies;
            definition.instanceNames = names;
            definition.transforms = transforms;
            for (var k = 0; k < size(transforms); k += 1)
            {
                setVariable(context, "dCharacteristic", .030*(1 + (k*.002))*inch);
                applyPattern(context, id + ("pattern" ~ k), definition, remainingTransform);
            }

  • john_mcclaryjohn_mcclary Member, Developers Posts: 2,801 PRO
    what error message are you getting @david_gregory
    If you click the FeatureScript notices button it will flyout a console output on the bottom of the screen If you toggle on Monitoring you can see the result of the last committed script
Sign In or Register to comment.