Polyline area macro issue help


tlinder
 Share

Go to solution Solved by Alaskan_Son,

Recommended Posts

I'm trying to create a macro that will calculate the area in polylines and show it in a separate text box. This is needed to calculate sod, concrete, sidewalk ect.

I found a macro that I have been trying to manipulate to do this. Attached is a simple file that a have been experimenting with to achieve my desired results.

 

This is the script:

 

$_2ExistingBoxSQFT = area rescue $_2ExistingBoxSQFT

 

if $_2ExistingBoxSQFT == 0

na = "N/A"

"#{na}"

else

"#{$_2ExistingBoxSQFT.round(2)} SQ. FT."

end

 

This is the evaluation error it is giving me:

 

Evaluation Error: Ruby NoMethodError: undefined method `round' for nil:NilClass

Stack Trace:

from (eval):1:in `instance_eval'

from (eval):1:in `block (2 levels) in <main>'

from eval:9:in `eval'

from eval:9:in `block (2 levels) in <main>'

from eval:3:in `loop'

from eval:3:in `block in <main>'

 

Macro Test.plan

Link to comment
Share on other sites

Do you understand the macro -- the syntax of each line and what it's supposed to do?

 

There are at least 2 people here on the forum that sell packages to do this.

  • Like 1
Link to comment
Share on other sites

9 minutes ago, rgardner said:

and know about polyline schedules???

 

To be more clear, there is no "polyline schedule". You may use a Custom Schedule to report polylines, and the polylines you want in the schedule need to have Include in Schedule checked.

  • Like 1
  • Upvote 1
Link to comment
Share on other sites

2 hours ago, solver said:

Do you understand the macro -- the syntax of each line and what it's supposed to do?

 

There are at least 2 people here on the forum that sell packages to do this.

Thank you for you quick reply. I am new to Ruby. All this language is still new to me.

Link to comment
Share on other sites

1 hour ago, solver said:

 

To be more clear, there is no "polyline schedule". You may use a Custom Schedule to report polylines, and the polylines you want in the schedule need to have Include in Schedule checked.

I have not tried that route. Thank you for suggesting it. 

Link to comment
Share on other sites

3 hours ago, tlinder said:

I'm trying to create a macro that will calculate the area in polylines and show it in a separate text box. This is needed to calculate sod, concrete, sidewalk ect.

 

Do you need this in a schedule format with a total ?   It is not entirely clear what you are after.

You can use the label of the polyline and move it away form the polyline or you can use as text box with an attached leader line and a referenced macro.  The leader line can be hidden with line style of color changes.

  • Like 1
Link to comment
Share on other sites

Looks to be some sort of an issue with your particular example in the test plan though.  I have not tried to get that area of a Material region before but in theory it should work but it is not.  Regular polylines are fine though.

 

image.thumb.png.f14cbfc6a6a9dceb2c2295bac84d8c68.png

  • Like 1
Link to comment
Share on other sites

2 hours ago, solver said:

 

To be more clear, there is no "polyline schedule". You may use a Custom Schedule to report polylines, and the polylines you want in the schedule need to have Include in Schedule checked.

Correct there is no polyline default schedule.  However once you have created a custom schedule to report polylines then yes there is a polyline schedule.  But thank you for clarifying this for the OP and any others looking for how to do this in X14.  Good information.

Link to comment
Share on other sites

  • Solution

You have all sorts of problems going on. 

 

First things first: 

That macro is overly complicated and was written by someone at some point prior to Chief implementing the Measurement class.  You can get rid of the error as shown below:

 

$_2ExistingBoxSQFT = area rescue $_2ExistingBoxSQFT

 

if $_2ExistingBoxSQFT.to_f == 0  #area is a Measurement with a unit and you're attempting to compare that to a unitless value of zero.  You first need to make the Measurement unitless as well.

na = "N/A"

"#{na}"  #These aren't actually breaking the code but they're unnecessarily redundant.

else

"#{$_2ExistingBoxSQFT.to_f.round(2)} SQ. FT." #Again, this wasn't causing the error, but you're adding some text to show a unit for a Measurement when a unit already exists.  You should really either use the automatic unit or first convert to a float and then use your own.

end

 

Second:

You need to set that global variable before it can be used in a text box.  That macro was designed to both define a variable and display a variable value.  Your plan attempts to display the value before it has even been defined.  To define the value, your macros need to be placed into the label of your polyline object. 

 

 

Now if you ask me: I would suggest an entirely different approach that completely bypasses Text Macro Management.

  • In your polyline object use something like %$my_box = area%
  • In your text box use either %$my_box.round(2).to_s%  or  %$my_box.to_f.round(2)% SQ. FT.

It can really be as simple as that.  If you need further formatting or conditional arguments you can either add it right in line or you can go back to writing and maintaining custom text macros, but that stuff isn't necessary for most use cases. 

  • Like 1
Link to comment
Share on other sites

On 6/24/2022 at 7:07 PM, Alaskan_Son said:

 

 

 

Now if you ask me: I would suggest an entirely different approach that completely bypasses Text Macro Management.

  • In your polyline object use something like %$my_box = area%
  • In your text box use either %$my_box.round(2).to_s%  or  %$my_box.to_f.round(2)% SQ. FT.

 

Thank you so much for your help!

  • Like 1
Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
 Share

  • Member Statistics

    32353
    Total Members
    9156
    Most Online
    RRSSeattle
    Newest Member
    RRSSeattle
    Joined