Sketchup Ruby development test plug-in

Source: Internet
Author: User

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:

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.