sketchucation logo sketchucation
    • Login
    1. Home
    2. Ruts
    3. Posts
    ℹ️ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info
    R
    Offline
    • Profile
    • Following 0
    • Followers 0
    • Topics 2
    • Posts 17
    • Groups 1

    Posts

    Recent Best Controversial
    • RE: Find out if point is inside solid

      I'm not sure if there's an existing extension for this, but I use this kind of in my extension. Neither am I sure if my method is easiest way to go, it's quiet computing-intensive if you're solid is made out of many faces.

      NOTE: a line is infinite long in both directions and a half line is infinite long in one direction.

      It is based on the principle that a half line that starts in your point should intersect your solid an odd number of times. So you have to check every face of the solid if it intersects with the half line.

      Method intersect_line_plane calculates the intersection of the line (in both directions) and the plane of the face. You have to check if the intersection is on the half line and on the face of the plane.

      For checking if the intersection is part the face again it can be done with another half line which starts in the intersection and is parallel to the plane of the face. Once again the intersection is part of the face if the half line intersects the edges of the face an odd number of times. So you should check every edge of the face and see if the half line intersects it. The method intersect_line_line calculates the intersection between the line of the half line and the line of the edge. Check if this intersection is part of the half line and the edge.

      Hopefully this is helpfull to you, it may be fomulated a little chaotic. I can share some of my code if you want.

      posted in Developers' Forum
      R
      Ruts
    • RE: [New scripter] Will need help on my project (now and then)

      @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.

      posted in Developers' Forum
      R
      Ruts
    • RE: [New scripter] Will need help on my project (now and then)

      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?

      posted in Developers' Forum
      R
      Ruts
    • RE: [New scripter] Will need help on my project (now and then)

      @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).

      posted in Developers' Forum
      R
      Ruts
    • RE: [New scripter] Will need help on my project (now and then)

      @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.

      posted in Developers' Forum
      R
      Ruts
    • RE: [New scripter] Will need help on my project (now and then)

      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?

      posted in Developers' Forum
      R
      Ruts
    • RE: Compute Rotation and Scale from Transform Object

      @dan rathbun said:

      You realize that this topic thread is like 4 and 1/2 years old ?

      Yes, I have seen it. That does not mean that people can't come here and look for code that works? That's how I landed here. I was looking for some code that could convert the rotation matrix to euler angles. I found out that this code didn't work for me, so I did correct it and now I share it here just in case people experience the same problem as me. I'm just excited that I finally can contribute a little instead of always asking things!

      Nothing wrong with that, right?

      posted in Developers' Forum
      R
      Ruts
    • RE: [New scripter] Will need help on my project (now and then)

      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)?

      posted in Developers' Forum
      R
      Ruts
    • RE: Compute Rotation and Scale from Transform Object

      I did delete the rotX/Y/Z methods, that's why I didn't understand where the variable xyz came from and why it could get value = 0/1/2. I do understand how methods with there variables work. Sorry was confused.

      On the other hand, I have been working with the euler_angle method for a while and now that I'm closely getting to a complete script I have noticed this method only partial works (for me?). Does it work for you guys? When I did draw shapes with a given rotation, the method didn't succeed to calculate the right angles for me so I did some research and made some changes. Here's the code I use:

      	def self.rotation(trans)
      		b = [trans.xaxis.to_a, trans.yaxis.to_a, trans.zaxis.to_a]
      		m = b.transpose.flatten!
      		if m[6] != 1 and m[6] != -1
      			ry = -Math.asin(m[6])
      			rx = Math.atan2(m[7]/Math.cos(ry),m[8]/Math.cos(ry))
      			rz = Math.atan2(m[3]/Math.cos(ry),m[0]/Math.cos(ry))
      		else
      			rz = 0
      			phipos = Math.atan2(m[1],m[2])
      			phineg = Math.atan2(-m[1],-m[2])
      			if m[6] == -1
      				ry = Math;;PI/2
      				rx = rz + phipos
      			else
      				ry = -Math;;PI/2
      				rx = -rz + phineg
      			end
      		end   
      	return [rx.radians,ry.radians,rz.radians]
      	end	
      

      First I found this document (page 5) that explains the calculations the way you do it. But it seems that you miss little pieces of code to make it complete.

      When I did calculate the angles it yet didn't calculate the right angles. So I did try some things and found out that the angles that were calculated represent the transpose matrix of the rotation that I need. So I fixed this by transposing the rotation matrix before the calculations.

      With these changes this piece of code does calculate the right angles. Did your code work for you?

      posted in Developers' Forum
      R
      Ruts
    • RE: Adding input parameter to simple code

      I think I might be able to help you, but I'm a afraid I don't understand very well what you want to realize. Correct me if I'm wrong:

      So you create a rectangle as a group and want an easy way to change the size of the rectangle?

      If this is the case, I might be able to help you! I believe you are looking for UI.inputbox

      posted in Developers' Forum
      R
      Ruts
    • RE: Compute Rotation and Scale from Transform Object

      I have a question about the euler_angle method, especially about the xyz. I have searched the web and found information about this case, but it didn't result in an answer.

      Here's how I read this piece of code:

      when you call the method euler_angles you create an empty array under variable xyz as parameter. Then nothing happens with the array for the whole piece of code. At the end the array can be ==0 (contains one element which is equal to zero), ==1, ==2 or still empty. How can it be that the array can contain elements?

      posted in Developers' Forum
      R
      Ruts
    • RE: [New scripter] Will need help on my project (now and then)

      @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.

      posted in Developers' Forum
      R
      Ruts
    • RE: [New scripter] Will need help on my project (now and then)

      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.

      posted in Developers' Forum
      R
      Ruts
    • [New scripter] Will need help on my project (now and then)

      Hi sketchucation community,

      As the tittle says, I'm a new scripter who's working on a project. I have little experience with programming (had a 20 hours java course), but I did some online ruby training (learningrubythehardway.org). I'm planning to do some more training, but because I have a deathline on my project I'd like some specific help on my project from experienced people. I will use this topic whenever I'm stuck. I am not asking you to solve my problems, but point me towards the right direction.

      • Situation
        My name is Thomas and I'm a student industrial engineer. I will start my last year, which means I have to do my thesis in the form of an internship which I am doing at SCK-CEN. Coding a sketchup extension is part of the thesis.

      • Project (Sketchup part)
        VISIPLAN, an existing piece of software that does radiation calculations, needs a 3D environment to do its calculations. For now this environment is not created by a CAD program, but by a database with all the elements in it. for example: if I want to add a wall in the environment I insert following in the database: type = box, start coordinates, width/length/height, rotations round x-/y-/z-axis.

      In order to make the creation of the 3D environment easier we want to use a CAD program (Sketchup). The extension that I need to make translates the Sketchup model back to the parameters that the database from VISIPLAN understands.

      • Plan
        The user can only create the 3D environment by using primitive shapes like; box, sphere, cylinder, tube, ... . These extensions already exsist and only need minor changes in order to satisfy my needs.

      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. Then it extracts the information it needs to translate it to the parameters the database needs. (TIG's export vertices to CSV seems intresting)

      The only question I have got right now is if there are extensions that (partially) contain code that can be usefull for me?

      posted in Developers' Forum
      R
      Ruts
    • RE: SketchUp 2015 plugins location

      Small problem here.

      I can't find the AppData map. When I go to C:\Users<your_windows_user_name> I the map AppData isn't there. I already installed 2 extensions, so the path should be created right?

      There is a map called Roaming though, but there's no map SketchUp in it.

      posted in Plugins
      R
      Ruts
    • RE: Extract 3D information to regenerate the shape

      Thanks for your respons oceanembers,

      So let's say I have drawn a cube with a random rotation somewhere in the coordinate system. Is it possible to extract all the information like centeroid of the cube, width/length/heigth and rotation matrix or angles with ruby scripting? If this is the case this seems very intresting.

      It would also be nice if it detects which space figure it is by itself.

      Kind regards
      Ruts

      posted in Developers' Forum
      R
      Ruts
    • Extract 3D information to regenerate the shape

      Hi,

      I am going to expand a piece of software that calculates radiation in a 3D environment. For now we create the 3D environment by using simple basic shapes like boxes,spheres,cylinders,... . All those different shapes which form the complete 3D environment are listed in a database. This database saves which kind of shape it is and some parameters to determine the size, place and rotation in the coordinate system.

      For example if I want to create a simple box I insert following in the database:

      • type:Box* First corner coordinates (X,Y,Z)* Width,Length and Heigth* Rotation from X-,Y- or Z-axis

      We want to expand our software so we don't have to insert every shape in the database, but can draw those shapes in a CAD program. My plan is to find a CAD program that's able to draw a 3D sketch with basic shapes and can give me the parameters according it's geometrical position in the coordinate system. I was wondering if this is possible with Sketchup (Pro)?

      Once I can retrieve the parameters of the shapes I can create a little program that translates those parameters into the parameters that our piece of software understands.

      Kind regards
      Ruts

      posted in Developers' Forum
      R
      Ruts
    • 1 / 1