Friday, December 1, 2023
Home3D ModelingFile path for SketchUp instruments - Ruby API

File path for SketchUp instruments – Ruby API


Can anybody direct me to the Ruby code for the default SketchUp instruments? I’m fascinated by how the arc software works and wish to make one thing comparable as an extension, however with my very own customizations that swimsuit my wants. I’m utilizing SU23.

I don’t consider the native instruments are coded with Ruby.



1 Like

Attention-grabbing. Are you aware the language they’re coded in and if I can cross that info by means of externally, type of like an extension.

I don’t know the language they’re coded in however I anticipate re-engineering the code can be a violation of the EULA. You need to examine on that. There are already extensions that may draw varied kinds of arcs. They’re coded in Ruby. As an alternative of reinventing the wheel why don’t you take a look at them. Possibly they already do what you want.

Effectively, there are points with that for my use case. I would like excessive precision, and a number of the arc creation instruments don’t at all times supply it. After I go to code my very own, I get some actually good precision, however I discover that a number of the final values are a bit completely different.

For instance, shall we say I need to discover the arc size of an arc of radius 30 and a central angle of 45 levels. Mathematically, that’s quite simple (Math::PI/4)*30.

However after I take that worth, and assign it to the suitable begin and finish angles, it produces an almost good worth.

____Actual: 23.561944901923449288469825…
_Extension: 23.561944901923447
SU Arc software: 23.56194490192345

Edit: (added these underscores to get it to align for higher visibility.)

What’s attention-grabbing is after I throw in an enormous 200 digit calculation and simply skip all the mathematics within the editor it provides me the identical consequence because the arc software does. I do know this sounds silly as a result of I’m nitpicking over a ridiculously small decimal worth however I simply need to make the most effective software potential.

What sort of work requires that degree of precision in sketchup? If it’s for one thing associated with quantum physics I’m positive you’re not utilizing the best software program.



1 Like

Or the proper of laptop. All digital units have a restrict to the precision of numbers they’ll deal with. For present industrial computer systems it’s 64 bits. I perceive the sensible restrict is decrease in most software program (as an example, I appear to do not forget that AutoCad numbers are 32-bit).

Verify this thread:

It would clarify why the results of your extension is much less correct than the native software’s consequence in comparison with the precise calculated, regardless of it’s increased variety of digits past the decimator.



1 Like

You’re working into the boundaries of the IEEE double precision floating level format. To extend the precision of the mathematics you’ll be able to set up the float-formats ruby gem.

Within the Ruby console, kind these instructions to put in the float-format Gem and take a look at the operations.


Gem.set up 'float-formats'
require 'float-formats'

PI = Flt::IEEE_decimal128('3.14159265358979323846264338327950288419716939937510582097494459230')
divisor = Flt::IEEE_decimal128('4.0')
multiplier = Flt::IEEE_decimal128('30.0')
consequence = (PI / divisor) * multiplier
places consequence.to_text #> 23.56194490192344928846982537459627





1 Like

So I want a little bit of an experiment. I used the next code and measured the road lengths of some non-terminating decimal values. I used 1 1/3, 10 1/3, 100 1/3, 1000 1/3, 10000 1/3, 100000 1/3. The sides had been made with the road software and typed these values within the measurement discipline.

selected_edge = choice.discover entity.is_a?(Sketchup::Edge) edge_length = selected_edge.size.to_f

Outcomes:
_____1.3333333333333333
____10.333333333333334
___100.33333333333333
__1000.3333333333334
_10000.333333333334
100000.33333333333

Can anybody clarify this sample? I perceive why the decimal locations descend, however why does SketchUp spherical 3 to 4 for a few of them? And would utilizing decimal128 to generate these edges with code alleviate this challenge?

This code will print the values that you simply specified as they seem within the within the ruby console together with the IEEE Double Precision illustration that’s really utilized in computations. If you want some perception into the binary representations of those floats attempt this hyperlink

def self.print_value(worth)
  places "The worth rounded to fifteen vital digits is #{ worth }"
  places "The very best Double Precision illustration of this quantity is #{ sprintf("%.50f", worth) }"
  places
finish

one_third = 1.0/3.0

numbers = [ 1.0 + one_third,
            10.0 + one_third,
            100.0 + one_third,
            1000.0 + one_third,
            10000.0 + one_third,
            100000.0 + one_third,
            1000000.0 + one_third
          ]
numbers.every  print_value(worth) 
nil

Notice: Edited so as to add a hyperlink to a greater IEEE-754 floating Level Converter



2 Likes

Actually it’s mindless to make use of greater than 5 decimals in a program like sketchup.

… particularly as a result of SketchUp has an inside tolerance of 0.001 inch.

Any factors nearer than this turn into coincident.

If the poster is nervous about nanoinches … they’ll mannequin at a excessive scale issue.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments