How Do I Subtract a Number from My Variable

3966_cad
3966_cad Member Posts: 10 EDU
I am trying to iterate an skCircle to space them out evenly, but I keep on running into an error: 
"Can not subtract ValueWithUnits (map) and number"
        for (var i = 0 * inch; i < definition.length; i += 1)
        {
            var iss = i - 0.5;
            skCircle(sketch2, "circle" ~ i, {
                        "center" : vector((iss), 0.5 * inch),
                        "radius" : 0.6299 * inch
                    });
        }
Here is the link to the full file.
I know what the error means, but I can't figure out how to make it work. 
I would appreciate any help you can offer me.

Comments

  • lana
    lana Onshape Employees Posts: 782 image
    In expression var iss = i - 0.5; i is a ValueWithUnits , namely length. The value you subtract from it also has to be length : 
    var iss = i - 0.5 * inch<span>; would fix the the error. </span>
  • Jake_Rosenfeld
    Jake_Rosenfeld Moderator, Onshape Employees, Developers Posts: 1,646 image
    edited July 2017
    You are going to run into similar issues with:
    i += 1
    and 
    </code>skCircle(sketch2, "circle" ~ i, {...</pre>The first is the same issue as you posed about (adding a number and a ValueWithUnits) and the second if that the Featurescript interpreter won't be happy with using a ValueWithUnits in an Id string. &nbsp;You can fix these issues by using:<br><pre class="CodeBlock"><code>i += 1 * inch
    and 
    skCircle(sketch2, "circle" ~ (i / inch), {...
    respecively.
    Jake Rosenfeld - Modeling Team
  • 3966_cad
    3966_cad Member Posts: 10 EDU
    Thanks! I was just about to ask that.

  • 3966_cad
    3966_cad Member Posts: 10 EDU
    OK. So I did that and I got another error that my qContainsPoint wasn't resolving to anything. Any tips on this?

  • 3966_cad
    3966_cad Member Posts: 10 EDU
    Still need help by the way
  • ilya_baran
    ilya_baran Onshape Employees, Developers, HDM Posts: 1,274 image
    I would guess the issue is that qSketchRegion(id + "sketch2") may not be selecting what you expect (try passing that into debug) and instead you should use qCreatedBy(id + "sketch2", EntityType.FACE)
    Ilya Baran \ VP, Architecture and FeatureScript \ Onshape Inc
  • 3966_cad
    3966_cad Member Posts: 10 EDU
    Got it.