List of Callable Ruby Object Attributes


Allen43
 Share

Go to solution Solved by solver,

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

  • Solution
15 minutes ago, Allen43 said:

If you see something I could improve on, I am open to suggestions as long as they have a good explanation with them.

 

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?

 

And no, Interiors does not have the ruby console.

 

h1.thumb.png.fec92a24dff34b897f835d2cd342f87b.png

 

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

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

 

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

1 minute ago, Allen43 said:

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.

 

Me too. I just Google, like I did just now for the case statement, because I never remember how Ruby does things. 

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

  • Member Statistics

    32900
    Total Members
    9156
    Most Online
    MicahR
    Newest Member
    MicahR
    Joined
  • Similar Content

    • By Scogginator
      Is there a way to write a custom command to auto-place lights?
       
      I've used chat GTP to write code that I'd like to utilize. I have attached a word file and pdf that I need proof read and corrected. I can have that done.
       
      Below is the code, but I'm not sure if it will format correctly:
      Sub PlaceLights()
          'Ask the user to select the room size and ceiling height
          Dim roomWidth As Double
          Dim roomLength As Double
          Dim roomHeight As Double
          roomWidth = InputBox("Enter the width of the room in feet:")
          roomLength = InputBox("Enter the length of the room in feet:")
          roomHeight = InputBox("Enter the height of the room in feet:")
          
          'Calculate the square footage of the room based on user input
          Dim roomArea As Double
          roomArea = roomWidth * roomLength
          
          'Determine the recommended lighting level for the room based on the ceiling height and room type
          Dim lightLevel As Double
          Select Case roomHeight
              Case Is <= 8
                  lightLevel = 10
              Case Is <= 9
                  lightLevel = 20
              Case Is <= 10
                  lightLevel = 30
              Case Is <= 12
                  lightLevel = 40
              Case Else
                  MsgBox "Invalid ceiling height"
                  Exit Sub
          End Select
          
          'Calculate the number of lights needed based on the room size and the recommended spacing
          Dim lightSpacing As Double
          If roomArea <= 100 Then
              lightSpacing = 48
          ElseIf roomArea <= 225 Then
              lightSpacing = 64
          ElseIf roomArea <= 400 Then
              lightSpacing = 80
          Else
              lightSpacing = 96
          End If
          Dim lightCount As Integer
          lightCount = Application.RoundUp((roomWidth + roomLength) / lightSpacing, 0)
          
          'Determine the optimal spacing for the lights based on the room size and ceiling height
          Dim xOffset As Double
          Dim yOffset As Double
          If roomWidth >= roomLength Then
              xOffset = lightSpacing
              yOffset = lightSpacing * roomLength / roomWidth
          Else
              xOffset = lightSpacing * roomWidth / roomLength
              yOffset = lightSpacing
          End If
          
          'Place the lights in a rectangular or square pattern within the room
          Dim lightType As String
          lightType = InputBox("Enter the light diameter (4 or 6):")
          Dim x As Integer
          Dim y As Integer
          Dim light As Object
          For x = 1 To lightCount
              For y = 1 To lightCount
                  Set light = ActiveDocument.CreateLight("Recessed Can Light", lightType & """", "General")
                  light.Move (x - 1) * xOffset, (y - 1) * yOffset, roomHeight - 48
              Next y
          Next x
          
          'Generate a report or summary of the lighting plan for the room
          Dim report As String
          report = "Room Size: " & roomWidth & " ft x " & roomLength & " ft" & vbCrLf
          report = report & "Ceiling Height: " & roomHeight & " ft" & vbCrLf
          report = report & "Recommended Light Level: " & lightLevel & " lux" & vbCrLf
          report = report & "Number of Lights: " & lightCount ^ 2 & vbCrLf
          report = report & "Light Spacing: " & lightSpacing & " in" & vbCrLf
          report = report & "Light Type: " & lightType & """ Recessed Can Light" & vbCrLf
          MsgBox report
       
       
      Any help would be appreciated.
       
      Thanks,
       
      Jeff
      Sub PlaceLights.docx Sub PlaceLights.pdf
    • By gravattedesign
      Assistance please.
      How can I set imported drawings from the PLAN FILE to have NO BOX BORDER and NO LABEL when sent to Layout?? I have to turn these off with every import to layout. Settings in layout doesnt help since the Template Sheet border in LAYOUT, 0 sheet, uses LAYOUT BOX BORDERS layer for default border line work for that sheet.
       
      Thanks for any help or insight for best practices. PIC attached of a recently imported Elevation (top Left) that illustrates the box border and Label

    • By Allen43
      I have been trying to reduce the time I spend on a design, and I realized that there are a few groups of cabinets and panels that I use a lot. I would like to save these cabinets as a group and place them all at once. However, I still need them to be individual cabinets for schedule and modularity purposes. It seems like this is out of Chief's current reach. I just wanted to make sure this wasn't possible before adding it to the suggestions forum.
       
      Oh before I forget an example of when I would want this. Almost every kitchen I design has a cabinet above a fridge supported by two full length panels on either side. I would like to place both panels and the cabinet at the same time. And even the fridge if possible. 
    • By Allen43
      I'll new to Chief and have learned that this form might be one of the best resources I have ever used. I am trying to streamline my design process and to do that I would love to be able to change cabinet ends to finished or paneled faster and easier. I tried to make a SP to do this, but I couldn't figure it out. I also thought that there might be a way to do this with macros is a SP, but I know even less about macros than I do Chief.
       
      Any help is appreciated, and if it's not possible that's fine I'll know not to spend more time on this.
    • By Allen43
      I am new to Chief but so far I love it. Far better than my previous software. So far, the only problem that I have had is using macros to create a custom label for cabinets.
       
      All I am trying to do is get chief's labels to match my manufacture nomenclature. I know I could manually change it on every cabinet, but that seems like to much work and honestly a waste of time. So could someone give me some help. Either a bit of a guide on custom macros and some recourses and documentation (which I, for the life of myself, can't find), or maybe a working-ish or example macro.
       
      Some examples:(chief nomenclature, needed nomenclature)
      3DB24, B3D24
      U242484L, T2484L
      FHB24L, BF24L
       
      Thanks in advance for the help! And if I didn't give enough information or if there is a better way to go about this, please let me know.
       
      Oh, almost forgot. I am running Interiors x14.