[New scripter] Will need help on my project (now and then)
-
Welcome.
When you hit a problem, ask clear questions, with example code [use the 'Code' formatting [...]] and I'm sure someone will try to help you...
I assume you have links to the API docs - but it's here again... http://www.sketchup.com/intl/en/developer/docs/classes.php -
In my opinion, the end use (of such an extension,) will be an obvious commercial use of the SketchUp software, that would require a SketchUp Pro license. But your development of the extension may not be.
Review the SketchUp Software Terms and Conditions
and pay close attention to clause 11(d).:
@unknownuser said:11. DISCLAIMER OF WARRANTIES
d) NONE OF THE SOFTWARE IS INTENDED FOR USE IN THE OPERATION OF NUCLEAR FACILITIES, LIFE SUPPORT SYSTEMS, EMERGENCY COMMUNICATIONS, AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL SYSTEMS, OR ANY OTHER SUCH ACTIVITIES IN WHICH CASE THE FAILURE OF THE SOFTWARE COULD LEAD TO DEATH, PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE.
Therefore the critical calculations should still be done within the VISIPLAN application.
-
@ruts said:
Once the 3D environment is created the user needs to start the "translation" script. It will detect all the primitive shapes (which are groups) and what shape they are.
You'll make the job easier if the user tags the groups either with Classifications (you create a custom XML schema for Visiplan Shapes,) or a simple AttributeDictionary that corresponds to the Access "Take" tables within Visiplan.
@ruts said:
Then it extracts the information it needs to translate it to the parameters the database needs. (TIG's export vertices to CSV seems interesting)
As, visiplan is using Access 2000 MDB, you may be able to use the Ruby WIN32OLE class to write directly into database tables.
There is an example of writing to an Excel spreadsheet, on the WIN32OLE class page.
The machine using the extension would likely need MS Office Runtime libraries installed.
Access 2007 Download: Access Runtime (Released before Windows 7.)There is also Access 2010 Runtime and Access 2013 Runtime libraries in both 32-bit and 64-bit, as well as service packs for them. (The links are too numerous to post here. Search the Microsoft website for the various downloads. Pay attention to the platforms supported.)
-
Additional WIN32OLE Samples that were distributed with the Ruby 1.8.6 packages ...
... are posted in the Ruby Resources thread:
-
http://www.sketchup.com/intl/en/developer/docs/faq told me that it is possible to load an editted script without restarting Sketchup. When I type the code
load 'tr_VISIPLAN.rb'
it answers with true, which probably means it did succeed. Although, when I tryout the editted script it still runs the script that was loaded when I did start Sketchup.
I think I know the reason, but not the solution. As mentioned in this link https://extensions.sketchup.com/developer Technical Requirements>Packaging I did create a root file (tr_VISIPLAN.rb) and map (tr_VISIPLAN) in the plugins folder. Located in that map are my actual code scripts with the main script (and currently my only script) called also tr_VISIPLAN.rb. I guess when I type
load 'tr_VISIPLAN.rb'
it loads the root file, but it doesn't load the file in the map?
If that's the case I can delete the root file for a while and bring back the script directly in the plugins direction. If it's directly in the plugins folder it will load, right? This raises a new question:
If my project exists out of multiple scripts, with one main script that requires the other scripts. If I reload the main script, does it also reload the other scripts?About my project:
Making progress, I'm able to create a box with the input of begincoordinates and dimensions of the box. I can also make a group from the entities of the box. Next step is to track any scaling, translation, rotation that is possibly be done. TIG's transformation_extensions.rb http://sketchucation.com/forums/viewtopic.php?f=180%26amp;t=27182 seems excelent for this.
-
Ruby knows nothing about SketchUp directory hierarchy.
All it knows is to check for scripts by prepending the paths that are in the
$LOAD_PATH
array. (Also aliased as$:
)So the SketchUp "Plugins" path is in
$:
. Therefore you need to enter relative path:
load "tr_VISIPLAN/tr_VISIPLAN.rb"
-
@ruts said:
This raises a new question:
If my project exists out of multiple scripts, with one main script that requires the other scripts. If I reload the main script, does it also reload the other scripts?You are asking basic Ruby questions that are covered in most Ruby books.
You need to learn Ruby, before you can use an API that extends Ruby (like the SketchUp API.)
At the very least read the files (except the "rake" files,) at the top of this page:
http://ruby-doc.org/core-2.0.0/index.htmlYou will save yourself hours of frustration if you read this book:
[doc] Programming Ruby (The "Pick-Axe" Book)
The answer is that your main loader file (in your plugin sub-folder,) uses
require
statements to load the other files that make up your extension.
http://ruby-doc.org/core-2.0.0/Kernel.html#method-i-require -
@unknownuser said:
You need to learn Ruby, before you can use an API that extends Ruby (like the SketchUp API.)
I'm aware that my knowledge is very little and I'm sorry that I don't take the time to properly learn ruby. But on the other hand, I have a deathline to keep in mind. With what I've been able to code right now it seems I can finish the code which I need to move on to the next part of my thesis.
When I have completed the other parts of the thesis I can come back to the programming part to expand it with new functions and adjust it so it looks like the code of an experienced programmer. But for now I want to move on as fast as possible. If I had no deathline I'd love to spend time learning ruby, I've been enjoying it so far.
If you think I don't deserve an answer because I didn't take the time to learn ruby properly, then just ignore me.
PS: Thank you for the links to the learning material, I will look in to it when I have time.
-
@ruts said:
If you think I don't deserve an answer because I didn't take the time to learn ruby properly, then just ignore me.
Please forgive all of us. It's not a matter of deserving. It can just be very frustrating answering questions that boil down to "do it for me" because the writer doesn't know even basic Ruby. It is hard to explain a question about the SketchUp Ruby API when the question comes down to "I don't know what that expression means". Sometimes the frustration leaks out...
-
In my calculations I have to do a matrix multiplication. Instead of doing this calculation of every element I want to use the base ruby class Matrix which is made for such operations. I found out that it's not just adding require 'matrix' to your code.
I did copy the matrix.rb and e2mmap.rb (which is required by matrix.rb) from the ruby2.2.2 folder to the plugin folder from SketchUp where also my main script is located. Next thing I did is add this line require File.join(File.dirname(FILE), 'matrix.rb') to my main script and this line require File.join(File.dirname(FILE), 'e2mmap.rb') in matrix.rb. I believe this is the right way to require 'matrix'.
The thing is, when I load my main script in SketchUp I get a bunch of error messages and my script still won't do any matrix calculations. Here's the list of errors:
Error Loading File matrix.rb C;/Program Files (x86)/Google/Google SketchUp 8/Plugins/matrix.rb;573; odd number list for Hash SELECTORS = {all; true, diagonal; true, off_dia... ^ C;/Program Files (x86)/Google/Google SketchUp 8/Plugins/matrix.rb;573; syntax error, unexpected ';', expecting '}' SELECTORS = {all; true, diagonal; true, off_dia... ^ C;/Program Files (x86)/Google/Google SketchUp 8/Plugins/matrix.rb;573; Can't assign to true SELECTORS = {all; true, diagonal; true, off_diagonal;... ^ C;/Program Files (x86)/Google/Google SketchUp 8/Plugins/matrix.rb;573; syntax error, unexpected ';', expecting '=' ...ECTORS = {all; true, diagonal; true, off_diagonal; true, low... ^ C;/Program Files (x86)/Google/Google SketchUp 8/Plugins/matrix.rb;573; Can't assign to true ... = {all; true, diagonal; true, off_diagonal; true, lower; tr... ^ C;/Program Files (x86)/Google/Google SketchUp 8/Plugins/matrix.rb;573; syntax error, unexpected ';', expecting '=' ... diagonal; true, off_diagonal; true, lower; true, strict_low... ^ C;/Program Files (x86)/Google/Google SketchUp 8/Plugins/matrix.rb;573; Can't assign to true ...nal; true, off_diagonal; true, lower; true, strict_lower; tr... ^ C;/Program Files (x86)/Google/Google SketchUp 8/Plugins/matrix.rb;573; syntax error, unexpected ';', expecting '=' ...ue, off_diagonal; true, lower; true, strict_lower; true, str... ^ C;/Program Files (x86)/Google/Google SketchUp 8/Plugins/matrix.rb;573; Can't assign to true ...f_diagonal; true, lower; true, strict_lower; true, strict_up... ^ C;/Program Files (x86)/Google/Google SketchUp 8/Plugins/matrix.rb;573; syntax error, unexpected ';', expecting '=' ...ue, lower; true, strict_lower; true, strict_upper; true, upp... ^ C;/Program Files (x86)/Google/Google SketchUp 8/Plugins/matrix.rb;573; Can't assign to true ...wer; true, strict_lower; true, strict_upper; true, upper; tr... ^ C;/Program Files (x86)/Google/Google SketchUp 8/Plugins/matrix.rb;573; syntax error, unexpected ';', expecting '=' ...ict_lower; true, strict_upper; true, upper; true}.freeze ^ C;/Program Files (x86)/Google/Google SketchUp 8/Plugins/matrix.rb;573; Can't assign to true ...wer; true, strict_upper; true, upper; true}.freeze ^ C;/Program Files (x86)/Google/Google SketchUp 8/Plugins/matrix.rb;573; syntax error, unexpected ';', expecting '=' ...ue, strict_upper; true, upper; true}.freeze ^ C;/Program Files (x86)/Google/Google SketchUp 8/Plugins/matrix.rb;717; syntax error, unexpected ';', expecting ')' def laplace_expansion(row; nil, column; nil) ^ C;/Program Files (x86)/Google/Google SketchUp 8/Plugins/matrix.rb;717; Can't assign to nil def laplace_expansion(row; nil, column; nil) ^ C;/Program Files (x86)/Google/Google SketchUp 8/Plugins/matrix.rb;717; syntax error, unexpected ';', expecting '=' def laplace_expansion(row; nil, column; nil) ^ C;/Program Files (x86)/Google/Google SketchUp 8/Plugins/matrix.rb;1535; module definition in method body C;/Program Files (x86)/Google/Google SketchUp 8/Plugins/matrix.rb;1561; module definition in method body C;/Program Files (x86)/Google/Google SketchUp 8/Plugins/matrix.rb;1603; class definition in method body C;/Program Files (x86)/Google/Google SketchUp 8/Plugins/matrix.rb;1673; syntax error, unexpected kEND, expecting $end
I think I already have a solution for my problem. I'm only going to use the multiplication class method. So I can maybe delete all the rest from matrix.rb, so the lines where the errors occur are gone. I can also code the calculation of a 3x3 matrix * 3x1 matrix by myself. But I just want to know why I can use the Matrix class in powershell and not in SketchUp. I'm think it has someting to do with my older version of SketchUp (8)?
-
@ruts said:
But I just want to know why I can use the Matrix class in powershell and not in SketchUp. I'm think it has someting to do with my older version of SketchUp (8)?
That is highly likely, as the Ruby interpreter is complaining about incorrect syntax in the matrix.rb file. SketchUp 8 uses an obsolete version of Ruby (1.8) and does not include the standard Ruby libraries. Depending on where you copied the matrix.rb file from, that could lead to incompatibilities. This begs the question: why not upgrade to the latest SketchUp Make 2015, which uses Ruby 2.0 and includes standard libraries such as matrix?
-
When I create shapes in Sketchup and start rotating and moving them my code is perfectly able to calculate the new position of the shape. The calulations are made by using the dimensions of the original bounding box and the transformation matrix.
Everything goes fine, until I start scaling the shape. In order to understand what goes wrong when I scale an object I did some scaling on easy shapes. The matching transformation matrices with the shapes gave results that did not make any sense for me. Here's one of the tests I did:
First I did create a box with begin coordinates (0,0,0) and width(X)/length(Y)/height(Z) (20,20,20). Next I scaled the box with value 2 in negative x-direction. This gave me a box with begin coordinates (-20,0,0) and W/L/H (40,20,20). This is the matching transformation matrix
[2.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, -20, 0.0, 0.0, 1.0]
The matrix makes perfect sense for this example.
For my next example I did create a box with begin coordinates (40,40,40) and W/L/H (20,20,20). Once again I scaled the shape with value 2 in negative x-direction. This gives a box with begin coordinates (20,40,40) and W/L/H (40,20,20). This is the matching transformation matrix
[2.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, -60, 0.0, 0.0, 1.0]
I can't find any reasonable explanation for the -60. I think it would be -20 as the other box.
Can someone explain me how this is possible?
-
@slbaumgartner said:
This begs the question: why not upgrade to the latest SketchUp Make 2015, which uses Ruby 2.0 and includes standard libraries such as matrix?
I use the software provided by the company I work for. I can ask if they don't have any keys for a more recent version, but I doubt it.
-
You are scaling from the ORIGIN in both cases?
-
@sdmitch said:
You are scaling from the ORIGIN in both cases?
My excuses if it's a common thing to know, but I don't know exactly what you mean by 'scaling from the origin'.
I did create both boxes which are created as groups. Next I scaled them 'Red Scale about Opposite Point' with the Scale tool in negative x-direction (scaling factor 2).
-
There are several potential arguments to a scaling transformation.
http://www.sketchup.com/intl/en/developer/docs/ourdoc/transformation#scaling
If you simply give the 'scale-factor[s]' it assumes the ORIGIN.
The first argument is taken as a point if 2 or 4 arguments are passed.
t = Geom::Transformation.scaling(scale) t = Geom::Transformation.scaling(xscale, yscale, zscale) t = Geom::Transformation.scaling(point, scale) t = Geom::Transformation.scaling(point, xscale, yscale, zscale)
-
How do I avoid rounding when using the Point3d.[] or Point3d.x/y/z methods?
Here's an example where I experience the problem. I have 3 Point3d's that are part of a line:
- edge_start = (-29,389263mm, 0mm, -40,45085mm)* edge_end = (-40,45085mm, 0mm, -29,389263mm) * intersection = (-40,458747mm, 0mm, -29,381365mm)
I want to run a piece of code if the intersection is on the edge. I have an if-statement that should work, but it fails when two points are close by because of the rounding of the Point3d.[] and Point3d.x/y/z methods.
edge_end.x should be greater then intersection.x, but it rounds edge_end.x to ~-40.5mm and also intersection.x to ~-40.5mm. This makes the variables equal to eachother.
How do I compare the x values of a Point3d without losing the precision?
-
Sketchup uses an internal precision of 0.001 or so. So any time you create a Point3d object values gets rounded to that.
So Ive seen some workarounds:
An idea is to use arrays instead of Point3d objects and do the bulk calculation in Ruby or C/C++.
Should you need Point3d objects for display, create them lastly before adding entities to the model. You can still get the x values from Point3D by pt[0] for ex. So no need to rewrite arguments.
Obviously you can't use Sketchup API methods that need Point3d objects during the calculations then, but it sounds like you are using your own intersection algorithm(?).
If not then an alternative is to scale up the whole piece you are working with. And when done scale down to original size.
-
@unknownuser said:
It sounds like you are using your own intersection algorithm(?)
The intersection of the lines is calculated with the Geom.intersect_line_line method. Next I use my own calculations to see if the edges on these lines also intersect.
The problem is solved by using arrays, thanks for your help.
-
@ruts said:
In my calculations ... I want to use the base ruby class
Matrix
which is made for such operations. I found out that it's not just adding require 'matrix' to your code.Because SketchUp was not distributed with the Ruby Standard Library until version 2014.
@ruts said:
I did copy the matrix.rb and e2mmap.rb (which is required by matrix.rb) from the ruby2.2.2 folder ...
This will not work, as you need to use the library compiled and distributed with the Ruby version that SketchUp uses. The constants
RUBY_VERSION
andRUBY_PATCHLEVEL
typed at the console tell you what SketchUp embedded Ruby is.@ruts said:
... I believe this is the right way to require 'matrix'.
Nope (when the standard library is properly installed,) just a simple
require 'matrix'
will do (because it will load it's own dependencies as it is evaluated.)@ruts said:
I think I already have a solution for my problem.
NO you don't, because you "don't have time to read the book," all this basic Ruby 101 knowledge is escaping you.
So just go to my GitHub repo and get the Standard Ruby 1.8.6-p287 Library packaged for SketchUp 2013 and earlier on Windows ONLY.
https://github.com/DanRathbun/sketchup-ruby186-stdlib-extension/releases/tag/2With SketchUp closed:
(1) Put the RBZ archive someplace where you can navigate easily to it.
(2) Delete any manually copied library files (such as those you mentioned copying above.)
(3) Then start SketchUp 8 and use the manual "Install Extension ..." button from
Window > Preferences > Extensions
(3a) Navigate to where you saved the RBZ archive, and select it, click OK.(4) Open the console and test that the paths are correctly set in
$LOAD_PATH
(aka$:
) by typing:
puts $:
and ENTER
You should see a listing similar to:
puts $:%(green)[C:/Program Files (x86)/SketchUp/SketchUp 8/Plugins C:/Program Files (x86)/SketchUp/SketchUp 8/Tools C:/Program Files (x86)/SketchUp/SketchUp 8/Plugins/Ruby186/lib/ruby/1.8 C:/Program Files (x86)/SketchUp/SketchUp 8/Plugins/Ruby186/lib/ruby/1.8/i386-mswin32 C:/Program Files (x86)/SketchUp/SketchUp 8/Plugins/Ruby186/lib/ruby/site_ruby/1.8 C:/Program Files (x86)/SketchUp/SketchUp 8/Plugins/Ruby186/lib/ruby/site_ruby/1.8/i386-msvcrt]nil
The actual program files path might also look like:
%(green)[C:/Program Files (x86)/Google/Google SketchUp 8/...]
(5) Then further test the loading of "matrix.rb" via:
require "matrix"
You should seetrue
returned.
Advertisement