Quantcast
Channel: Ruby API - SketchUp Community
Viewing all 3009 articles
Browse latest View live

Cleaning Dynamic Attributes

$
0
0

@milmandre wrote:

Hi API friends,

Today I bumped into an unexpected behavior and I’d like your advise regading what I’m doing (working on SU2019 Pro).

After cleaning a scene provided by users using Dynamic Components to generate their model, I added a quick “dynamic_attributes” attribute dictionary cleaning pass to avoid errors when subsequent manually trasnformations are performed by the users.

Files

Cleaning Code (only dynamic part)

#Remove the dynamic component data
Sketchup.active_model.entities.each do |current_entity|
  if current_entity.is_a? Sketchup::Entity
    current_attrdict = current_entity.attribute_dictionaries
    current_attrdict.delete("dynamic_attributes") unless current_attrdict.nil?
  end
end

The dynamic attributes seems totaly deleted but on some component instances, when transforming them , they are recreated and SU is trying to apply them again…

Did I missed something when cleaning the dynamics attributes ?

Thanks for any help on this :slight_smile:

Posts: 6

Participants: 4

Read full topic


Get the coordinate of a component

How to add .so files to ruby ffi

$
0
0

@dejaunsilverman wrote:

Hey guys, I have a self defined so file that I have been trying to incorporate in a ruby plugin file for use in Sketchup.
Whenever i try to start Sketchup,it loads to a point then crashes.
Can someone offer any advice in this regard

Posts: 6

Participants: 4

Read full topic

How to get the texture of face when just give material to a group/component instance

$
0
0

@lm20224 wrote:

Now i make a group from some face(without material) and give it a material like this:141115hddxk2rn0qkmmkk6_jpg_thumb|215x500
the skp file like this:
ART 03.skp (415.1 KB)
then i use the C SDK to export geometry file by the follow steps:
1.SUMeshHelperGetFrontSTQCoords/SUMeshHelperGetBackSTQCoords
2.SUUVHelperGetFrontUVQ/SUUVHelperGetBackUVQ
3.SUTexturegetDimensions
then i transform the STQ like this:

For backface:
geo.UVs.Add((float)(mesh.STQBack[i].X/ mesh.STQBack[i].Z) * (float)currentMaterial.TextureScaleT);
geo.UVs.Add((float)(mesh.STQBack[i].Y/ mesh.STQBack[i].Z) * (float)currentMaterial.TextureScaleS);

For frontFace:
geo.UVs.Add((float)(mesh.STQFront[i].X/ mesh.STQFront[i].Z) * (float)currentMaterial.TextureScaleT);
geo.UVs.Add((float)(mesh.STQFront[i].Y/ mesh.STQFront[i].Z) * (float)currentMaterial.TextureScaleS);

after export,i got the same back and from material.(i mean the exported two face looks same as the back face of skp-file.)


i want to know how to transform between the UV and STQ.
or any other API can i used to export such skp file.
Thanks a lot!!!

Posts: 1

Participants: 1

Read full topic

UI::Notification

$
0
0

@Guy wrote:

Is there a way to set the time a notification is shown? Now it is automatically dismissed after a few seconds.

Posts: 5

Participants: 5

Read full topic

Defining the line_styles using ruby in SketchUp 2019

$
0
0

@lee_jay_hom wrote:

Folks, I’ve been trying to find out what’s the value of the mystery line_styles when adding a new layer, I’ve tried [“Solid”], [“Dot”] and [“Dash”] works, but however the other line styles listed here even follow the names on it the layer panel will only return the new_layer as “Default”.
Codes below:

layers = model.layers
new_layer = layers.add("new_name")
new_layer.line_style = Sketchup.active_model.line_styles["VALUe"]

can anyone help to point out what VALUE will set the new_layer.linestyles = Short Dash, Dash Dot etc shown below?

Thanks!

Posts: 3

Participants: 2

Read full topic

Loading dynamic components

$
0
0

@Ries wrote:

I have dynamic components saved in a separate .skp file and I’m loading them into new Sketchup drawings via use of a toolbar via Ruby (see below code snippet)

button = UI::Command.new("Button") { load_component("/location/Button.skp") 

}

Issue I’m having is this is creating a group around the dynamic component so I can not see the attributes in the options window unless I click into/explode the group.

