Adding input parameter to simple code
-
Hi
I'm a beginner at making codes and am currently doing a work which 3D model is changed to 2D plan(its similar with 'section plane') with a code which I personally made. I used to change the size of retangle by inputting numbers into the coordinates(p1~p5), but it was a troublesome work. Inputting number to a created box may be more handy for my main work. Could you please help me create an box which can input coordinates? The codes I made is shown below
model = Sketchup.active_model entities = model.entities group_a=entities.add_group entities.to_a entities_a=group_a.entities trans_a=group_a.transformation group_b=entities.add_group entities_b=group_b.entities p1 = [0, 0, 1000.mm] p2 = [15000.mm, 0, 1000.mm] p3 = [15000.mm, 15000.mm, 1000.mm] p4 = [0, 15000.mm, 1000.mm] p5 = [0, 0, 1000.mm] entities_b.add_face(p1,p2,p3,p4,p5) trans_b=group_b.transformation entities_a.intersect_with true, trans_a, group_b, trans_b , true, group_b group_b.explode group_a.erase!
-
did you consider using the
model.bounds.corner
method to then use as group_b points?just a thought
john
-
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
-
Yes right, I was talking about adding 'UI.input box' to the codes and would like to make the coordinates act like variables. Hmmm.. X and Y coordinates will correspond to length and width of rectangle, and Z coordinates will correspond to height of generated rectangle.
After making rectangle automatically, objects in space will be cut by the rectangle. It is like a process of making cross section. This work could have been finished manually, but so many objects are involved in my work. Defining all entities and being cut and removed by rectangle automatically would be easier by making codes
-
Assuming you wrap all of your code in a method inside your own module...
@x = 1.m unless @x @y = 1.m unless @y @z = 0.m unless @z results = inputbox(['X: ', 'Y: ', 'Z: '], [@x, @y, @z], 'Slicing Rectangle Dims') return nil unless results @x, @y, @z = results
BUT then you need to decide the values for each point...
If all of the slices are in plan then only the Z value is important.
Can I suggest you use:
bb = model.bounds min = bb.min max = bb.max
then a single input for the Z thus:
@z = 0.m unless @z results = inputbox(['Z: '], [@z], 'Slicing Height') return nil unless results @z = results[0]
Extract the x/y/z values from min and max and make the points for the face from those...
p1 = [min.x, min.y, @z] p2 = [max.x, min.y, @z] p3 = [max.x, max.y, @z] p4 = [min.x, max.y, @z]
later
entities_b.add_face(p1, p2, p3, p4)
Note how whe adding a face you only need the points for each vertex, if you were adding edges you need to add the extra 'p5' to close the loop.
Advertisement