SketchUp RUBY API Wishlist [way of coding wishes, please]

Re: SketchUp RUBY API Wishlist [way of coding wishes, please]

Postby thomthom » Wed Jun 17, 2009 9:43 am

Being able to set Layer colour.
0
Thomas Thomassen — SketchUp Monkey & Coding addict
List of my plugins and link to the CookieWare fund
User avatar
thomthom 
PluginStore Author
PluginStore Author
 

Re: SketchUp RUBY API Wishlist [way of coding wishes, please]

Postby thomthom » Tue Jun 23, 2009 9:48 am

* Being able to set Material name.
* Being able to delete materials.
* Being able to delete ComponentDefinitions
0
Thomas Thomassen — SketchUp Monkey & Coding addict
List of my plugins and link to the CookieWare fund
User avatar
thomthom 
PluginStore Author
PluginStore Author
 

Re: SketchUp RUBY API Wishlist [way of coding wishes, please]

Postby TIG » Tue Jun 23, 2009 10:20 am

You can delete a definition's instances and then that individual definition from the component-browser thus:
Code: Select all
model.start_operation("Delete Instances and Definition")
  definition.instances.each{|instance|instance.erase! if instance.valid?}
  # this 1st step is optional since all instance become nil anyway when the definition is emptied
  definition.entities.erase_entities(definition.entities.to_a)
model.commit_operation

Assumes you have set model and definition... It empties a definition and therefore it disappears off the browser listing. It must be inside an operation to work.


PS: You can delete a material BUT it's pretty convoluted. I'll publish a script for it shortly...
0
TIG
User avatar
TIG 
Global Moderator
 

Re: SketchUp RUBY API Wishlist [way of coding wishes, please]

Postby thomthom » Tue Jun 23, 2009 10:30 am

I've not had 100% success with deleting definitions like that. I seemed to run into bugsplats. But I'll do new tests.



As for materials, I seen how V-Ray for Sketchup renames and deletes materials:
Deleting: iterate the whole model and remove the material - then apply unused materials to dummy groups and purge.

Rename: Create new material identical to old with new name - iterate and replace the old material with new. Then run the Delete method.

Ugly hacks which I'd rather not use. When model grows in size this just bogs down.
0
Thomas Thomassen — SketchUp Monkey & Coding addict
List of my plugins and link to the CookieWare fund
User avatar
thomthom 
PluginStore Author
PluginStore Author
 

Re: SketchUp RUBY API Wishlist [way of coding wishes, please]

Postby TIG » Tue Jun 23, 2009 11:28 am

viewtopic.php?p=166978#p166978 has material.delete method - I've streamlined it as much as possible ???
0
Last edited by TIG on Tue Jun 23, 2009 11:51 am, edited 1 time in total.
TIG
User avatar
TIG 
Global Moderator
 

Re: SketchUp RUBY API Wishlist [way of coding wishes, please]

Postby TIG » Tue Jun 23, 2009 11:51 am

I've also made the equivalent layer.delete method here viewtopic.php?p=166985#p166985 ...
0
TIG
User avatar
TIG 
Global Moderator
 

Re: SketchUp RUBY API Wishlist [way of coding wishes, please]

Postby TIG » Wed Jun 24, 2009 2:38 pm

I've also made a material.name="new_name" method here viewtopic.php?p=167219#p167219 ...
0
TIG
User avatar
TIG 
Global Moderator
 

Re: SketchUp RUBY API Wishlist [way of coding wishes, please]

Postby TIG » Fri Jun 26, 2009 10:12 am

material.name="new_name" method now v1.1 - here viewtopic.php?p=167219#p167219
Temp folder fixed for Mac users...
0
TIG
User avatar
TIG 
Global Moderator
 

Re: SketchUp RUBY API Wishlist [way of coding wishes, please]

Postby narongwit12 » Tue Jul 14, 2009 3:57 am

Be able to track the shadow area on each face. This could make the calculation of shading possible for energy simulation.
0

narongwit12 
 

Re: SketchUp RUBY API Wishlist [way of coding wishes, please]

Postby •BTM » Fri Aug 28, 2009 4:03 pm

• to have the 5th (optional) argument for write_image as 'Transparent Background' if the file type is .png
0

•BTM 
PluginStore Author
PluginStore Author
 

Sketchup::load

Postby Dan Rathbun » Tue Feb 09, 2010 2:51 pm