Is there a way to remove this behavior so the dynamic component options are immediately accessible when importing?

Posts: 3

Participants: 3

Read full topic

Find the lower left corner of the quad

$
0
0

@skyfire wrote:


I want to lay out the components from the bottom left corner of a face.
I wrote a code to get the nearest point of the quadrilateral from the origin and sort the four endpoints.
But many of the actual points closest to the origin are not the lower left corner of the quadrilateral,just like the picture.
How can I do to find the points in the lower left corner of the quadrilateral and sort them?
I would be grateful if you could help me with the answer.

Posts: 6

Participants: 5

Read full topic


Reload dynamic library with Fiddle

$
0
0

@Rojj wrote:

I am using Fiddle to load a function from a dynamic library written in C. During development I need to make changes to the library and reload it for testing. The problem is that dlload does not reload the library unless I restart SketchUp.

Sample code to show the issue:

require 'fiddle'
require 'fiddle/import'
require 'fileutils'

# test
module RG
  extend Fiddle::Importer  
  dlload 'utils.dylib'
end

FileUtils.rm 'utils.dylib'

module RG
  extend Fiddle::Importer  
  dlload 'utils.dylib'
end

If you launch the script the first time there is no error. If you launch it the second time you get the error: image not found.

So it seems that during the execution the library is imported only once. It seems that this is the reason why I cannot update it during a SketchUp session.

Any suggestion on how to force Fiddle to reload the library?

I am using SketchUp 2015 on macos

Posts: 2

Participants: 2

Read full topic

onRButtonDown never triggered

$
0
0

@milmandre wrote:

Hi all,

I was working on a tool when I was unable to assign actions to the right mouse button clic using the onRButtonDown tool method. Using the Sketchup debugger I was unable to reach my brake point inside the tool onRButtonDown method…

  def onRButtonDown(arg_flags, arg_x, arg_y, arg_view)
    #Remove the last position recorded
    @picked_positions.pop

    #Force view to be refreshed and redrawn
    arg_view.refresh
  end

When I switch from the onRButtonDown to the onRButtonUp everything works fine. Does anyone notice this before? That sounds strange to me so I’m posting it here to double check my experience on this (I’m using SU2019 19.0.685 64-bit on Windows)

Thanks for your feedbacks.

Posts: 1

Participants: 1

Read full topic

Understanding Transformation Use Case

$
0
0

@milmandre wrote:

Hi there,

Until now I thought that Sketchup::ComponentInstance and Sketchup::Group transformations where local transformation matrix relative to their direct parent. But I bumped into a use case (443.4 KB) that I can’t understand/explanin and for which I need your help. The file is an extract from an existing scene.

In this use case the component instance has a transformation matrix and its direct child group also have the same exact transformation matrix. That means, if I’m right that both counteract each other :

  1. subgroup_transform * cmp_transform.inverse == IDENTITY
  2. the visible shape is a non transformed shaped.

The use case behavior that I can’t understand is that :

  • If I reset the component instance scale transform, the subgroup has its transform reset to an identity matrix (i’m fine with this) but its shape is altered and I can’t understand why…

  • If I explode the component instance, the subgroup keeps the same shape and the same transform matrix… Its not what I was expected, I was much more wating for keeping the same shape but having the transform matrix altered.

These 3 tests aren’t consistants in their behaviour, moreover when using two instances transformed of the same definition we can check that the trnbsformation matrix of the subgroup isn’t the same… How can that be possible ?

Any idea ? Can anyone give me a clue of what is happening here ?

Thanks :wink:

Posts: 1

Participants: 1

Read full topic

Create a context menu by R-click in 'free space'?

$
0
0

@john_mcclenahan wrote:

Some years ago I developed a tool which (more or less) worked in SU 2017 and 2018.

A R-click anywhere the drawing window (even in an empty part of it) would pop up a ‘context’ menu looking like this, from which to choose a softwood size before drawing a length of:
image

The content was defined in a method def getMenu(menu)....end using information from arrays defined earlier in the code.

It was called by a simple onRButtonDown method within the Tool code.

  def onRButtonDown flags, x, y, view
    ## Load plugin-specific R-click context menu
		getMenu()
	end

I’m working again with Steve Baumgartner (@slbaumgartner) to rework the code, and we are trying to replicate this behaviour in SU 2019.

