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.

How Do I Subtract a Number from My Variable

3966_cad3966_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

  • lanalana Onshape Employees Posts: 704
    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_RosenfeldJake_Rosenfeld Moderator, Onshape Employees, Developers Posts: 1,646
    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_cad3966_cad Member Posts: 10 EDU
    Thanks! I was just about to ask that.

  • 3966_cad3966_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_cad3966_cad Member Posts: 10 EDU
    Still need help by the way
  • ilya_baranilya_baran Onshape Employees, Developers, HDM Posts: 1,210
    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_cad3966_cad Member Posts: 10 EDU
    Got it.

Sign In or Register to comment.