Jump to content

Rounding & Absolute Numbers in Macros & Diesel


Recommended Posts

Posted

I am using LT 2010, working on cable route drawings. I have a macro that sets two variables WALLSEQ1 and WALLSEQ2 for cable sequential numbers (in meters), and calculates a corresponding cable coil COIL1 (in feet).

 

The sequential readings are in a 4 or 5 digit format, examples 0012 or 01234. I use SETENV to define my cable sequential variables, in order to capture the preceding zeroes. Then I subtract one from the other, and multiply by 3.28084 to convert the coil to feet.

 

My problem is that the coil value is sometimes negative, depending on the sequential numbers. If WALLSEQ1 is larger than WALLSEQ2, the coil is positive, if not then the coil is negative. The coil value is also in decimal format. I need to round it to the nearest whole number.

 

Is there a way to use ABS (absolute) and RND (round) in macros and diesel expressions? If I can't get an absolute value, could an IF statement be used instead?

 

Here is my macro...

 

^C^Csetenv;WALLSEQ1;\setenv;WALLSEQ2;\setenv;COIL1;$M=$(*,$(-,$(getenv,WALLSEQ1),$(getenv,WALLSEQ2)),3.28084)

Posted

Thanks rkmcswain. I'll try an IF statement to resolve the negative value. Is there another way to round a number?

Posted

I found a way to use ABS and ROUND within my macro. I used the 'CAL command when I was setting my COIL1 variable. No need for an IF statement.

 

^C^Csetenv;WALLSEQ1;\setenv;WALLSEQ2;\setenv;COIL1;'cal;abs(round($M=$(*,$(-,$(getenv,WALLSEQ1),$(getenv,WALLSEQ2)),3.28084)));

Posted

Here's the final macro using an IF statement with diesel and 'CAL expressions.

 

^C^Csetenv;SEQUNITS-F-or-M;\setenv;WALLSEQ1;\setenv;WALLSEQ2;\$M=$(if,$(eq,$(upper,$(getenv,SEQUNITS-F-or-M)),M),setenv;COIL1;'cal;abs(round(3.28084*($(getenv,WALLSEQ1)-$(getenv,WALLSEQ2)))),setenv;COIL1;'cal;abs($(getenv,WALLSEQ1)-$(getenv,WALLSEQ2)));

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...