Neither of us can work out why this worked at all - the getmenu() call has no menu parameter which the getMenu(menu) method requires, and in SU 2019 it immediately throws a mismatched number of arguments: 1 required, 0 supplied error (or words to that effect).

Somehow, SU2018 fills in a valid Menu object ID and the menu works fine. SU 2019 doesn’t, and the code errors.

Here’s a simplified version of the getMenu(menu) method, with fixed text replacing the array values, and just with a fixed item in the menu shown as MF_CHECKED.

 def getMenu(menu)
   puts "getMenu called #{menu.inspect}"
  menu.add_item("UK PAR/PSE") {} ## Displays type of timber (only PAR implemented so far)
	menu.add_item("Softwood size (nominal)") {}
	menu.add_separator
    item1 = menu.add_item("1\" x 1\"") {"do action 1"}
      menu.set_validation_proc(item1) { MF_UNCHECKED}
    item2 = menu.add_item("2\" x 1\"") {"do action 2"}
      menu.set_validation_proc(item2) { MF_CHECKED}
    item3 = menu.add_item("3\" x 1\"") {"do action 3"}
      menu.set_validation_proc(item3) {MF_UNCHECKED}
  menu.add_separator
  menu.add_item("Custom size (actual)") {}
  menu.add_separator
	item4 = menu.add_item("3/4\" x 1/2\"") {"do action 4"}
  menu.set_validation_proc(item4) {MF_UNCHECKED}
 end # def getMenu

Here’s what it pops up, when I replace the method in the tool with this simplified version.
image

QUESTIONS

  1. Why did it work at all, and where did SU 2018 get the menu object ID which it passes to the getMenu(menu) method? (We entered some test code to show that the receiving function was given a Menu object and ID.)

  2. Even if we don’t find out how it worked in SU 2018, how can we provide a menu object ID to the onRButtonDown (or …Up) event so the menu will work in SU 2019? Just use something like
    size_menu = UI.menu("")?
    At least that doesn’t error when I try it in the Ruby console, and returns:
    #<Sketchup::Menu:0x007f85491a2310>

  3. And anyway, how does a context menu get triggered when you click on empty space in the model window?

AFAIK, context menus usually need an object to click on, to provide a suitable context.

Posts: 6

Participants: 4

Read full topic

Drawing a Face but removing the actual Face

$
0
0

@medeek wrote:

I’m surprised I have never had to do this type of operation before but I’m wanting to create a face given an array of points using the add_face method and then remove the actual face but leave the (outer loop) edges behind.

Its seems I must have done this sort of thing before but I can’t find a single example in any of my code.

This block first creates the face:

dep_group = Sketchup.active_model.active_entities.add_group
entities_dep = dep_group.entities
new_face_outline = entities_dep.add_face @pts

Posts: 4

Participants: 2

Read full topic

Temp Face or Draw Method of the Tool Class

$
0
0

@medeek wrote:

These days it seems like most of my API manipulations can be accomplished by rehashing previous code with some minor tweaks. In other words I don’t come across something totally new as much as I used to, I guess I’ve been at this a while now.

Today however, I am trying to build a tool which will allow me to select one of the edges of a face/group however the actual edges may or may not actually exist within the model. The points that define these edges are actually an array within my foundation’s attribute library. I can utilize these points to define the edges in question.

My first thought is to draw a temporary face/group given the points and then my tool can allow the user to select an edge. Once the selection is done the tool would then have to erase this temp group (face and edges), at that point I would then pass the vertices of that edge to the rest of my logic. My only reservation with this method is I don’t like inserting temp geometry as a rule of thumb since something could potentially disrupt the tool and then this temp group would be left abandoned within my model.

My other thought is to use the Draw method(s) of the Tool class and create the virtual face/edges this way. However there does not appear to be any way to select the geometry created by the Draw method of the Tool class since it really isn’t valid geometry within the model.

It’s highly possible that there is a something I’m missing here or even a third and better way to accomplish this edge selection process. I am very open to any thoughts or ideas anyone might have on the matter.

Posts: 6

Participants: 2

Read full topic

Force Dynamic Components to Redraw

$
0
0

@milmandre wrote:

Hi all,

