Custom Unit Conversions for Area ?


Chopsaw
 Share

Recommended Posts

Has anyone had any luck or experience with adding Custom Unit Conversions for Area to Preferences and using them in the software?

I am hoping I am wrong but there does not seem to be any way of accessing this information in any other part of the program.  Bad day perhaps.

 

image.thumb.png.829f4f83aa5801261ca9229daf71c550.png

 

However reading in the Ruby section of the Help File it seems to suggest that Custom Unit Conversions are supported by the Measurement Class.

 

So something like this should work ?    %area.to_acre%   or perhaps   %area.to_sq_acre%

 

Maybe I need to put acre in as a "Length" measurement like feet or meters so the software can do the math and "sq" it ?

 

I called tech support and put in a request that acres and hectares be added to the hard-coded default units but that was all the help they could offer.

 

Any insight would be much appreciated.

 

Link to comment
Share on other sites

Why are you trying to do it via the Unit Conversions? , rather than just writing your own macro to put into the Polyline Label for example ?

 

Just wondering if you are over thinking this? 

 

image.thumb.png.5591237d07dae7b052c965178bd4088b.png

 

you maybe able to use the New Number Formatter in Ruby to convert sq.ft to acre perhaps?

 

M.

 

 

Link to comment
Share on other sites

22 minutes ago, Kbird1 said:

Why are you trying to do it via the Unit Conversions? , rather than just writing your own macro to put into the Polyline Label for example ?

 

Just thinking that the software might be able to do it without a user macro for simplicity and consistency.  If you need some sort of little macro for everything you do that is a lot of macro's to keep track of without any sort of indexing system.

 

24 minutes ago, Kbird1 said:

Just wondering if you are over thinking this? 

 

Perhaps but can you think of any way to access even a hard-coded default unit that is an Area or Volume in the program aside from the new Measurement Class system ?

 

27 minutes ago, Kbird1 said:

you maybe able to use the New Number Formatter in Ruby to convert sq.ft to acre perhaps?

 

I don't think so.  I would like to be proven wrong of course, but I think it only "stylizes" the existing hard-coded default units.

Link to comment
Share on other sites

I don't disagree and you would think Acre and Hectare were already built in being the common 2 areas for large parcels of land , but CA's track record on supplying "Industry needs" is not stellar... ConDocs are almost a 2nd thought these days....

 

No, we don't have access to anything hardcoded such as the built in Macros to alter them AFAIK.

 

Ok, you know Macros better than me, but I was thinking perhaps the Num.Formatter could include the conversion equation from say Sq.Ft.

 

M.

  • Like 1
Link to comment
Share on other sites

On 12/15/2021 at 8:44 AM, Chopsaw said:

in the Ruby section of the Help File it seems to suggest that Custom Unit Conversions are supported by the Measurement Class.

They are.  You can for example do the conversion using something like %area.convert_to("acre")% or you can specify your new Unit using the NumberFormatter as well.

Link to comment
Share on other sites

45 minutes ago, Alaskan_Son said:

something like %area.convert_to("acre")%

 

Knowing ruby inside out helps I guess :) .....   I played around with it yest.  but  %area.convert_to_acre%  didn't work :) ( after making the new acre "Unit" )

 

Thanks.

 

M.

Link to comment
Share on other sites

1 hour ago, Alaskan_Son said:
On 12/15/2021 at 12:44 PM, Chopsaw said:

in the Ruby section of the Help File it seems to suggest that Custom Unit Conversions are supported by the Measurement Class.

They are.  You can for example do the conversion using something like %area.convert_to("acre")% or you can specify your new Unit using the NumberFormatter as well.

 

Thanks Michael,  That is actually one more character than the method I ended up using  %(area.to_sq_m/4047)%  but it saves me having to look up the conversion factor and maybe not get it correct every time.

 

Seems strange that the SHORTCUT will not work for this instance.   %area.to_acre%

 

Is there a way to use the rest of the formatting "convert_to(unit: Symbol | String)"  to display the "units" ?

Or do you need to create a complete NumberFormatter for that with unit=("acre") in it ?

Link to comment
Share on other sites

1 hour ago, Kbird1 said:

 

Knowing ruby inside out helps I guess :) .....   I played around with it yest.  but  %area.convert_to_acre%  didn't work :) ( after making the new acre "Unit" )

 

Thanks.

 

M.

I definitely wouldn’t say that I know Ruby inside out. Even if I did though, all that knowledge and expertise would be old but useless in this situation since the required syntax was all written and specified by Chief.  

Link to comment
Share on other sites

7 minutes ago, Alaskan_Son said:

I definitely wouldn’t say that I know Ruby inside out. Even if I did though, all that knowledge and expertise would be old but useless in this situation since the required syntax was all written and specified by Chief.  

 

