2020# This allows the diagram to be moved afterwards without having to redefine the parameters.
2121
2222
23+ def get_location ():
24+ option = rs .GetString ("Location" , strings = ["Origin" , "Coordinates" , "Point" ])
25+ if not option :
26+ return
27+
28+ if option == "Origin" :
29+ point = (0 , 0 )
30+
31+ elif option == "Coordinates" :
32+ x = rs .GetReal ("X" , 0.0 , - 1000.0 , 1000.0 )
33+ if x is None :
34+ return
35+
36+ y = rs .GetReal ("Y" , 0.0 , - 1000.0 , 1000.0 )
37+ if y is None :
38+ return
39+
40+ point = (x , y )
41+
42+ elif option == "Point" :
43+ point = rs .GetPoint ("Point" )
44+ if not point :
45+ return
46+
47+ else :
48+ raise NotImplementedError
49+
50+ return point [0 ], point [1 ]
51+
52+
2353def RunCommand ():
2454 session = Session ()
2555
@@ -80,6 +110,10 @@ def RunCommand():
80110 # =============================================================================
81111
82112 if option == "Circular" :
113+ center = get_location ()
114+ if not center :
115+ return
116+
83117 radius = rs .GetReal ("Radius" , number = 1.0 , minimum = 0.0 )
84118 if not radius :
85119 return
@@ -97,65 +131,60 @@ def RunCommand():
97131 return
98132
99133 formdiagram = FormDiagram .create_circular_radial (
100- center = ( 0 , 0 ) ,
134+ center = center ,
101135 radius = radius ,
102136 n_hoops = rings ,
103137 n_parallels = radials ,
104138 r_oculus = oculus ,
105139 )
106140
107- session ["params" ]["formdiagram" ] = "circular"
108- session ["params" ]["center" ] = (0 , 0 )
109- session ["params" ]["radius" ] = radius
110- session ["params" ]["n_hoops" ] = rings
111- session ["params" ]["n_parallels" ] = radials
112- session ["params" ]["r_oculus" ] = oculus
113-
114141 # =============================================================================
115142 # From a cross vault pattern
116143 # =============================================================================
117144
118145 elif option == "Cross" :
119- xsize = rs .GetReal ("XSize" , number = 10 , minimum = 0 )
120- if not xsize :
146+ point = get_location ()
147+ if not point :
148+ return
149+
150+ x_size = rs .GetReal ("X Size" , 10 , 0.0 , 1000 )
151+ if not x_size :
121152 return
122- x_span = (0 , xsize )
123153
124- ysize = rs .GetReal ("YSize " , number = xsize , minimum = 0 )
125- if not ysize :
154+ y_size = rs .GetReal ("Y Size " , 10 , 0.0 , 1000 )
155+ if not y_size :
126156 return
127- y_span = (0 , ysize )
128157
129- n = rs .GetInteger ("Resolution" , 10 , 2 )
158+ n = rs .GetInteger ("Resolution" , 10 , 0 )
130159 if not n :
131160 return
132161
162+ x_span = (point [0 ], point [0 ] + x_size )
163+ y_span = (point [1 ], point [1 ] + y_size )
164+
133165 formdiagram = FormDiagram .create_cross (
134166 x_span = x_span ,
135167 y_span = y_span ,
136168 n = n ,
137169 supports = None , # type: ignore
138170 )
139171
140- session ["params" ]["formdiagram" ] = "cross"
141- session ["params" ]["x_span" ] = x_span
142- session ["params" ]["y_span" ] = y_span
143- session ["params" ]["n" ] = n
144-
145172 # =============================================================================
146173 # From a fan vault pattern
147174 # =============================================================================
148175
149176 elif option == "Fan" :
150- xsize = rs . GetReal ( "XSize" , number = 10 , minimum = 0 )
151- if not xsize :
177+ point = get_location ( )
178+ if not point :
152179 return
153- x_span = (0 , xsize )
154180
155- ysize = rs .GetReal ("YSize" , number = xsize , minimum = 0 )
156- if not ysize :
181+ x_size = rs .GetReal ("X Size" , 10 , 0.0 , 1000 )
182+ if not x_size :
183+ return
184+
185+ y_size = rs .GetReal ("Y Size" , 10 , 0.0 , 1000 )
186+ if not y_size :
157187 return
158- y_span = (0 , ysize )
159188
160189 n_fans = rs .GetInteger ("Number of Fans" , 10 , 2 )
161190 if not n_fans :
@@ -165,6 +194,9 @@ def RunCommand():
165194 if not n_hoops :
166195 return
167196
197+ x_span = (point [0 ], point [0 ] + x_size )
198+ y_span = (point [1 ], point [1 ] + y_size )
199+
168200 formdiagram = FormDiagram .create_fan (
169201 x_span = x_span ,
170202 y_span = y_span ,
@@ -173,26 +205,22 @@ def RunCommand():
173205 supports = None , # type: ignore
174206 )
175207
176- session ["params" ]["formdiagram" ] = "fan"
177- session ["params" ]["x_span" ] = x_span
178- session ["params" ]["y_span" ] = y_span
179- session ["params" ]["n_fans" ] = n_fans
180- session ["params" ]["n_hoops" ] = n_hoops
181-
182208 # =============================================================================
183209 # From an orthogonal pattern
184210 # =============================================================================
185211
186212 elif option == "Ortho" :
187- xsize = rs . GetReal ( "XSize" , number = 10 , minimum = 0 )
188- if not xsize :
213+ point = get_location ( )
214+ if not point :
189215 return
190- x_span = (0 , xsize )
191216
192- ysize = rs .GetReal ("YSize" , number = xsize , minimum = 0 )
193- if not ysize :
217+ x_size = rs .GetReal ("X Size" , 10 , 0.0 , 1000 )
218+ if not x_size :
219+ return
220+
221+ y_size = rs .GetReal ("Y Size" , 10 , 0.0 , 1000 )
222+ if not y_size :
194223 return
195- y_span = (0 , ysize )
196224
197225 nx = rs .GetInteger ("Number of X Faces" , 10 , 2 )
198226 if not nx :
@@ -202,6 +230,9 @@ def RunCommand():
202230 if not ny :
203231 return
204232
233+ x_span = (point [0 ], point [0 ] + x_size )
234+ y_span = (point [1 ], point [1 ] + y_size )
235+
205236 formdiagram = FormDiagram .create_ortho (
206237 x_span = x_span ,
207238 y_span = y_span ,
@@ -210,12 +241,6 @@ def RunCommand():
210241 supports = None , # type: ignore
211242 )
212243
213- session ["params" ]["formdiagram" ] = "ortho"
214- session ["params" ]["x_span" ] = x_span
215- session ["params" ]["y_span" ] = y_span
216- session ["params" ]["nx" ] = nx
217- session ["params" ]["ny" ] = ny
218-
219244 # =============================================================================
220245 # Not supported
221246 # =============================================================================
0 commit comments