I’m actually writing a wall tool that wrap a dynamic component placement, orientation and scaling. Everything works fine except that I’m unable to force the dynamic component to be refreshed/redrawn correctly

I found @DanRathbun post regarding the way to force a dynamic component to be redrawn.

That works perfectly for a single usage but doesn’t for subsequent use. When I add an another instance of my dynamic component that use the ScaleTool behaviour with my drawing tool I get the dynamic component instance redrawn using both previous and current scale factors.

Any idea of what append cause I’m unable to understand that code snippet and there’s no documentation regarding the dynamic components
:
$dc_observers.get_latest_class.redraw_with_undo(inst)

Thanks all for your help as usual :wink:

Posts: 5

Participants: 2

Read full topic


Create a face entity with outer and inner loops

$
0
0

@carlosM wrote:

Hi,

I am working on a plug-in for the SketchUp Rubi API able to read a text file containing a some geometrical information and create a SketchUp model with that.

The surfaces in my model are flat and rectilinear (no curved shapes) but often they consist in an outer loop plus some inner loops. My question is how can I create a new face in model made of outer + inner loops as the one in the image below

image

Best regards, Carlos

Posts: 7

Participants: 4

Read full topic

Hide user input in UI.inputbox?

$
0
0

@mdeeps wrote:

I’m sending some model data over to our 3rd party application, and am using UI.inputbox for users to input their login credentials to our app.

Since it’s not mentioned in the docs, I’m assuming there is no way to hide the text as it is put into the box? I feel like this is pretty standard functionality for hiding passwords so I thought it would be built in. Am I missing something or do I need to do something else like build a custom html input box?

Thanks!

Posts: 2

Participants: 2

Read full topic

Layout import table data through api

$
0
0

@kengey wrote:

Hi,

I am working on an extension that automates some work in Layout. One of the things I need to realize is the creation of a table. Currently, I create that one manually (well, still automated since it is code, but…). However, I am looking for a solution that lets me import table data, just like the UI allows you to do, but through the API. The reason is simply the fact that afterwards, the user could update that data whenever the source changes.

Maybe @adam knows a solution?

Thanks,

Kenny

Posts: 5

Participants: 4

Read full topic

Inputting a Polyline (extracting its vertices)

$
0
0

@medeek wrote:

I’m currently working on a whole new module for the foundation plugin and I am trying to implement a polyline stemwall rather than a polygon or rectangular stemwall (outline) which requires a closed loop.

The initial draw function is fairly simple, the user consecutively picks a bunch of points which then are passed from the tool to my main draw function and the stemwall is drawn, and the points are stored in an array within the attribute library for the assembly (group). I immediately know which is the first point, which is the last point and the points will naturally be in order.

The problem will arise when the user goes to edit this polyline. My intent is to have the plugin create the edges in a temp group via the stored points and then the user can simply edit the edges and then hit the submit button once they have moved, added or deleted the edges they choose to modify.

Once they hit the submit button I somehow have to extract the points from this group of interconnected edges. It’s really not too hard to grab all of the edges in the goup or even to check to make sure that they are connected using some logic and the all_connected method in the Edge class.

My bigger question is how to best determine which two points are the end points of the polyline and also how to get the points so they are in order. This becomes particularly important when I lay out anchor bolts and other features along each segment of this polyline. I also need to come up with some logic to check to see if the user created a closed loop rather than an open polyline (start point will equal end point?).

Strangely I have not come across this specific problem before, up until now it has been single edges or closed loops of edges that I’ve had to deal with.

Posts: 4

Participants: 2

Read full topic

Redirect Ruby console to file(s) - example

$
0
0

@MSP_Greg wrote:

Attached is an example file that shows how to redirect the Ruby console to file(s). At present, the path is set to ENV['TMPDIR'] || ENV['TEMPDIR']. Usage after load:

SU_IO.file        stderr & stdout to ruby_all.log
SU_IO.file :all   stderr to ruby_err.log, stdout to ruby_out.log
SU_IO.file :err   stderr to ruby_err.log
SU_IO.file :out   stdout to ruby_out.log

SU_IO.rc          reconnect Ruby console

Tested on Windows, there may be buffering issues. Also, I set it to work with a UDP socket, and everything worked fine.

console_redirect.rb (2.0 KB)

Posts: 2

Participants: 2

Read full topic

Viewing all 3009 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>