Simple (I hope) macro question


TSJDesign
 Share

Recommended Posts

I am a complete macro dunce, so please forgive if this is a elementary question.  

 

I would like to make a seemingly simple modification to a "user" macro that ships with x8 - FormattedOpeningWidth.  All I want to do is add a "/" character between the foot and inch results (currently a 3'-6" opening gives a result of 36.  I would like to see 3/6)  I looked at the macro and realized I haven't a clue, so I'm hoping someone here can provide the magic syntax to make this happen.

 

Thank you!

Todd
 

Link to comment
Share on other sites

Todd,

 

Copy/Paste the following as a replacement for the existing:

 

arr = width.round.divmod(12)

arr = "#{arr[0]}#{arr[1].round}"

arr = arr[0]+"/" + arr[1]

 

Or create a new macro with that code. 

 

Characters in a string are numbered 0,1,2,3,4,5......

So arr[0] is the first character, arr[1] is the second, etc.  The 3rd line just puts a (slash) between those 2.

Link to comment
Share on other sites

Joe - thank you so much, worked perfectly!

 

Your explanation is helpful, although macros in their entirety are absolutely baffling to me.  I'm usually pretty good at reverse engineering things, but without even the basic knowledge of syntax, I would not know where to start.

 

Thank you so much for your help - my client will be happy!

 

Todd

Link to comment
Share on other sites

>Characters in a string are numbered 0,1,2,3,4,5......

 

Techncally these are not "characters", it is an array. ...and  divmod produces array of a quotient and modulus. 

There are typed as Float's.

 

See

    http://ruby-doc.org/core-2.3.0/Numeric.html#method-i-divmod

 

One can also do

 

a,b = width.round.divmod(12)

 

I recommend you to create your own extended class Float and save it into 'FloatExtended.rb' under Documents\ChiefArchitect v8\scripts. This will allow You instead of putting dreaded logic in every macro to use include file... 

 

require 'FloatExtended.rb'

//after that you couldimmediately use...

width.to_ftin(16) 

//instead of a giant macro you now can use one liner

Link to comment
Share on other sites

>Characters in a string are numbered 0,1,2,3,4,5......

 

Techncally these are not "characters", it is an array. ...and  divmod produces array of a quotient and modulus. 

There are typed as Float's.

 

Technically you are correct.  But for the amateurs it's sometimes simpler to show a sequence of commands rather than the most elegant programming syntax.  Also, you didn't show the definition of to_ftin that would be needed to put the slash in.

 

I've found that most Chief users (at least on the forum) are very reluctant to learn Ruby. 

Link to comment
Share on other sites

Here is my class FloatExtended.rb to be placed into C:\Users\<name>\Documents\Chief Architect Premier X# Data\Scripts

class Float
    def to_ftin(n=16)
		arr = self.divmod(12)
  	    inch_frac = ((arr[1]-arr[1].floor)*n).round.quo(n)
		result = case inch_frac
		when Rational(1.0)
			"#{arr[0]}'-#{arr[1].ceil}\""
		when Rational(0.0)
			"#{arr[0]}'-#{arr[1].floor}\""
		else
			"#{arr[0].floor}'-#{arr[1].floor} #{inch_frac}\""
		end
		result
    end
	
	def to_inches(n=8)
  	    inch_frac = ((self-self.floor)*n).round.quo(n)
		result = case inch_frac
		when Rational(1.0)
			"#{self.ceil}\""
		when Rational(0.0)
			"#{self.floor}\""
		else
			"#{self.floor} #{inch_frac}\""
		end
		result
	end
end
 

Using it is very simple, this macro would be two liner.

 

require "FloatExtended.rb"

width.to_ftin

 

or

209.to_ftin

 

For your case the line "#{self.floor} #{inch_frac}\"" needs to be changed into "#{self.floor}" + "/" + "#{inch_frac}\""

Link to comment
Share on other sites



        def to_full_inches
		self.round
	end
	
	def to_full_ftin
	    arr = self.round(0).divmod(12)
		"#{arr[0]}'-#{arr[1].round}\"" 
	end

Last two methods to complete the class.

 

So that entire ceiling_height:

 

require "FloatExtended.rb"

(ceiling_elevation-floor_elevation).to_full_ftin + " CLG.HT."

Link to comment
Share on other sites



        def to_full_inches
		self.round
	end
	
	def to_full_ftin
	    arr = self.round(0).divmod(12)
		"#{arr[0]}'-#{arr[1].round}\"" 
	end

Last two methods to complete the class.

 

So that entire ceiling_height:

 

require "FloatExtended.rb"

(ceiling_elevation-floor_elevation).to_full_ftin + " CLG.HT."

 

FWIW, I already have a FloatClass.rb with similar but mine does Metric as well.

Link to comment
Share on other sites

  • 1 month later...

Hey there - 

So I just noticed that the method from the top of the post does not appear deal with openings with components that are not single numbers (for instance a 2'-10" door show as 2/1, and a 12'-6" opening shows up as 1/2). 

 

There was discussion after that post, but unfortunately it was (far) over my head.  Any ideas?

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