Ok Chief's Version of Ruby then :) , they sure don't make it User Friendly or easy for anyone with an interest as there is virtually no documentation Online to support it's use.

 

There are a few Threads with info but not many.... as some were lost with the Beta Forum, pity Chief doesn't have a Sub-Forum for Users and CA Ruby Experts to help Each other....

 

https://chieftalk.chiefarchitect.com/topic/25611-macro-returning-units/?tab=comments#comment-205770

 

M.

 

Link to comment
Share on other sites

1 hour ago, Chopsaw said:

Seems strange that the SHORTCUT will not work for this instance.   %area.to_acre%

 

Is there a way to use the rest of the formatting "convert_to(unit: Symbol | String)"  to display the "units" ?

Or do you need to create a complete NumberFormatter for that with unit=("acre") in it ?


The shortcuts only work with a limited subset of the built-in units. I suspect in large part that is due to the formatting limitations imposed by Ruby’s method naming conventions.  It’s probably just too risky to allow custom units to create matching methods when there’s no telling what the name of that unit might be.  
 

Anyway, to answer your last question, there are a whole handful of ways to do what you are after using the Measurement class, the NumberFormatter, or both, but pretty much all of them require both making the conversion (either in Float form or in Measurement form) and then specifying the unit in two distinct steps. I’m not sure I can think of any way to do so in a single step.  You could of course write any number of custom macros that would carry out the whole operation in a single process, but inside that macro it would still require taking both of those steps.  

  • Like 1
Link to comment
Share on other sites

18 hours ago, Alaskan_Son said:

The shortcuts only work with a limited subset of the built-in units. I suspect in large part that is due to the formatting limitations imposed by Ruby’s method naming conventions.  It’s probably just too risky to allow custom units to create matching methods when there’s no telling what the name of that unit might be.  

 

This is correct. We don't place restrictions on unit names.

 

20 hours ago, Chopsaw said:

Is there a way to use the rest of the formatting "convert_to(unit: Symbol | String)"  to display the "units" ?

Or do you need to create a complete NumberFormatter for that with unit=("acre") in it ?

 

This method doesn't allow further control over the formatting, but you could try:

 

area.to_s("acre")
  • Like 1
  • Upvote 1
Link to comment
Share on other sites

11 minutes ago, ChiefPlagman said:

This method doesn't allow further control over the formatting, but you could try:

 

area.to_s("acre")

 

By the way, possibly even more handy...this method works when a Measurement is converted to a float as well.  In fact, this even works with feet and inches.

 

@ChiefPlagman, I'm curious if there are any other hidden formatting controls using these seemingly secret string and float arguments that don't require initializing the NumberFormatter?

Link to comment
Share on other sites

54 minutes ago, ChiefPlagman said:
21 hours ago, Chopsaw said:

Is there a way to use the rest of the formatting "convert_to(unit: Symbol | String)"  to display the "units" ?

Or do you need to create a complete NumberFormatter for that with unit=("acre") in it ?

 

This method doesn't allow further control over the formatting, but you could try:

 

area.to_s("acre")

 

That almost works but I don't see any way to get anything other than the default six decimal places which is a bit of a deal breaker.

 

The problem I have with the existing documentation which seems to be quite common is that it is all written by someone who is a Ruby master and there is not distinction between the ruby code and items that need to be substituted into the ruby code.

 

So unless practical examples are given it is really difficult for a novice to figure out.  Someone who already knows ruby likely does not even notice this issue but for someone starting out it would be a lot easier if the items that need to be substituted were another color or italicized or something since ruby uses common words as code.

  • Like 1
Link to comment
Share on other sites

On 12/17/2021 at 1:52 PM, Alaskan_Son said:

I'm curious if there are any other hidden formatting controls

No.

 

On 12/17/2021 at 1:52 PM, Alaskan_Son said:

this method works when a Measurement is converted to a float as well

to_f is the same as convert_to, but the unit argument is optional. If it isn't provided we use the default unit specified in the documentation for that category of Measurement.

 

On 12/17/2021 at 1:32 PM, Alaskan_Son said:

I don't see that one listed anywhere in the documentation. 

I submitted a request for to_s to be added to the documentation.
I'll add to_f too.
Since we allow an extra argument compared to most built-in Ruby classes it seems important.


To the best of my knowledge most Measurement methods that accept a variable amount of arguments will produce an error message that includes the expected number of arguments, as well as what they should be, if too many are provided.
The exceptions should be cases where we delegate to the behavior of the Ruby Float class.

 

On 12/17/2021 at 2:30 PM, Chopsaw said:

for someone starting out it would be a lot easier if the items that need to be substituted were another color or italicized or something

I'll submit a request for this too :)

  • Upvote 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