sketchucation logo sketchucation
    • Login
    1. Home
    2. vtikka
    โ„น๏ธ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info
    V
    Offline
    • Profile
    • Following 0
    • Followers 0
    • Topics 2
    • Posts 6
    • Groups 1

    vtikka

    @vtikka

    10
    Reputation
    1
    Profile views
    6
    Posts
    0
    Followers
    0
    Following
    Joined
    Last Online

    vtikka Unfollow Follow
    registered-users

    Latest posts made by vtikka

    • RE: Changing the dynamic components attributes using SU API

      Thanks for responding to my post. I figured out what the mistake was. Error is kind of misleading because in my code sample at the following code

      @unknownuser said:

      componentInstance = aqx_get_component_instance(componentName)

      "ComponentInstance" is coming back as nil because I am looking for instance in a wrong way i.e. instead of looking for Definition name I was looking at the instance name which is empty string. After bunch of puts statements I finally figured out the issue and finally got it work.

      posted in Developers' Forum
      V
      vtikka
    • Changing the dynamic components attributes using SU API

      Hi All,

      Can some one shed some light on what I am missing here to get this to work. What I am trying accomplish is very simple, I getting a component instance based on the name and change that component instance "lenz" value to a user specified value.

      Following is my function that is supposed to do all the heavy lifting. I can see that the attribute dictionary is having right value in it but component instance is not updating in the Sketch Up UI. After lot of google searching I came across the $dc.observers and on using it I am getting the following message and error is outside the scope of my code.

      setting lenght to 46' 11 1/8"
      lenz value 46' 11 1/8"
      Error: #<NoMethodError: undefined method transform!' for #<Sketchup::ComponentDefinition:0xa0ae90c>> (eval):465:in redraw'
      (eval):417:in `redraw_with_undo'

      
      #componentName ---> Name of the component
      #component_length ----> new length for the component instance.
      
      #aqx_get_component_instance ---> is a different fuction that return the instance based on #the name
      
      def self.aqx_set_component_length(componentName,component_length)
      		componentInstance = aqx_get_component_instance(componentName)
      		attribDictlist = componentInstance.attribute_dictionary "dynamic_attributes"
      		puts("setting length to #{component_length}")
      		attribDictlist["lenz"] = component_length	
      		
      		value = componentInstance.get_attribute "dynamic_attributes", "lenz"
      		puts("lenz value #{value}")
      		
      		# Redraw the DC using the $dc_observers global variable. 
      		$dc_observers.get_latest_class.redraw_with_undo(componentInstance) 
      	end
      
      
      posted in Developers' Forum
      V
      vtikka
    • RE: New to Ruby and sketchup API, need some clarifications

      @jolran said:

      If I was you I would rather download a few plugin that reminds of what you want to do, from some of the more experienced experts around here. And have a poke around.

      A good idea, (if you havent), is to download some of the Ruby code editors. With wich you can try snippets directly inside Sketchup. And also reload scripts.

      There is also "Automatic Sketchup"(ebook), wich is a good startingpoint about using the API.
      A bit old, though..
      But it might help speed up the progress since you already have programming experience.

      Thanks for your thoughts and suggestions. I tried few different IDEs including eclipse and others Ruby editors and ended up settling with NotePad ++ because that is the only IDE that is working with SketchUp bridge plugin. I have already downloaded "Automatic Sketchup" ebook and it has been a great help so far.

      I am looking at different plugin's code to get an understanding of code structuring etc. From your experience is it a good idea to use core ruby classes with Sketchup and I am not sure how it will effect the working of plugin on Macs.

      Tik

      posted in Developers' Forum
      V
      vtikka
    • RE: New to Ruby and sketchup API, need some clarifications

      @jolran said:

      Glad to help!

      For gluebehavior you can have a look in my code in "Hatchfaces".
      (I don't know of any other scripts using that method.. ๐Ÿ˜• )

      BUT! be adviced, I'm novice programmer so there might be lack of style and
      best practices in there.

      I am very new to Ruby programming as well. I am having very hard time with structuring my code. Here is a small example related to one of my problems. I created a component with some constraints and place this component in the model. Before placing the component, I want to get the length of the component by clicking two points in SU and use that length for my component length.

      To keep my code clean I am trying to separate my class into following folders or lets say module

      Module 1:- this has the UI related classes like my toolbar and commands

      Module 2:- this is supposed to have all the "Sketch up" api methods.

      Module 3:- In this module I want to keep all my components related classes.

      And this is how I always structured my plugin code in AutoCAD. With sketch up I want to do the same way but I am having hard with separation of code. In my API module I want to have a function lets say "get_length" which will call the tool class which does the mouse tracking etc and returns a length back when user is done picking two points or hits cancel. So far I have a class which is doing every thing i want to do related to getting the length. Only problem I am having is passing that length back to my api module when user is done. I am not sure how to get that length back, on the other hand I think I am over complicating this because of my lack of SU api knowledge.

      Here is code snippet from my API class.

      
      class Aqx_api
      	def self.getActiveModel
      		return Sketchup.active_model
      	end
      
              def self.getLength
      		aqxGetLength = Aqx_Get_Length.new
      		getActiveModel.select_tool aqxGetLength				
      	end
      end
      
      # Class for getting the length which is based LineTool class from plugin examples.
      
      class Aqx_Get_Length    
                      
             # This class has code from LineTool. So I am not pasting every thing here.
      end
      
      
      posted in Developers' Forum
      V
      vtikka
    • RE: New to Ruby and sketchup API, need some clarifications

      @jolran said:

      I would like to add that different hierarchy's can be a solution to solve problem 2 maybe?

      For ex:

      Thanks for pointing me in the right direction, i will take a look at the pickhelper class. I like idea of creating a hierarchy of components to make them work there. Once again thanks for the help.

      Tik.

      posted in Developers' Forum
      V
      vtikka
    • New to Ruby and sketchup API, need some clarifications

      Hi All,

      I am new to Sketch up plugin development and also new to Ruby. I have experience with writing plugins for Autodesk products and other CAD platforms.

      I want to do something very simple like getting distance between points(similar to tap measure tool). I took the code from the LineTool example and able to get an understanding of its inner workings. My dilemma is how to get the distance from the Tool class to my wrapper class when user is done picking two points or hits cancel.

      Can I add some kind of observer when the tool is deactivated and read the length from the Tool class member variable?

      Even better will API let me use the Tape measure command from my code ?

      My second question is,
      from reading the API I see that you can have only one glue plane per component, is possible to have multiple glue plans for same components so that I can attach multiple components to a component.

      Thanks in advance.
      Tik.

      posted in Developers' Forum
      V
      vtikka