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

brad_phelan
brad_phelan Member Posts: 91 ✭✭
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_phelan
    brad_phelan Member Posts: 91 ✭✭
    Answer ✓
    Ok. That did the trick. 


Answers

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


  • brad_phelan
    brad_phelan Member Posts: 91 ✭✭
    @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_shiriazdanov
    konstantin_shiriazdanov Member Posts: 1,221 ✭✭✭✭✭
    I would even request an option of feature pattern to not to drop external sketch references
  • brad_phelan
    brad_phelan Member Posts: 91 ✭✭
    Note the 220 calls to generate the below take about 5 seconds. And yes +1 to not dropping the external refs. 

  • david_gregory
    david_gregory Member Posts: 14 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_gregory
    david_gregory Member Posts: 14 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_mcclary
    john_mcclary Member, Developers Posts: 4,115 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