SketchUcation Plugin Store

 

 

[CityGen] Trying to use City_Gen.module_path

Moderator: Jim

[CityGen] Trying to use City_Gen.module_path

Postby Chris Fullmer » Thu Jun 18, 2009 9:37 pm

I'm sure this is fundamental ruby 101 question and I'm being dense....so nothing new!

I want to make a variable with the path to the "building" folder (not in the program yet, its something I'm playing with). So I figured I could do this:
path = City_Gen.module_path
path.concat "/buildings"


But everytime I run that, it keeps adding another /buildings onto the end. So I get:

C:/Program Files/Google/Google SketchUp 7/Plugins/citygen/modules/buildings/buildings/buildings/buildings/buildings/buildings/buildings

I figure that each time I ran it, it would return the path, and so the concat would just add /buildings onto the end of the path. I wasn't expecting it to actually modify the @module_path variable.

So what would be the correct way to use City_Gen.module_path so I could append my buildings folder onto it, and not change the @module_path and mess up everything else that depends on that variable remaining constant.

Chris
Lately you've been tan, suspicious for the winter.
All my Plugins I've written
User avatar
Chris Fullmer
SketchUp Team
 
Posts: 6758
Joined: Wed Nov 21, 2007 3:21 am
Location: Davis, CA
Name: Chris Fullmer
Operating system: Windows
SketchUp version: 8
License type: Pro
SketchUp use: landscape architecture
Level of SketchUp: Advanced

Re: Trying to use City_Gen.module_path

Postby thomthom » Thu Jun 18, 2009 9:49 pm

hm... taht's odd.

I thought ruby made a copy when you used the =

What happens if you do: path = City_Gen.module_path + "/buildings" ?
Thomas Thomassen — SketchUp Monkey & Coding addict
List of my plugins and link to the CookieWare fund
User avatar
thomthom
Global Moderator
 
Posts: 17907
Joined: Tue Nov 13, 2007 12:47 pm
Location: Trondheim, Norway
Name: Thomas Thomassen
Operating system: Windows
SketchUp version: 2013
License type: Pro
SketchUp use: architecture
Level of SketchUp: Advanced

Re: Trying to use City_Gen.module_path

Postby Chris Fullmer » Thu Jun 18, 2009 9:52 pm

Ahh, yes that works. I so rarely work with strings, its like my mind turns to mush when I try. Thanks Thom!

Chris
Lately you've been tan, suspicious for the winter.
All my Plugins I've written
User avatar
Chris Fullmer
SketchUp Team
 
Posts: 6758
Joined: Wed Nov 21, 2007 3:21 am
Location: Davis, CA
Name: Chris Fullmer
Operating system: Windows
SketchUp version: 8
License type: Pro
SketchUp use: landscape architecture
Level of SketchUp: Advanced

Re: Trying to use City_Gen.module_path

Postby tbd » Thu Jun 18, 2009 9:54 pm

Code: Select all
path = File.join(City_Gen.module_path,"buildings")
SketchUp Ruby Consultant | Podium 1.x developer
http://plugins.ro
User avatar
tbd
 
Posts: 1018
Joined: Wed Nov 14, 2007 10:47 am
Location: Romania
Name: TBD

Re: Trying to use City_Gen.module_path

Postby thomthom » Thu Jun 18, 2009 9:57 pm

FYI; if you do a lot of string processing then you might want to use single quotes strings instead of double quoted string. Double quoted strings allows variables inside it and require more processing than single quoted. I'm not that familiar with the performance difference in Ruby, but it's the same in PHP. I've done quite a bit of PHP programming for making websites and then it's always string manipulations so I got into the habit for always using single quoted unless I need variables in my string.
The Su plugins there's usually not that much string processing going on, so I don't think it'll matter that much.
Thomas Thomassen — SketchUp Monkey & Coding addict
List of my plugins and link to the CookieWare fund
User avatar
thomthom
Global Moderator
 
Posts: 17907
Joined: Tue Nov 13, 2007 12:47 pm
Location: Trondheim, Norway
Name: Thomas Thomassen
Operating system: Windows
SketchUp version: 2013
License type: Pro
SketchUp use: architecture
Level of SketchUp: Advanced

Re: Trying to use City_Gen.module_path

Postby thomthom » Thu Jun 18, 2009 9:58 pm

TBD wrote:
Code: Select all
path = File.join(City_Gen.module_path,"buildings")

Ah. :)
Thomas Thomassen — SketchUp Monkey & Coding addict
List of my plugins and link to the CookieWare fund
User avatar
thomthom
Global Moderator
 
Posts: 17907
Joined: Tue Nov 13, 2007 12:47 pm
Location: Trondheim, Norway
Name: Thomas Thomassen
Operating system: Windows
SketchUp version: 2013
License type: Pro
SketchUp use: architecture
Level of SketchUp: Advanced

SketchUcation One-Liner Adverts

by Ad Machine » 5 minutes ago

Not a Premium Member yet? Check out the great time-limited deal we are offering.

Ad Machine
Robot
 
Posts: 2012


Return to City Generator

Who is online

Users browsing this forum: No registered users and 0 guests