Sketchup has a ruby interface that allows you to easily develop plug-ins you need. First, we will try to draw a ball. However, there is a small problem, that is, when we draw the same ball continuously (with the same radius and ball Center), we will not only see the new ball, but even delete the original one. We need to study it again.
The Code is as follows:
Require 'sketchup. rb'
@ Cx = 0
@ Cy = 0
@ Cz = 0
Def drawshpere (center, radius)
# Access the entities object
Ents = sketchup. active_model.entities
# Create the initial circle
Circle = ENTs. add_circle center, [0, 0, 1], radius
Circle_face = ENTs. add_face circle
# Create the circular path
Path = ENTs. add_circle center, [0, 1, 0], radius + 1
# Create the sphere
Circle_face.followme path
# Remove the path
ENTs. erase_entities path
End
Def auto_sphere
Prompts = ["CX", "Cy", "CZ", "R"]
Types = ["", ""]
Title = "shpere parameter"
@ Cx = 0 if not @ CX
@ Cy = 0 if not @ cy
@ Cz = 0 if not @ CZ
@ Radius = 5 if not @ radius
Values = [@ CX, @ cy, @ CZ, @ radius]
Popups = ["", ""]
Results = inputbox (prompts, values, popups, title)
Return nil if not results
@ Cx = Results [0]
@ Cy = Results [1]
@ Cz = Results [2]
@ Radius = Results [3]
Center = [@ CX, @ cy, @ CZ]
Drawshpere (center, @ radius)
End
If (not file_loaded? (_ File __))
Ui. menu ("plugins"). add_item ("autosphere") {auto_sphere}
End
File_loaded (_ file __)
Input parameters:
Generate sphere: