Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: Using the modulo operator (%) in parametric parts

  1. #1
    100 Club
    Join Date
    2008-06
    Location
    VA
    Posts
    165
    Login to Give a bone
    0

    Default Using the modulo operator (%) in parametric parts

    Hi all,

    I'm making a parametric part where the connection height is based on a calculation that may not result in integer values (e.g. 6.75"). I figured out a formula that uses the mod operator (%) (available in the Model Parameters Calculator) and rounds a number to its nearest value: N+((N%1)-(2*((N%1)%0.5))) . "Hooray!" I thought, since this formula works perfectly inside the Model Parameters dialog box (see SS below). However, when I try to look at the Size Parameters, I get a message that says "One or more calculated values failed", and consequently, my part can't be validated and used. Through some troubleshooting, I'm 99.9% sure that it's because of the % operator I'm using in the Model Parameters.

    My question is: Is there a certain way I need to format the % operator so that it doesn't cause an error in the Size Parameters? Or, know of any ways to round the number without using %?

    Any ideas are appreciated.

    Thanks,
    Brad
    Attached Images Attached Images

  2. #2
    All AUGI, all the time
    Join Date
    2007-10
    Location
    Tucson, Arizona
    Posts
    613
    Login to Give a bone
    0

    Default Re: Using the modulo operator (%) in parametric parts

    Try using Int(6.75)

    (integer function)

    This will not round up though, so if you need to have that ability you could use an if statement:

    If Int(NUM) = Int(NUM+0.5) Then
    RESULT = Int(NUM)
    Else
    RESULT = Int(NUM+0.5)
    End If

    -Buzz

  3. #3
    All AUGI, all the time
    Join Date
    2007-10
    Location
    Tucson, Arizona
    Posts
    613
    Login to Give a bone
    0

    Default Re: Using the modulo operator (%) in parametric parts

    Looking at my post, and realizing that I haven't had my coffee yet...

    No if statement required, could simply use:

    Int(NUM+0.5)

    -Buzz

  4. #4
    100 Club
    Join Date
    2008-06
    Location
    VA
    Posts
    165
    Login to Give a bone
    0

    Default Re: Using the modulo operator (%) in parametric parts

    Thanks Buzz,

    Maybe I'm missing something, but the dimension I'm trying to control is the Connection Height RH1, which is controlled through the Model Parameters; and if I understand you corrently, I'll have to do a Size Parameters calculation to use Int(). As of now, whenever I try to tell RH1 to refer to a Size Parameter (e.g. PDim1), it just tells me that it's an invalid equation. Hopefully you know of a way to get Model Parameters to play nice with Size Parameters?

    -Brad

  5. #5
    All AUGI, all the time
    Join Date
    2007-10
    Location
    Tucson, Arizona
    Posts
    613
    Login to Give a bone
    0

    Default Re: Using the modulo operator (%) in parametric parts

    For formulae, you need to edit them through the model parameters. It looks like Int() does not work, but int() does (lowercase). Try that.

    -Buzz

  6. #6
    100 Club
    Join Date
    2008-06
    Location
    VA
    Posts
    165
    Login to Give a bone
    0

    Default Re: Using the modulo operator (%) in parametric parts

    Hooray Buzz! It works, and is much more elegant than that formula I was using.

    Thanks a million,
    -Brad

  7. #7
    All AUGI, all the time
    Join Date
    2007-10
    Location
    Tucson, Arizona
    Posts
    613
    Login to Give a bone
    0

    Default Re: Using the modulo operator (%) in parametric parts

    No sweat - strange that it needs to be lowercase...

    -Buzz

  8. #8
    100 Club
    Join Date
    2008-06
    Location
    VA
    Posts
    165
    Login to Give a bone
    0

    Default Re: Using the modulo operator (%) in parametric parts

    On a different (perhaps more interesting?) note:

    After playing around with a custom Size Parameter, I'm now 100% sure that the % operator in Size Parameter calculations is broken. Even though it gives '%' as an available option in the calculator, the result it gives is completely wrong; for example, doing 7 % 4 should yield 3, however, 7 % 4 in the size parameters yields 7 (see SS).

    It appears the correct operator is Mod instead of %, since Size Parameters are apparently evaluated using VB. Doing 7 Mod 4 yields the correct result of 3 (SS). However, it seems that it doesn't like it when I try to Mod by a decimal/non-integer number (i.e. 0.5 or (1/2)); it just gives an "Invalid equation" error. My formula doesn't give an error if I copy+paste it into a Size Parameter calculation and replace all of the %'s with Mod's, and then change the 0.5 to an integer. Microsoft says VB can handle decimal mods, so perhaps AMEP is using VBA instead ( http://msdn.microsoft.com/en-us/libr...sz(VS.80).aspx ).

    Finally, it seems that what was giving me trouble in the first place is the fact that it doesn't like having the % operator (whatever it does) in the same equation as a named-variable, since trying 7 % 4 doesn't produce an 'Invalid equation' error, but pH % 4 does.


    If I had to place a bet as to what's going on here, I'd guess that the Model Parameters are being evaluated using C or C++ or something similar, but the Size Parameters are evaluated using VB (or more likely, VBA). Unfortunately, it seems that all equations are ultimately evaluated in SP's VB, and therefore any equations entered in MP must also be valid in VB, despite being written for C. This would explain why % works in MP, but does nothing in SP, and vice-versa for Mod. It would also (possibly) explain why Int(x) works in SP, but you have to use int(x) in MP; luckily, it appears that VB doesn't care that the i isn't capitalized.

    I may be wrong about all that, but it's my best guess. Anyhow, anyone know of a good way to tell Autodesk they've screwed up? = ]

    -Brad
    Attached Images Attached Images

  9. #9
    All AUGI, all the time
    Join Date
    2007-10
    Location
    Tucson, Arizona
    Posts
    613
    Login to Give a bone
    0

    Default Re: Using the modulo operator (%) in parametric parts

    anyone know of a good way to tell Autodesk they've screwed up?
    I usually start with "Dear Autodesk" and then end with "Love, Buzz"

    It sounds like you have it working, but in the future if you run into more problems because of this, you may have some luck editing the .xml file directly for those equations.

    -Buzz

  10. #10
    Super Moderator dkoch's Avatar
    Join Date
    2003-03
    Location
    Philadelphia, PA
    Posts
    2,392
    Login to Give a bone
    0

    Default Re: Using the modulo operator (%) in parametric parts

    Quote Originally Posted by bradg View Post
    If I had to place a bet as to what's going on here, I'd guess that the Model Parameters are being evaluated using C or C++ or something similar, but the Size Parameters are evaluated using VB (or more likely, VBA).
    I do not have access to MEP (just ACA), so I am not certain how MEP evaluates things, but given that a formula property in a Property Set is evaluated using VBScript (which is similar to VB but does have some differences), I would guess that anything "VB-like" is being evaluated using VBScript.
    http://msdn.microsoft.com/en-us/libr...h6(VS.85).aspx

Page 1 of 2 12 LastLast

Similar Threads

  1. Parametric Parts - Five-Segment Elbow
    By fkleiner in forum AMEP General
    Replies: 0
    Last Post: 2011-10-19, 06:05 PM
  2. Parametric Parts Help
    By bradg in forum AMEP General
    Replies: 2
    Last Post: 2008-06-19, 02:24 PM
  3. Parametric MV Parts
    By Eric Wing in forum AMEP General
    Replies: 4
    Last Post: 2007-12-17, 09:16 PM
  4. Parametric Parts in ABS2007
    By bbambu in forum Parts Builder
    Replies: 2
    Last Post: 2006-12-14, 05:25 PM
  5. Parametric Parts & Ductwork Help
    By ameador in forum Parts Builder
    Replies: 6
    Last Post: 2006-09-28, 08:51 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •