Ruby Code custom wall label


IvanCyr
 Share

Recommended Posts

Good day to the Ruby code gurus,

 

I have an interesting idea...at least to me.  I'm building a paired template.  I have a client who would like to have a set of plans that has as-built, demo plans, and the proposed views.  The challenge is that the layout pages are to have as-built walls that show both as-is and then those which are to be demo-ed.  I would prefer NOT to create a separate Demo .plan file to link to the views.  I'm thinking of creating a "SMART" label which will type text "X";s in the label that would overlay the main layer of the demo walls.  I could then assign the unique label to the wall.

 

The height of the text would be set in Ruby code as a function of  the wall main layer width, and the number of X's in the string would be a function of how many of those X's (truncated to the nearest whole number) could then fit in along the entire length of the wall.  The label would be text justified to center.

 

The length of the wall is easily found by %length%.

 

3 problems:

 

1. How do you retrieve the wall main layer thickness.  It is "nested" in "upper_layers" and "[1]" and "thickness".

2. Anyone ever try to generate a string of text a specified number of characters long based on an objects attributes?? No idea how to code this.

3. The text size would ideally be controlled automatically such that the X's (or perhaps the label's corresponding border) would fill the main layer of the wall.

 

Thanks in advance.

 

Ivan

 

Edited to add #3 problem.

 

Link to comment
Share on other sites

Hi Joe,

 

I suspected the same for #3, I would likely set the text via layer...since I could create demo walls for 2x4, 2x6, 8" and 10" stem walls...generally what I use out here for main layers.

 

Any idea to solve #1 and #2 above??

 

Ivan

Link to comment
Share on other sites

1 hour ago, IvanCyr said:

Any idea to solve #1 and #2 above??

  1.  owner.upper_layers[1].thickness.to_s
  2.  you would need to determine the width of the letter "X" (probably external calculations) and divide that into the wall length.  Then convert that to integer and subtract 4 (just to keep it slightly smaller than the width
Link to comment
Share on other sites

Thanks Joe,

I've calculated the width in inches of one "X" in caps.  I simply take the truncated value of (X width multiplied by the wall length). This keeps the label shorter than the wall.

I just don't know how to create the string of X's using the code.  I've been researching since 6 this morning!!!

 

As far as I can tell I need a loop to add X's to a string that will loop as many times as I determine in the function.  The function is the easy part.  How to get Ruby to understand my brain is confusing....or perhaps it is just Ruby who is confused.  She doesn't talk back so I'm still at a loss... :-)

 

I've tried:

 

def multiple_string(str, n) return str*n end

Edited by IvanCyr
To add code example
Link to comment
Share on other sites

I have this so far. 

 

numbers_of_characters = (0.34* length).truncate()

multiple_string('X', (0.34* length).truncate())

 

The first line calculates fine by itself.  The second line causes the error.  If I replace the "(0.34* length).truncate()" with an integer, it works splendid.  I just need it to work smart...

 

Still quite a newbie to this Ruby stuff....

Link to comment
Share on other sites

35 minutes ago, IvanCyr said:

I have this so far. 

 

numbers_of_characters = (0.34* length).truncate()

multiple_string('X', (0.34* length).truncate())

 

The first line calculates fine by itself.  The second line causes the error.  If I replace the "(0.34* length).truncate()" with an integer, it works splendid.  I just need it to work smart...

 

Still quite a newbie to this Ruby stuff....

length in X12 and beyond is a measurement.  You need to convert it to an integer

  • numbers_of_characters = (0.34* length.to_i)
  • multiple_string('X', (0.34* length.to_i))
Link to comment
Share on other sites

Are you essentially creating a series of Xs to represent an existing wall(which is not a CA wall), which is to be demoed?

 

Is there a reason you would not create a different wall type with a different fill and put those on a different layer, and set them to no locate and no room dimension? and then use the wall schedule or create your own?image.thumb.png.36463fa500048e70f1c1b9625061c158.png

I remember running into some problems with doing the two walls types such as you could not offset a wall, and problems with the rendering  where the no locate wall intersected an existing wall, but for 2d it seemed to work pretty well.

 

or why not use CAD polylines with a different fill?

 

I'm trying to figure out what the advantage of using the X's are

 

 

image.png.2ef15d7b8b22f15c3dbd310496fb2b16.png

image.png

Link to comment
Share on other sites

Hi Jason.  This was mostly an exercise to determine the feasibility of the concept; as I haven't been tasked with such a request.  As I stated, it was "an interesting idea".  The client is desiring 3 plan views of each floor: 1. Existing , 2. Demo and 3. Proposed (which ALSO includes the As-built as a reference floor).  I do NOT wish to generate 3 files....max 2; namely the As-built and the Proposed.  I was hoping to be able to buzz around the As-built and use the wall break tool, as needed, and select my walls and set them to my demo type.  However, the wall settings are global, so if you change the fill in one wall, all the walls change.  Therefore, you must change another attribute.  However, just changing a label on the wall, say a continuous 2x4 interior wall where you wish to demo a section, if you change the wall label, the wall will automatically snap to a continuous wall type despite having different wall labels which is a non-starter.  Complicating things, is that I am also using the same As-built information (NOT Demo) in the Proposed as a Reference Floor.

 

The walls don't need to be on the wall schedule so no need to set them as unique walls and I use 3D extensively so don't want to be troubled with "No locate, No room definition" walls interfering with otherwise great 3D renderings.

 

I'm back to the CAD line option....unless someone has found a better solution. 

 

For what it is worth...

Link to comment
Share on other sites

6 hours ago, IvanCyr said:

Hi Jason.  This was mostly an exercise to determine the feasibility of the concept; as I haven't been tasked with such a request.  As I stated, it was "an interesting idea".  The client is desiring 3 plan views of each floor: 1. Existing , 2. Demo and 3. Proposed (which ALSO includes the As-built as a reference floor).  I do NOT wish to generate 3 files....max 2; namely the As-built and the Proposed.  I was hoping to be able to buzz around the As-built and use the wall break tool, as needed, and select my walls and set them to my demo type.  However, the wall settings are global, so if you change the fill in one wall, all the walls change.  Therefore, you must change another attribute.  However, just changing a label on the wall, say a continuous 2x4 interior wall where you wish to demo a section, if you change the wall label, the wall will automatically snap to a continuous wall type despite having different wall labels which is a non-starter.  Complicating things, is that I am also using the same As-built information (NOT Demo) in the Proposed as a Reference Floor.

 

The walls don't need to be on the wall schedule so no need to set them as unique walls and I use 3D extensively so don't want to be troubled with "No locate, No room definition" walls interfering with otherwise great 3D renderings.

 

I'm back to the CAD line option....unless someone has found a better solution. 

 

For what it is worth...

It seems to me that you can use different layersets to create different views of the same floor, then send each one to the layout.

Link to comment
Share on other sites

Yes Perry, but walls cannot be drawn over each other therefore you are limited in options unlike other items.  Cabinets act in a similar manner in Chief...

 

I'm open to options but putting walls on different layers and having it look "nice" in 2D and 3D is quite a stretch....if not impossible.  I'm looking to save time....and make a template efficient for a clients desires.  If CAD on a layer is the  easiest and faster method given the limitations (as you've stated above), then it is an easy decision.

 

Link to comment
Share on other sites

6 hours ago, IvanCyr said:

I'm back to the CAD line option....unless someone has found a better solution. 

 

it was more curiosity than anything else as i do these on a small scale rather frequently, but I tend to only show existing and proposed walls, not the demo (occasionally when asked I will and then it is 2 plans, existing/demo/proposed(2d walls only) & proposed(without all the other walls)). But then I am sitting there editing two files for the same wall change. So I'm curious to see how you make out

 

 

Link to comment
Share on other sites

My thoughts for whatever they're worth to you:

  1. Abandon the idea of using Ruby and wall labels.  I think you'll find its just a time sync that ultimately won't work or it will just work like crap even if you manage to make it somewhat functional.
  2. I personally think we try to hard sometimes to remove some step and the resulting solution is more problematic than the original problem.  In this particular case, I think 3 plans is the most effective solution.  Having said that...
  3. Don't forget that we have a Wall Hatching tool that can be used in lieu of CAD boxes or polylines. 
  4. Also don't forget that you can place different walls on different layers, that we can use different layer sets for our as-built reference, and that those layer sets can have fills or not, and can be drawn on top or bottom.  It may be that you can layer your as-built and proposed plan a little more effectively to simulate your demo walls. 
  • Upvote 1
Link to comment
Share on other sites

Hi Michael,

 

Yes indeed...abandoned. As you stated, the solution complexity was greater than the problem.  It was a good learning exercise in Ruby, label, and layer control.  The problem, as I see it, is that the client desires different fills in the same wall.  You can't do that (as far as I can tell)...so you're left with CAD overlays or Wall Hatching.

 

Thanks for chiming in....your comments are always appreciated. :-)

 

Ivan

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