Sketchup::load

The Sketchup::load method does NOT expose the wrap argument, so we can specify wrap=true for rbs scripts.

For some unknown reason, the Google team defeated, or just didn't pass the 2nd argument (wrap) on to the aliased standard load, when they overrode it to handle rbs decrypting.

Please fix this!
_
0
    I'm not here much anymore. But a PM will fire email notifications.
    User avatar
    Dan Rathbun 
    PluginStore Author
    PluginStore Author
     

    Re: SketchUp RUBY API Wishlist [way of coding wishes, please

    Postby Pout » Fri May 07, 2010 10:34 am

    Here is my list:

    * Tig, although your solutions on material.name=, layer.delete, material.delete are good, it seems to me it would be much easier to just have them in the API. So i second the proposals of ThomThom

    * Also i second the proposal of Morisdov concerning the add_framechange_observer not firing when creating movies or when working in layout. It should fire there to.

    * make the entity.id consistent throughout different SU sessions (it changes now from time to time)
    * it would be great if you could just select an entity based on a parameter (eg. entity.id) without looping all the entities in the model
    * being able to access the font/size and other parameters of a text
    * make a difference between the execution of scripts and the interface so it is possible to incorporate a 'stop script' button for example. Now the interface freezes as long as scripts are running. This makes users believe the execution of the script has halted and Sketchup has stopped working.
    * ...more to come
    0

    Pout 
     

    Re: SketchUp RUBY API Wishlist [way of coding wishes, please

    Postby thomthom » Fri May 07, 2010 11:09 am

    Pout wrote:* Tig, although your solutions on material.name=, layer.delete, material.delete are good, it seems to me it would be much easier to just have them in the API.

    And it would be faster.

    Pout wrote:* make the entity.id consistent throughout different SU sessions (it changes now from time to time)

    Ditto!

    Pout wrote:* it would be great if you could just select an entity based on a parameter (eg. entity.id) without looping all the entities in the model

    Ditto. If you have a script that requires observers attached to some objects one want these to be reattached when the model is loaded. Currently one has to iterate the whole model to find the entities, and one has to attach an attribute to be able to find the correct one - which means string comparisons which are really slow.
    So a better way to directly reference entities across sessions would be a great addition.

    Pout wrote:* make a difference between the execution of scripts and the interface so it is possible to incorporate a 'stop script' button for example. Now the interface freezes as long as scripts are running. This makes users believe the execution of the script has halted and Sketchup has stopped working.

    while true
    puts 'Ditto!'
    end
    0
    Thomas Thomassen — SketchUp Monkey & Coding addict
    List of my plugins and link to the CookieWare fund
    User avatar
    thomthom 
    PluginStore Author
    PluginStore Author
     

    Get||Set Layer Material & Color

    Postby Dan Rathbun » Sun Jun 20, 2010 9:02 am

    thomthom wrote:Being able to set Layer colour.

    ..and also a "getter" method to read the color.

    Actually when you manually click the color button in the Layers dialog, the Edit Material dialog appears. If you choose 'Use texture image' and assign a texture file, the layer will be displayed with that texture over the layer color, when 'Color by Layer' is true, and rendering mode is 'Shaded with Textues'.

    Issues:
    (1) Technically, Layers have a material attribute that holds a Sketchup::Material object.
    (2) These material objects ARE saved with the model, but NOT accessible thru the API.
    (3) When a layer is assigned a texture, it does not appear in the "In Model" Materials Collection, and it should as well as allow us to assign a name (thru the layer's material object.)
    In the UI manual mode the new material could be given a temporary name equal to the Layer name, so the user could manually rename it thru the Materials Browser, or we could name it in a subsequent ruby statment like:
    model.materials['Layer3'].name='PolishedWood'
    We should also then be able to go totally automatic thru the API, thus:
    mat = model.materials.add('PolishedWood')
    mat.texture = 'wood/polished.png'
    mat.color = [195,144,86]
    model.layers['Layer3'].name = 'Surface'
    model.layers['Surface'].material = 'PolishedWood'
    model.rendering_options['DisplayColorByLayer'] = true

    Later on getting a layer's color, we could do:
    surfaceColor = model.layers['Surface'].material.color
    and setting it to some other color:
    surfaceColor = [127,127,200]
    model.layers['Surface'].material.color = surfaceColor
    [*]

    ** So what we really need is the Sketchup::Layer object's material attribute getter and setter methods exposed in the API, along with the manual UI naming hack.


    EDIT: [*] (2010AUG05) Added missing "wish" statement to set layer color.
    0
    Last edited by Dan Rathbun on Thu Aug 05, 2010 11:05 am, edited 2 times in total.
      I'm not here much anymore. But a PM will fire email notifications.
      User avatar
      Dan Rathbun 
      PluginStore Author
      PluginStore Author
       

      Re: SketchUp RUBY API Wishlist [way of coding wishes, please

      Postby Pout » Thu Jul 29, 2010 10:52 am

      does anyone know if any of the remarks here will be taken into consideration in a new version?
      0

      Pout 
       

      Re: Sketchup::load

      Postby Dan Rathbun » Sat Jul 31, 2010 11:10 pm

      Dan Rathbun wrote:Sketchup::load

      The Sketchup::load method does NOT expose the wrap argument, so we can specify wrap=true for rbs scripts.

      For some unknown reason, the Google team defeated, or just didn't pass the 2nd argument (wrap) on to the aliased standard load, when they overrode it to handle rbs decrypting.

      Please fix this!_

      Taking this a step further.

      Since the rbs code blocks are eval'd, and Sketchup.load is an override (redefinition,) just pass the 2nd argument to Sketchup.load (if given,) on as the 2nd argument to the eval method.

      That way developers can instantiate a binding() to their custom namespace(s), and have the code evaluated within that scope.

      This can also give the GSUT the opportunity to protect some Google namespaces, within the argument validation block of the Sketchup.load method (ie: raise a custom "NotAllowedError" exception.)
      0
        I'm not here much anymore. But a PM will fire email notifications.
        User avatar
        Dan Rathbun 
        PluginStore Author
        PluginStore Author
         

        Re: SketchUp RUBY API Wishlist [way of coding wishes, please

        Postby Dan Rathbun » Thu Aug 05, 2010 11:04 am


        EDITED: Get||Set Layer Material & Color
        Added missing "wish" statement to set Layer color in the example I gave (the last statement.)
        0
          I'm not here much anymore. But a PM will fire email notifications.
          User avatar
          Dan Rathbun 
          PluginStore Author
          PluginStore Author
           

          Re: SketchUp RUBY API Wishlist [way of coding wishes, please

          Postby kwalkerman » Tue Aug 10, 2010 2:44 pm

          Seconded on the Layers usability, also, it would be great to be able to do:

          Layers.active_layer
          Layers[layer] = active

          A consistent entityID would be awesome. The entity should maintain the ID if it is deleted, and then undeleted as well.

          Pages:

          In addition to retaining information on which layers are on and off, should also be able to retain the active layer for each page.

          --
          Karen
          0

          kwalkerman 
           

          Re: active Layer via the Sketchup::Layers class

          Postby Dan Rathbun » Tue Aug 10, 2010 4:46 pm

          kwalkerman wrote:Seconded on the Layers usability, also, it would be great to be able to do:

          Layers.active_layer

          That can already be done:
          Sketchup.active_model.active_layer
          .. as it's a property of the model (Sketchup::Model class.)

          see API: Model.active_layer

          kwalkerman wrote:Layers[layer] = active

          Will not work because there is no .= method defined for the Sketchup::Layer class. (You'd just be calling Ruby's internal hardcoded refererence assignment operator, which could set the layer reference on the left of the operator, to any kind of Ruby object. A bad idea, if it doesn't immediately cause an exception.)
          This why the .new constructor is "hidden" (or made private,) and we create layers thru the collection class' .add method.

          Sketchup.active_model.active_layer=layers['mylayername']
          .. again, a property of the model (Sketchup::Model class.)

          see API: Model.active_layer=

          You CAN get a SKP DOM object's parent by using the .parent method. The model is the layer collection's parent, in the SKP doucment heirarchy. Where layers is the model's Sketchup::Layers class instance:
          this_layer = layers.parent.active_layer

          But, since each model instance, has an instance of a Sketchup::Layers class object, you'd think it (the Layers collection,) should also know which one of it's elements was active.
          A simple Ruby patch for the Layers class:
          Code: Select all
          class Sketchup::Layers
            unless method_defined?('active')
              def active
                self.parent.active_layer
              end # def active
            end
            unless method_defined?('current')
              alias_method('current','active')
            end
            unless method_defined?('active=')
              def active=(arg)
                if arg.class==String || arg.kind_of?Integer
                  self.parent.active_layer=self[arg]
                elsif arg.class==Sketchup::Layer
                  self.parent.active_layer=arg
                else
                  raise(TypeError,'Sketchup::Layer, String, or Integer expected.')
                end
              end # def active=
            end
            unless method_defined?('current=')
              alias_method('current=','active=')
            end
          end # class extension
          EDIT:
          • added aliases
          • fixed method defintion tests
          Note: The reason I do not call
          Sketchup.active_model.active_layer (in the patch,) is to accomodate multi-model environment on the Mac, where the active model may not be the one a script is working on.
          ADD: This can be extended to the Sketchup::Layer class, so that a layer can return (boolean) whether it is the active layer or not.
          Code: Select all
          class Sketchup::Layer
            unless method_defined?('active?')
              def active?
                # .equal? returns true ONLY if receiver and arg have same object_id
                self.equal?( self.parent.parent.active_layer )
              end # def active?
            end
            unless method_defined?('current?')
              alias_method('current?','active?')
            end
            #
            unless public_methods(false).include?('eql?')
              # only override if it hasn't yet been redefined
              def eql?(arg)
                if arg.class==Sketchup::Layer
                  # we shall ignore the name attribute
                  # use the == override to include name in test
                  # use <=> to test only the names (match returns 0)
                  same = true
                  return (same = (self.page_behavior==arg.page_behavior)) if (not same)
                  return (same = (self.visible?==arg.visible?)) if (not same)
                  return same
                else
                  raise(TypeError,'Sketchup::Layer expected.')
                end
              end # override eql?
            end
            #
          end # class extension
          0
          Last edited by Dan Rathbun on Wed Aug 11, 2010 12:31 am, edited 8 times in total.
            I'm not here much anymore. But a PM will fire email notifications.
            User avatar
            Dan Rathbun 
            PluginStore Author
            PluginStore Author
             

            Re: SketchUp RUBY API Wishlist [way of coding wishes, please

            Postby thomthom » Tue Aug 10, 2010 4:52 pm

            hm... never thought of that inconsistency before...
            model.materials.current vs model.active_layer
            0
            Thomas Thomassen — SketchUp Monkey & Coding addict
            List of my plugins and link to the CookieWare fund
            User avatar
            thomthom 
            PluginStore Author
            PluginStore Author
             

            Re: SketchUp RUBY API Wishlist [way of coding wishes, please

            Postby Dan Rathbun » Tue Aug 10, 2010 5:02 pm

            thomthom wrote:hm... never thought of that inconsistency before...
            model.materials.current vs model.active_layer

            "current and "active" should aliases for each other.
            0
              I'm not here much anymore. But a PM will fire email notifications.
              User avatar
              Dan Rathbun 
              PluginStore Author
              PluginStore Author
               

              Re: SketchUp RUBY API Wishlist [way of coding wishes, please

              Postby kwalkerman » Tue Aug 10, 2010 5:16 pm

              Cool. Thanks again.
              0

              kwalkerman 
               

              Re: SketchUp RUBY API Wishlist [way of coding wishes, please

              Postby Dan Rathbun » Tue Aug 10, 2010 6:53 pm

              kwalkerman wrote:Cool. Thanks again.

              No problem.

              (bumping the topic..)
              • Made edits to the Layers code example
              • Added a second code example for Layer class.
              See previous post...
              0
                I'm not here much anymore. But a PM will fire email notifications.
                User avatar
                Dan Rathbun 
                PluginStore Author
                PluginStore Author
                 

                Re: SketchUp RUBY API Wishlist [way of coding wishes, please

                Postby Jim » Tue Aug 10, 2010 7:17 pm

                kwalkerman wrote:In addition to retaining information on which layers are on and off, should also be able to retain the active layer for each page.


                I like this idea, particularly useful when adding text to Scenes. It seems quite possible using an Observer.
                0
                Hi

                Jim 
                Global Moderator
                 

                Re: SketchUp RUBY API Wishlist [way of coding wishes, please

                Postby Jim » Tue Aug 10, 2010 8:53 pm

                Dan Rathbun wrote:
                thomthom wrote:hm... never thought of that inconsistency before...
                model.materials.current vs model.active_layer

                "current and "active" should aliases for each other.


                Well, don't leave out Pages.selected_page!
                0
                Hi

                Jim 
                Global Moderator
                 

                Re: SketchUp RUBY API Wishlist [way of coding wishes, please

                Postby Dan Rathbun » Tue Aug 10, 2010 11:22 pm

                Jim wrote:
                Dan Rathbun wrote:
                thomthom wrote:hm... never thought of that inconsistency before...
                model.materials.current vs model.active_layer

                "current and "active" should aliases for each other.


                Well, don't leave out Pages.selected_page!

                I don't know about that one... Pages are special. Even though you "select" a Page, depending on transition time, Sketchup can be animating somewhere between the previous page and the selected one.
                A FrameChangeObserver is needed to know when the animation is complete. Only at that point would I 'technically' say that a Page was the "active_page" or "current_page."

                @Karen. You can get an array of the hidden layers for a Page:
                mypage.layers
                so the visible layers would be:
                my_vis_layers = model.layers.to_a - mypage.layers
                * why they didn't name the method Page.hidden_layers, I don't know.
                0
                  I'm not here much anymore. But a PM will fire email notifications.
                  User avatar
                  Dan Rathbun 
                  PluginStore Author
                  PluginStore Author
                   

                  Re: SketchUp RUBY API Wishlist [way of coding wishes, please

                  Postby Dan Rathbun » Wed Aug 11, 2010 12:24 am

                  Jim wrote:
                  kwalkerman wrote:..., should also be able to retain the active layer for each page.


                  I like this idea, particularly useful when adding text to Scenes. It seems quite possible using an Observer.

                  But when you add text to Scenes (Pages,) are you drawing to the model, or drawing to the View ??

                  If it's the View, then the active layer does not matter.

                  The active layer is a property of the model. A Scene (Page,) is a View mechanism, which does not "have" layers; it only 'remembers' which of the model's layers to hide or show. A layer also has "new page behaviour" which it can tell new Scenes (Pages,) how to 'remember' their visibilty.

                  I can see some problems for other scripts, if the active layer was automatically changed when a Scene changed. There would need to be some kind of toggle to turn the "auto" feature on and off.
                  In addition, their would need to be scoping. What if an Observer was to be triggered while this "auto layer" feature was on? Outside the current script (or scope,) the Observer may want to "see" or "use" another layer as the active one.

                  It also occurs to me, that we are supposed to always be drawing primitives on "Layer 0", but still some modelers want to draw on other layers (construction lines especially.)

                  Anyway.. we'd need to consider this carefully. It could be a disaster.
                  0
                    I'm not here much anymore. But a PM will fire email notifications.
                    User avatar
                    Dan Rathbun 
                    PluginStore Author
                    PluginStore Author
                     

                    Re: SketchUp RUBY API Wishlist [way of coding wishes, please

                    Postby TommyK » Fri Nov 21, 2014 9:38 pm

                    I don't know if this thread is still checked by the Sketchup team, but I have one ruby request:
                    - be able to set selection colour per entity, including bounding box color.

                    It would allow different kinds of entities to be shown as such.
                    0
                    User avatar
                    TommyK 
                    PluginStore Author
                    PluginStore Author
                     

                    Re: SketchUp RUBY API Wishlist [way of coding wishes, please

                    Postby Rich O Brien » Fri Nov 21, 2014 9:48 pm

                    That's a very old feature request.

                    I think it was back at v7 I remember seeing members ask for groups and components to be different colours.

                    I love it to happen. Sorely needed in such a visual program.
                    0
                    There's a frontroom and a backroom....reverse faces
                    User avatar
                    Rich O Brien 
                    Administrator
                     

                    Re: SketchUp RUBY API Wishlist [way of coding wishes, please

                    Postby AdamB » Mon Nov 24, 2014 11:31 am

                    Pretty, but whats the use case?
                    0
                    Developer of LightUp Click for website
                    User avatar
                    AdamB 
                    LightUp Support
                    LightUp Support
                     

                    SketchUcation One-Liner Adverts

                    by Ad Machine » 5 minutes ago



                    Ad Machine 
                    Robot
                     

                    PreviousNext


                     

                    Return to Developers' Forum

                    Who is online

                    Users browsing this forum: No registered users and 12 guests

                    Visit our sponsors: