Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New Coder
    Join Date
    Dec 2009
    Posts
    71
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Add method to existing class

    I use Sketchup's Ruby API to manipulate model components. I am using one class called Bone which does not have a method for giving a name to each bone (part of skeletal animation). I am more familiar with javascript than Ruby so would be grateful for some newby oriented advice about how to make and implement a naming method. Thanks

  • #2
    New Coder
    Join Date
    May 2006
    Posts
    21
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Without an example of the code I don't know what the Bone object implements, this is how you would define and instance method on the bone object:

    Code:
    class Bone
      def give_name(name)
        # manipulate the name here
      end
    end
    If you post up the Bone class code it would help us to be able to shoe you how to actually change/assign the name. You may simply be able to do something like this:

    Code:
    class Bone
      attr_accessor :name
    end
    Which would create getter and setter methods for the @name attribute
    Flexible UK web hosting solutions for designers and developers
    PHP5, Ruby on Rails, MySQL, spam and virus filtering
    UK Hosting from Media72, Media72 on twitter

  • #3
    New Coder
    Join Date
    Dec 2009
    Posts
    71
    Thanks
    4
    Thanked 0 Times in 0 Posts
    Thanks for the the reply. I'm onto something else but will return soon to try out your suggestions. Thanks

  • #4
    New Coder
    Join Date
    Dec 2009
    Posts
    71
    Thanks
    4
    Thanked 0 Times in 0 Posts
    Here's the file. It is not made by me, but I want to use it as a required file to set up a skeleton. I need to give the bones names in my own code so that I can find and rotate them.

    I am sure what you noted is fine but I am still not sure how to implement it.

    Thanks
    Attached Files Attached Files

  • #5
    New Coder
    Join Date
    Dec 2009
    Posts
    71
    Thanks
    4
    Thanked 0 Times in 0 Posts
    ... and a pic.
    Attached Thumbnails Attached Thumbnails Add method to existing class-skel-progress.gif  

  • #6
    New Coder
    Join Date
    Dec 2009
    Posts
    71
    Thanks
    4
    Thanked 0 Times in 0 Posts
    Code:
    class Bone
      attr_accessor :name
    end
    Just figured out how to fit it in - works great! Thanks

  • #7
    New Coder
    Join Date
    Dec 2009
    Posts
    71
    Thanks
    4
    Thanked 0 Times in 0 Posts
    ... if you want to add methods to a class someone else has created. In my case, the original author had no need to name instances, but I did because I wanted to identify and animate each

    ... that was a long time ago!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •