Thanks TIG that worked
Latest posts made by pmagans
-
RE: [Plugin] Import ALL from Folder
TIG,
Do you know of any .stl batch importers? I have found two .stl importers but nothing with the batch capabilities.
Thanks -
RE: Intersecting Hollow Objects using intersect_with
Well I've been using the "solid" tools for the last few days and it is a whole lot easier than what I was trying before. It would be nice to find a non-Pro version, for home use. The following is my test_code. I will re-write using Dan's previous post as a guide. It's a little over my head at this moment and I'm still trying to completly understand it.
module PMA_INT_TEST require('sketchup.rb') l = 1.50 w = 1.50 t = 0.078 h = 20 model = Sketchup.active_model ents = model.entities #Just test geometry pt1 = [0,0,0] pt2 = [l,0,0] pt3 = [l,w,0] pt4 = [0,w,0] object_group = ents.add_group() object_group.name = "OBJECT GROUP" cpt = object_group.entities.add_cpoint(ORIGIN) face1 = object_group.entities.add_face pt1,pt2,pt3,pt4 cpt.erase! pt1 = [0+t,0+t,0] pt2 = [l-t,0+t,0] pt3 = [l-t,w-t,0] pt4 = [0+t,w-t,0] face2 = object_group.entities.add_face pt1,pt2,pt3,pt4 face2.erase! face1.reverse! face1.pushpull h #Creating Test Cutgroup1 cut_group1 = ents.add_group() cpt = cut_group1.entities.add_cpoint(ORIGIN) pt1 = [0,0,0] pt2 = [l,0,0] pt3 = [l,w,0] pt4 = [0,w,0] face3 = cut_group1.entities.add_face pt1,pt2,pt3,pt4 face3.reverse! face3.pushpull h t1 = Geom;;Transformation.translation [0,0,10] ts1 = Geom;;Transformation.scaling [l/2,w/2,0], 10 tr1 = Geom;;Transformation.rotation [0, 0, 0], [1, 0, 0], 10.degrees cut_group1.transform! tr1 * t1 * ts1 cut_group1.name = "CUT GROUP1" cpt.erase! #Creating Test Cutgroup2 cut_group2 = ents.add_group() cpt = cut_group2.entities.add_cpoint(ORIGIN) pt1 = [0,0,0] pt2 = [l,0,0] pt3 = [l,w,0] pt4 = [0,w,0] face4 = cut_group2.entities.add_face pt1,pt2,pt3,pt4 face4.pushpull h t2 = Geom;;Transformation.translation [0,0,1] tr2 = Geom;;Transformation.rotation [0, 0, 0], [1, 0, 0], -10.degrees cut_group2.transform! tr2 * t2 * ts1 cut_group2.name = "CUT GROUP2" cpt.erase! #Create "NEW" group from cut group and from object group UI.messagebox("CUTTING") cut_group = cut_group1.subtract(object_group) cut_group = cut_group2.subtract(cut_group) cut_group.name = "NEW NAME" end #of module PMA_INT_TEST
-
RE: Intersecting Hollow Objects using intersect_with
Thanks TIG. I am still working on this and will post my results.
On a side note:
I tried to create a function in the module I wrapped everything in and it won't load in Sketchup but works fine outside of the function block.
ex.module PMA_INT_TEST ..code here to create geometry end #of module
load PMA_INT_TEST.rb into Sketchup works fine
then I changed:
module PMA_INT_TEST create_geometry() def create_geometry() exact same..code here to create geometry end end #of module
load PMA_INT_TEST.rb into Sketchup get:
Error: #<NoMethodError: undefined method `create_geometry' for PMA_INT_TEST:Module> -
RE: Help Understanding Classes and Class objects
@dan rathbun said:
Bookmark that page.
Done, thanks for the link.
I remember doing the tutorials when DC's first came out but have forgotton the majority of what I learned so I guess I will be spending some time there first.
-
RE: Help Understanding Classes and Class objects
@dan rathbun said:
But of course the coding means is not documented because the Free license users are not supposed to do it. (... or at least use a wizard interface.)
That's a bummer. I like the concept of dynamic tools for locking up variables and documenting the components, but I hate the user interface! It would just take me too long through traditional means to create a workable library. And of course if I wanted to change something I would have to do it in multiple places. I will do a more active search for creating/modifying dynamic components through Ruby. So far what I have found has not been that helpful besides holding/setting attributes. Any tips on where to start?
Thanks! -
RE: Intersecting Hollow Objects using intersect_with
Thanks for the plugins, TIG! Those are awesome starting points for me. I will need to modify them so that they work for any plane that is non-orthogonal to the orgin. But I think that's just a matter of creating a "plane" through code and not choosing it like the plugin. Thanks again!
-
RE: Intersecting Hollow Objects using intersect_with
Thanks TIG,
I will definitely give that a go. I'll have to start up my work computer to give it a try though. I use the "free" version on a mac at home and the Pro windows version on my work laptop.Dan your thoughts are exactly where I wanted to go with being able to pick a direction for the cut. I envisioned a future user prompt to pick a side. I still think I could make it look like a plane being cut using TIG's described method by creating the geometry after the pick. But as a tool it would only be usable on a Pro machine it sounds.
I thought using the array comparisons would be a quick check of the entities created, but actually it didn't work out well because it looks as though Sketchup "redraws" entities like lines and faces when the intersect_with happens even if it's basically the same location. That's why I started down the checking edges, then checking vertices, etc.
-
Intersecting Hollow Objects using intersect_with
So I am attempting to use planes to cut a hollow object. I am having trouble with the weird conditions such as:
Plane cutting a line in the object
The array comparisons don't seem to work on faces and entities reliably? any thoughts?
I did some Array math to help myself out but I think I'm confusing how Sketchup creates entities.array1 = [1,2,3,4,5] array2 = [1,3,5,6] array3 = array1 | array2 array4 = array1 & array2 array5 = array1 - array2 array6 = array1 + array2 array7 = array2 | array1 array8 = array2 & array1 array9 = array2 - array1 array10 = array2 + array1 array11 = (array1 | array2) - (array1 & array2) puts "array1 = " + array1.to_s puts "array2 = " +array2.to_s puts "UNION 1&2 = " +array3.to_s puts "INT 1&2 = " +array4.to_s puts "Diff 1-2 = " +array5.to_s puts "Add 1+2 = " +array6.to_s puts "UNION 2&1 = " +array7.to_s puts "INT 2&1 = " +array8.to_s puts "Diff 2-1 = " +array9.to_s puts "Add 2+1 = " +array10.to_s puts "UN 1-2 - int 1-2 = " +array11.to_s =begin ARRAY MATH EXAMPLE array1 = 12345 array2 = 1356 UNION 1&2 = 123456 same but order changed UNION 2&1 = 135624 INT 1&2 = 135 and INT 2&1 are SAME! Diff 1-2 = 24 Add 1+2 = 123451356 same but order changed Add 2+1 = 135612345 Diff 2-1 = 6 UN 1-2 - int 1-2 = 246 =end
module PMA_Intersect require 'sketchup.rb' mod = Sketchup.active_model ents = mod.entities #Just test geometry pt1 = [0,0,0] pt2 = [10,0,0] pt3 = [10,10,0] pt4 = [0,10,0] group = ents.add_group face = group.entities.add_face pt1,pt2,pt3,pt4 off = 1 pt1_in = [0+off,0+off,0] pt2_in = [10-off,0+off,0] pt3_in = [10-off,10-off,0] pt4_in = [0+off,10-off,0] face2 = group.entities.add_face pt1_in,pt2_in,pt3_in,pt4_in face2.erase! face.reverse! face.pushpull 20 #Creating Test Cutgroup cut_group = ents.add_group cut_group.entities.add_face pt1,pt2,pt3,pt4 t1 = Geom;;Transformation.translation [0,0,10] t2 = Geom;;Transformation.scaling [5,5,0], 3 tr1 = Geom;;Transformation.rotation [0, 0, 16.5], [1, 0, 0], 10.degrees cut_group.transform! t1 * t2 * tr1 cut_tran = cut_group.transformation group_tran = group.transformation #Entity to cut will be transformed based on the cutting cut_group #provided. Both entity and cut_group need to be a group passed original_faces = [] original_edges = [] group.entities.each do |e| original_faces << e if e.is_a? Sketchup;;Face original_edges << e if e.is_a? Sketchup;;Edge end cut_trans = cut_group.transformation entity_trans = group.transformation #entities.intersect_with recurse, trans1, entities1, trans2, hidden, entities2 result = ents.add_group(cut_group.entities.intersect_with( true, cut_tran, group, group_tran , true, group)) cut_group.erase! result.erase! new_faces = [] group.entities.each do |e| new_faces << e if e.is_a? Sketchup;;Face end # Array Union and subtraction to find the unique faces unique_faces = [] unique_faces = (original_faces | new_faces) - (original_faces & new_faces) face_selection = [] new_faces.each do |e| unique_faces.each do |eo| if eo.vertices == e.vertices face_selection << e end end end face_selection.each do |e| e.erase! end left_faces = [] left_edges = [] group.entities.each do |e| left_faces << e if e.is_a? Sketchup;;Face left_edges << e if e.is_a? Sketchup;;Edge end to_erase = [] left_edges.each do |e| if e.faces[0] == nil e.erase! #to_erase << e end end end #of PMA_Intersect module
-
RE: Help Understanding Classes and Class objects
I will check into the mixin module approach also the dynamic components. Are dynamic components "create-able" through Ruby code or only through the Sketchup interface?
The only info/tutorial I could find was:
http://sketchucation.com/forums/viewtopic.php?f=180&t=17888&p=145120&hilit=dynamic+component+tutorial#p145120