TSJDesign

Simple (I hope) macro question

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
 

Share this post


Link to post
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.

Share this post


Link to post
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

Share this post


Link to post
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

Share this post


Link to post
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. 

Share this post


Link to post
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}\""

Share this post


Link to post
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."

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

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?

Share this post


Link to post
Share on other sites

Todd, take a look at a code I posted, specifically to_ftin. Replace - with /. Or use the full class I supplied. E.g. width.to_ftin...

B

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

  • Member Statistics

    28868
    Total Members
    9156
    Most Online
    snakes911
    Newest Member
    snakes911
    Joined
  • Similar Content

    • By SteveByars
      Some objects, like GFCI's, toilets with a handle, or kitchen faucets with a lever control are tedious to locate. When inserting them into a plan they are located based on the center of the symbol, including the 'GFCI' label or the side handle. Is there a way to redefine the 2D insertion point of these symbols?  Thanks!
    • By KTransue
      Anyone know if there is a text macro that reflects the name of a "Saved Plan View" attached to a layout window view port?  I've looked, and searched ChiefTalk, and even a general Google search, but I'm not finding anything.  Am I missing the obvious?
    • By ccarpenter18
      In X12 I've noticed that when using Structural Member Reporting in a material list, the price column in the list does not appear to be sensitive to whether a "per unit" or "per length" calculation is being performed by the material list.  In both cases, the material list appears to use the same Price variable in the Component Panel of each object.  Does anyone know of some Ruby scripting that could be used to correct this?  Off hand, I'm thinking of a macro inserted into the Price variable on the Component Panel of each structural member that would use the Material List row context to report a price that depends on how the row wants to use the Price.
    • By wjmdes
      OK, so today I learned that Legacy is just a fancy term for obsolete.  See, I do know how to search  
       
      I have numerous macros, from others and some I wrote.  Has there been any enhanced documentation regarding what "migrating" is going to do to my macros and what I can expect? Or how to fix issues? Is this going to put the brakes on my workflow?  I know enough to write small macros for menial tasks, but I do not have an extended knowledge.
       
      Or is this just not a big deal?
       
       
    • By kylejmarsh
      Wondering if there's a way to drop the '0' which is generated in front of the schedule numbers. It adds size to my labels and most of the time there are less than 10 items so it wouldn't be confusing - but I haven't been able to find any options where we can omit this automatically generated zero.
       
      Anybody have any tips or insight?