List of Callable Ruby Object Attributes


Allen43
 Share

Recommended Posts

I have returned to this forum once again in seek some help with ruby and macros.

 

I have been working on a macro to automate cabinet labels. So far I have a mostly working macro, but I feel like my hands are tied and my eyes are closed. First of all the documentation on chief implementation of ruby and its capabilities it really lacking. And second, I don't have the Ruby terminal. I think this is because I am running Interiors, but am not sure as all Chief says is that there is limited use of Ruby in this version.

 

Anyways, right now I would love to have a list of all callable object attributes. I honestly don't even know if that is the right name for what I am looking for. I am trying to find a list of what info I can scrape from a cabinet. So, what can I put after obj. (ie. obj.width, obj.type)? I think I could find this by running the selected.names command in the terminal, but I have no way of knowing.

 

This is my current macro. It is built from parts of a macro from @MarkMc and whatever I have been able to come up with from random trial and error. If you see something I could improve on, I am open to suggestions as long as they have a good explanation with them. Thanks in advance!

 

Macro:

obj = owner

obj = referenced unless referenced.nil?

obj.depth

 

type = obj.type.to_s

 

nf = NumberFormatter.new

nf.unit = 'in'

nf.use_fractions = true

nf.show_unit = false

nf.apply(obj.depth)

 

standard_size = 24.0 if type == 'base_cabinet'

standard_size = 12.0 if type == 'wall_cabinet'

standard_size = 24.0 if type == 'full_height_cabinet'

 

depth = nf.apply(obj.depth) if obj.depth.to_f != standard_size

 

standard_size_height = 36 if type == 'base_cabinet'

standard_size_height = 0.0 if type == 'full_height_cabinet'

 

height = nf.apply(obj.height) if obj.height.to_f != standard_size_height

 

width = nf.apply(obj.width)

 

nomen = 'B' if type == 'base_cabinet'

nomen = 'W' if type == 'wall_cabinet'

nomen = 'T' if type == 'full_height_cabinet'

 

hinging = owner.door_swing

label = ""

label << nomen << width.to_s << height.to_s << depth.to_s << hinging

 

p label

 

Link to comment
Share on other sites

Here's a macro you can import and then use to check what NVPs are available for whatever object you select.  In order to use it:

  • select an object
  • open TMM and select the _Object_properties_expanded_sorted_wo_default macro.
  • all of the NVPs for that object will be listed in the lower right panel.

This is one of the most important tools I have for creating macros.

 

Object Properties.json

Link to comment
Share on other sites

2 minutes ago, solver said:

 

You might say what you are doing in your macro, and it's probably helpful to document your code (I know it is for me) so you can understand what you did in a year when you need to make a change.

Yeah, I would love to but have not found a way to comment out a line. I know it has to be simple but every time that I look it up I get ruby implantations in a IDE and from what I can tell non of those methods work in chief's ruby implementation.

5 minutes ago, solver said:

 

You might say what you are doing in your macro, and it's probably helpful to document your code (I know it is for me) so you can understand what you did in a year when you need to make a change.

 

Do you know about the object_properties macro?

 

No I did not, but I will definantly check it out now.

Link to comment
Share on other sites

6 minutes ago, Joe_Carrick said:

Here's a macro you can import and then use to check what NVPs are available for whatever object you select.  In order to use it:

  • select an object
  • open TMM and select the _Object_properties_expanded_sorted_wo_default macro.
  • all of the NVPs for that object will be listed in the lower right panel.

This is one of the most important tools I have for creating macros.

 

Object Properties.json 3.61 kB · 0 downloads

Thank you!! I will give this a look, but from the name it seems like exactly what I have been looking for.

Link to comment
Share on other sites

2 minutes ago, solver said:

You are testing the same value multiple times. I'd consolidate like this. This isn't complete, just done to give you an idea.

 

case obj.type.to_s

when 'base_cabinet'

  standard_size = 24.0

  standard_size_height = 36

  nomen = 'B'

when 'wall_cabinet'

  standard_size = 12.0

  nomen = 'W'

else

  standard_size = 0

  nomen = 'error'

end

 

Thank you!!! I have been dying without when and else statements. Believe it or not, but I do know how to code in other languages. I don't know why this one is throwing me for such a loop.

Link to comment
Share on other sites

5 hours ago, Allen43 said:

I would love to but have not found a way to comment out a line

 

A hashtag works in Chief.......

 

#=================================================
#
# MACRO EDITED/CREATED BY MICK @ MHD

#=================================================
# All Code "found" on the CA Forums and altered to suit as needed
# Credits to Eric (Solver), Michael (AlaskanSon) and Joe_Carrick                    
#=================================================
#

#=================================================
#Initalise Macro

referenced ? obj= referenced : obj=owner
result = ""
 

Link to comment
Share on other sites

Here's my version of the macro.

 

###################################

# Macro Name: cab_label

#   OBJECT type width depth height swing

###################################

 

referenced ? obj = referenced : obj = owner

 

slabel = ""

slabel << obj.type[0].upcase.gsub("F","T")  # convert Full to Tall

slabel << obj.width.to_f.round(0).to_s

slabel << obj.depth.to_f.round(0).to_s

slabel << obj.height.to_f.round(0).to_s

slabel << obj.door_swing

 

Nothing else is required 

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