Graph to convert point coordinate text to vector list

Hello everyone
Here is a little solution, still a bit hacky, but functional, to go from a SketchUp surface or a curve… Into a list of vectors for Trimble creator.

The idea is to be able to feed a large list of points by pasting a simple text into a text input of the dialog box.

Here is a little demo of what I managed to do:

Here is the Ruby code to extract the information.

# Extract outerloop points position of a face in a selected Component Instance to a string
# x,y,z values are roundes to 1 decimal
# string use different separator for points and values

# How to use 
# 1- Draw à face
# 2- Create a Component of the face
# 3- Define the origin of the component it will be the equal at the origin of the graphe
# 4- paste this code in the Ruby Console
# 5- Copy the string result
# 6- Past it in the Live component dialog, in the string input

def stringOuterloop(separatorPoint=";",separatorValue=",")
  
  inst = Sketchup.active_model.selection.grep(Sketchup::ComponentInstance)[0]
  face = inst.definition.entities.grep(Sketchup::Face)[0]
  vertices = face.outer_loop.vertices
  points = vertices.map{|v| v.position}
  points_mm = points.map{|p| "#{p.x.to_mm.round(1)}#{separatorValue}#{p.y.to_mm.round(1)}#{separatorValue}#{p.z.to_mm.round(1)}"}
  points_string = points_mm.join("#{separatorPoint}")
  return points_string
  
end

def stringCurve(separatorPoint=";",separatorValue=",")
  
  inst = Sketchup.active_model.selection.grep(Sketchup::ComponentInstance)[0]
  curve = inst.definition.entities.grep(Sketchup::Edge)[0].curve
  vertices = curve.vertices
  points = vertices.map{|v| v.position}
  points_mm = points.map{|p| "#{p.x.to_mm.round(1)}#{separatorValue}#{p.y.to_mm.round(1)}#{separatorValue}#{p.z.to_mm.round(1)}"}
  points_string = points_mm.join("#{separatorPoint}")
  return points_string
  
end

string = stringCurve()
puts string

And to finish use with my live wood deck component

It’s up to Keith’s team to make the direct knot with as an output parameter: create points, a mesh if points are coplanar, a curve, and as an input parameter the separators for each level.

And I will make a small plugin with different text output options and copy to clipboard.

Link to the graph : Graphe string to liste


How do you like it ?

1 Like

Should be:

def stringOuterloop(
  separatorPoint = Sketchup::RegionalSettings.list_separator ,
  separatorValue = Sketchup::RegionalSettings.decimal_separator
)

REF: Sketchup::RegionalSettings module


You can also use Ruby 2.x shortcut iterators …

Like so …

  points = face.outer_loop.vertices.map(&:position)

Please try to make long statements more readable especially for the forum …

See how it forces horizontal scrolling to read the code ?
Better to break it up into a multiline statement under 80 wide:

  points_mm = points.map do |pt|
    pt.to_a.map { |val| val.to_mm.round(1) }.join(separatorValue)
  end

Using String interpolation here is frivolous …

Just use the variable as the argument is already a String:

  points_string = points_mm.join(separatorPoint)
3 Likes

Hello Dan
Thank you for your technical answer about the Ruby code. :+1:

However, the 2 “separator” attributes can be any alphabetic symbol since the values to be extracted are digits.

This was so that everyone could define their own separator values, and then enter them in the live component dialog.
They must be the same values in the ruby code and in the dialog to do the reverse operation.

They still can. They are called default values.

Any code or person calling the method still has the option of overriding the default values.

But it also makes it easier for users who do not want to use “special” characters.
When using the separators from the API, they will automatically adjust to the user’s system settings.

Hello Dan
On the Ruby code side that generates the text, I agree, we could simplify and use regional settings.

But on the Trimble Creator side, my graph requires entering the separators between the groups of coordinates and another separator between the x, y, z values to cut the string into a list of vectors.

I don’t have the knowledge of the live components API to prepopulate the dialog from Ruby.
So I have to enter these two values, so the user can’t save having to set them in the Ruby code.

1 Like

I love where you are going with this!

1 Like

Thanks Keith!
I try to clear the path at my level. :fr: :man_farmer:
But you’ll have to help me a little too! By unlocking some features.
If you really want to do “Live” the interaction must be input and output to take advantage of the power of the nodes.
Imagine when we can import and extract the attributes, interact on the layers… drive the live component dialog box from ruby, from a dynamic component, when outliner will display the hierarchy of the live component… :star_struck:

2 Likes