else ( Parametric )
About this tool :
Also see :
- Startup code
- if statement (precedes else statement in code)
- elif statement (may precede else statement in code)
- Using a text editor
This script prints the " Bearing depth " (in decimal inches) that is reported in the local shape file for the joist that the user selects. If the user selects a member type other than a joist, the parametric prints, "You selected a xxx -- select a joist instead."
# Prints the bearing depth of the joist you select.
from member import MemberLocate
from param import ClearSelection, Units
Units("feet") #sets output to decimal inches
mem1 = MemberLocate("Select a joist")
if mem1.Type == "Joist":
print("Joist bearing depth is:", mem1.BearingDepth)
else:
print("You selected a", mem1.Type, "-- select a joist instead.")
ClearSelection()
This next script prints the distance from a user-located point and either another user-located point or the 0, 0, 0 global coordinate . This is the example used in the step-by-step instructions . Note how if and else are used. Also note that, since Units("feet") is specified in this script, the output using dim_print() will be feet-inches fractions , no matter what the specified primary dimension " Units " are in setup.
# Distance from user-located point to origin or to other point.
from point import PointLocate, Point
from param import Units, yes_or_no, dim_print
Units("feet")
pt1 = PointLocate("Locate a point")
pt3 = Point(0, 0, 0)
var = yes_or_no("From point or origin?", "point", pt3)
if var is "point":
pt2 = PointLocate("Locate another point")
print(dim_print(pt1.Distance(pt2)))
else:
print(dim_print(pt1.Distance(pt3)))
Tip: See Copying and Pasting scripts from Help for information on how to paste these scripts into blank .py text files that you can Run as parametrics in Modeling .