-
Notifications
You must be signed in to change notification settings - Fork 72
Expand file tree
/
Copy pathview.py
More file actions
1574 lines (1461 loc) · 54.5 KB
/
Copy pathview.py
File metadata and controls
1574 lines (1461 loc) · 54.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import scriptcontext
import utility as rhutil
import Rhino
import System.Enum
import math
def __viewhelper(view):
if view is None: return scriptcontext.doc.Views.ActiveView
allviews = scriptcontext.doc.Views.GetViewList(True, True)
view_id = rhutil.coerceguid(view, False)
for item in allviews:
if view_id:
if item.MainViewport.Id == view_id: return item
elif item.MainViewport.Name == view:
return item
raise ValueError("unable to coerce %s into a view"%view)
def AddDetail(layout_id, corner1, corner2, title=None, projection=1):
"""Add new detail view to an existing layout view
Parameters:
layout_id (guid): identifier of an existing layout
corner1, corner2 (point): 2d corners of the detail in the layout's unit system
title (str, optional): title of the new detail
projection (number, optional): type of initial view projection for the detail
1 = parallel top view
2 = parallel bottom view
3 = parallel left view
4 = parallel right view
5 = parallel front view
6 = parallel back view
7 = perspective view
Returns:
guid: identifier of the newly created detail on success
None: on error
Example:
import rhinoscriptsyntax as rs
layout = rs.AddLayout("Portrait", (8.5,11))
if layout:
rs.AddDetail(layout, (0.5,0.5), (8,10.5), None, 7)
See Also:
DeleteNamedView
NamedViews
RestoreNamedView
"""
layout_id = rhutil.coerceguid(layout_id, True)
corner1 = rhutil.coerce2dpoint(corner1, True)
corner2 = rhutil.coerce2dpoint(corner2, True)
if projection<1 or projection>7: raise ValueError("projection must be a value between 1-7")
layout = scriptcontext.doc.Views.Find(layout_id)
if not layout: raise ValueError("no layout found for given layout_id")
projection = System.Enum.ToObject(Rhino.Display.DefinedViewportProjection, projection)
detail = layout.AddDetailView(title, corner1, corner2, projection)
if not detail: return scriptcontext.errorhandler()
scriptcontext.doc.Views.Redraw()
return detail.Id
def AddLayout(title=None, size=None):
"""Adds a new page layout view
Parameters:
title (str, optional): title of new layout
size ([number, number], optional): width and height of paper for the new layout
Returns:
guid: id of new layout
Example:
import rhinoscriptsyntax as rs
rs.AddLayout("Portrait")
See Also:
DeleteNamedView
NamedViews
RestoreNamedView
"""
page = None
if size is None: page = scriptcontext.doc.Views.AddPageView(title)
else: page = scriptcontext.doc.Views.AddPageView(title, size[0], size[1])
if page: return page.MainViewport.Id
def AddNamedCPlane(cplane_name, view=None):
"""Adds new named construction plane to the document
Parameters:
cplane_name (str): the name of the new named construction plane
view (guid|str): Title or identifier of the view from which to save
the construction plane. If omitted, the current active view is used.
Returns:
atr: name of the newly created construction plane if successful
None: on error
Example:
import rhinoscriptsyntax as rs
views = rs.ViewNames()
if views:
for view in views:
name = view + "_cplane"
rs.AddNamedCPlane( name, view )
See Also:
DeleteNamedCPlane
NamedCPlane
NamedCPlanes
RestoreNamedCPlane
"""
view = __viewhelper(view)
if not cplane_name: raise ValueError("cplane_name is empty")
plane = view.MainViewport.ConstructionPlane()
index = scriptcontext.doc.NamedConstructionPlanes.Add(cplane_name, plane)
if index<0: return scriptcontext.errorhandler()
return cplane_name
def AddNamedView(name, view=None):
"""Adds a new named view to the document
Parameters:
name (str): the name of the new named view
view: (guid|str): the title or identifier of the view to save. If omitted, the current
active view is saved
Returns:
str: name fo the newly created named view if successful
None: on error
Example:
import rhinoscriptsyntax as rs
views = rs.ViewNames()
if views:
for view in views:
name = view + "_view"
rs.AddNamedView( name, view )
See Also:
DeleteNamedView
NamedViews
RestoreNamedView
"""
view = __viewhelper(view)
if not name: raise ValueError("name is empty")
viewportId = view.MainViewport.Id
index = scriptcontext.doc.NamedViews.Add(name, viewportId)
if index<0: return scriptcontext.errorhandler()
return name
def CurrentDetail(layout, detail=None, return_name=True):
"""Returns or changes the current detail view in a page layout view
Parameters:
layout (str|guid): title or identifier of an existing page layout view
detail (str|guid, optional): title or identifier the the detail view to set
return_name (bool, optional): return title if True, else return identifier
Returns:
str: if detail is not specified, the title or id of the current detail view
str: if detail is specified, the title or id of the previous detail view
None: on error
Example:
import rhinoscriptsyntax as rs
layout = rs.CurrentView(return_name=False)
if rs.IsLayout(layout):
rs.CurrentDetail( layout, layout )
See Also:
IsDetail
IsLayout
"""
layout_id = rhutil.coerceguid(layout)
page = None
if layout_id is None: page = scriptcontext.doc.Views.Find(layout, False)
else: page = scriptcontext.doc.Views.Find(layout_id)
if page is None: return scriptcontext.errorhandler()
rc = None
active_viewport = page.ActiveViewport
if return_name: rc = active_viewport.Name
else: rc = active_viewport.Id
if detail:
id = rhutil.coerceguid(detail)
if( (id and id==page.MainViewport.Id) or (id is None and detail==page.MainViewport.Name) ):
page.SetPageAsActive()
else:
if id: page.SetActiveDetail(id)
else: page.SetActiveDetail(detail, False)
scriptcontext.doc.Views.Redraw()
return rc
def CurrentView(view=None, return_name=True):
"""Returns or sets the currently active view
Parameters:
view (str|guid): Title or id of the view to set current.
If omitted, only the title or identifier of the current view is returned
return_name (bool, optional): If True, then the name, or title, of the view is returned.
If False, then the identifier of the view is returned
Returns:
str: if the title is not specified, the title or id of the current view
str: if the title is specified, the title or id of the previous current view
None: on error
Example:
import rhinoscriptsyntax as rs
previous = rs.CurrentView("Perspective")
print "The previous current view was ", previous
viewId = rs.CurrentView( return_name=False )
print "The identifier of the current view is ", viewId
See Also:
IsViewCurrent
ViewNames
"""
rc = None
if return_name: rc = scriptcontext.doc.Views.ActiveView.MainViewport.Name
else: rc = scriptcontext.doc.Views.ActiveView.MainViewport.Id
if view:
id = rhutil.coerceguid(view)
rhview = None
if id: rhview = scriptcontext.doc.Views.Find(id)
else: rhview = scriptcontext.doc.Views.Find(view, False)
if rhview is None: return scriptcontext.errorhandler()
scriptcontext.doc.Views.ActiveView = rhview
return rc
def DeleteNamedCPlane(name):
"""Removes a named construction plane from the document
Parameters:
name (str): name of the construction plane to remove
Returns:
bool: True or False indicating success or failure
Example:
import rhinoscriptsyntax as rs
cplanes = rs.NamedCplanes()
if cplanes:
for cplane in cplanes: rs.DeleteNamedCPlane(cplane)
See Also:
AddNamedCPlane
NamedCPlane
NamedCPlanes
RestoreNamedCPlane
"""
return scriptcontext.doc.NamedConstructionPlanes.Delete(name)
def DeleteNamedView(name):
"""Removes a named view from the document
Parameters:
name (str): name of the named view to remove
Returns:
bool: True or False indicating success or failure
Example:
import rhinoscriptsyntax as rs
views = rs.NamedViews()
if views:
for view in views: rs.DeleteNamedView(view)
See Also:
AddNamedView
NamedViews
RestoreNamedView
"""
return scriptcontext.doc.NamedViews.Delete(name)
def DetailLock(detail_id, lock=None):
"""Returns or modifies the projection locked state of a detail
Parameters:
detail_id (guid): identifier of a detail object
lock (bool, optional) the new lock state
Returns:
bool: if lock==None, the current detail projection locked state
bool: if lock is True or False, the previous detail projection locked state
None: on error
Example:
import rhinoscriptsyntax as rs
detail = rs.GetObject("select a detail", rs.filter.detail)
if detail: rs.DetailLock(detail,True)
See Also:
IsDetail
IsLayout
"""
detail_id = rhutil.coerceguid(detail_id, True)
detail = scriptcontext.doc.Objects.Find(detail_id)
if not detail: return scriptcontext.errorhandler()
rc = detail.DetailGeometry.IsProjectionLocked
if lock is not None and lock!=rc:
detail.DetailGeometry.IsProjectionLocked = lock
detail.CommitChanges()
return rc
def DetailScale(detail_id, model_length=None, page_length=None):
"""Returns or modifies the scale of a detail object
Parameters:
detail_id (guid): identifier of a detail object
model_length (number, optional): a length in the current model units
page_length (number, optional): a length in the current page units
Returns:
number: current page to model scale ratio if model_length and page_length are both None
number: previous page to model scale ratio if model_length and page_length are values
None: on error
Example:
import rhinoscriptsyntax as rs
detail = rs.GetObject("select a detail", rs.filter.detail)
if detail: rs.DetailScale(detail,1,1)
See Also:
IsDetail
IsLayout
"""
detail_id = rhutil.coerceguid(detail_id, True)
detail = scriptcontext.doc.Objects.Find(detail_id)
if detail is None: return scriptcontext.errorhandler()
rc = detail.DetailGeometry.PageToModelRatio
if model_length or page_length:
if model_length is None or page_length is None:
return scriptcontext.errorhandler()
model_units = scriptcontext.doc.ModelUnitSystem
page_units = scriptcontext.doc.PageUnitSystem
if detail.DetailGeometry.SetScale(model_length, model_units, page_length, page_units):
detail.CommitChanges()
scriptcontext.doc.Views.Redraw()
return rc
def IsDetail(layout, detail):
"""Verifies that a detail view exists on a page layout view
Parameters:
layout (str|guid): title or identifier of an existing page layout
detail (str|guid): title or identifier of an existing detail view
Returns:
bool: True if detail is a detail view
bool: False if detail is not a detail view
None: on error
Example:
import rhinoscriptsyntax as rs
view = rs.CurrentView()
if rs.IsLayout(view):
isdetail = rs.IsDetail(view, "Top")
if isdetail:
print "Top is a detail view."
else:
print "Top is not a detail view."
See Also:
IsLayout
CurrentDetail
"""
layout_id = rhutil.coerceguid(layout)
views = scriptcontext.doc.Views.GetViewList(False, True)
found_layout = None
for view in views:
if layout_id:
if view.MainViewport.Id==layout_id:
found_layout = view
break
elif view.MainViewport.Name==layout:
found_layout = view
break
# if we couldn't find a layout, this is an error
if found_layout is None: return scriptcontext.errorhandler()
detail_id = rhutil.coerceguid(detail)
details = view.GetDetailViews()
if not details: return False
for detail_view in details:
if detail_id:
if detail_view.Id==detail_id: return True
else:
if detail_view.Name==detail: return True
return False
def IsLayout(layout):
"""Verifies that a view is a page layout view
Parameters:
layout (guid|str): title or identifier of an existing page layout view
Returns:
bool: True if layout is a page layout view
bool: False is layout is a standard, model view
None: on error
Example:
import rhinoscriptsyntax as rs
view = rs.CurrentView()
if rs.IsLayout(view):
print "The current view is a page layout view."
else:
print "The current view is standard, model view."
See Also:
IsLayout
CurrentDetail
"""
layout_id = rhutil.coerceguid(layout)
alllayouts = scriptcontext.doc.Views.GetViewList(False, True)
for layoutview in alllayouts:
if layout_id:
if layoutview.MainViewport.Id==layout_id: return True
elif layoutview.MainViewport.Name==layout: return True
allmodelviews = scriptcontext.doc.Views.GetViewList(True, False)
for modelview in allmodelviews:
if layout_id:
if modelview.MainViewport.Id==layout_id: return False
elif modelview.MainViewport.Name==layout: return False
return scriptcontext.errorhandler()
def IsView(view):
"""Verifies that the specified view exists
Parameters:
view (str|guid): title or identifier of the view
Returns:
bool: True of False indicating success or failure
Example:
import rhinoscriptsyntax as rs
title = "Perspective"
result = rs.IsView(title)
if result:
print "The " + title + " view exists."
else:
print "The " + title + " view does not exist."
See Also:
ViewNames
"""
view_id = rhutil.coerceguid(view)
if view_id is None and view is None: return False
allviews = scriptcontext.doc.Views.GetViewList(True, True)
for item in allviews:
if view_id:
if item.MainViewport.Id==view_id: return True
elif item.MainViewport.Name==view: return True
return False
def IsViewCurrent(view):
"""Verifies that the specified view is the current, or active view
Parameters:
view (str|guid): title or identifier of the view
Returns:
bool: True of False indicating success or failure
Example:
import rhinoscriptsyntax as rs
title = "Perspective"
result = rs.IsViewCurrent(title)
if result:
print "The " + title + " view is current."
else:
print "The " + title + " view is not current."
See Also:
CurrentView
"""
activeview = scriptcontext.doc.Views.ActiveView
view_id = rhutil.coerceguid(view)
if view_id: return view_id==activeview.MainViewport.Id
return view==activeview.MainViewport.Name
def IsViewMaximized(view=None):
"""Verifies that the specified view is maximized (enlarged so as to fill
the entire Rhino window)
Parameters:
view: (str|guid): title or identifier of the view. If omitted, the current
view is used
Returns:
bool: True of False
Example:
import rhinoscriptsyntax as rs
title = rs.CurrentView()
result = rs.IsViewMaximized(title)
if result:
print "The " + title + " view is maximized."
else:
print "The " + title + " view is not maximized."
See Also:
MaximizeRestoreView
"""
view = __viewhelper(view)
return view.Maximized
def IsViewPerspective(view):
"""Verifies that the specified view's projection is set to perspective
Parameters:
view (str|guid): title or identifier of the view
Returns:
bool: True of False
Example:
import rhinoscriptsyntax as rs
title = rs.CurrentView()
result = rs.IsViewPerspective(title)
if result:
print "The " + title + " view is set to perspective projection."
else:
print "The " + title + " view is set to parallel projection."
See Also:
ViewProjection
"""
view = __viewhelper(view)
return view.MainViewport.IsPerspectiveProjection
def IsViewTitleVisible(view=None):
"""Verifies that the specified view's title window is visible
Parameters:
view: (str|guid, optional): The title or identifier of the view. If omitted, the current
active view is used
Returns:
bool: True of False
Example:
import rhinoscriptsyntax as rs
title = rs.CurrentView()
vis = rs.IsViewTitleVisible(title)
if vis:
print "The ", title, " view's title is visible."
else:
print "The ", title, " view's title is not visible."
See Also:
ShowViewTitle
"""
view = __viewhelper(view)
return view.TitleVisible
def IsWallpaper(view):
"""Verifies that the specified view contains a wallpaper image
Parameters:
view (str|guid): view to verify
Returns:
bool: True or False
Example:
import rhinoscriptsyntax as rs
view = rs.CurrentView()
filename = rs.OpenFileName()
if filename and not rs.IsWallpaper(view):
rs.Wallpaper(view, filename)
See Also:
Wallpaper
"""
view = __viewhelper(view)
return len(view.MainViewport.WallpaperFilename)>0
def MaximizeRestoreView(view=None):
"""Toggles a view's maximized/restore window state of the specified view
Parameters:
view: (str|guid, optional): the title or identifier of the view. If omitted, the current
active view is used
Returns:
None
Example:
import rhinoscriptsyntax as rs
title = rs.CurrentView()
if rs.IsViewMaximized(title):
rs.MaximizeRestoreView( title )
See Also:
IsViewMaximized
"""
view = __viewhelper(view)
view.Maximized = not view.Maximized
def NamedCPlane(name):
"""Returns the plane geometry of the specified named construction plane
Parameters:
name (str): the name of the construction plane
Returns:
plane: a plane on success
None: on error
Example:
import rhinoscriptsyntax as rs
names = rs.NamedCPlanes()
if names:
for name in names:
plane = rs.NamedCPlane(name)
print "CPlane name:" + name
print "CPlane origin:" + plane.Origin
print "CPlane x-axis:" + plane.Xaxis
print "CPlane y-axis:" + plane.Yaxis
print "CPlane z-axis:" + plane.Zaxis
See Also:
AddNamedCPlane
DeleteNamedCPlane
NamedCPlanes
RestoreNamedCPlane
"""
index = scriptcontext.doc.NamedConstructionPlanes.Find(name)
if index<0: return scriptcontext.errorhandler()
return scriptcontext.doc.NamedConstructionPlanes[index].Plane
def NamedCPlanes():
"""Returns the names of all named construction planes in the document
Returns:
list(str, ...): the names of all named construction planes in the document
Example:
import rhinoscriptsyntax as rs
cplanes = rs.NamedCPlanes()
if cplanes:
for cplane in cplanes: print cplane
See Also:
AddNamedCPlane
DeleteNamedCPlane
NamedCPlane
RestoreNamedCPlane
"""
count = scriptcontext.doc.NamedConstructionPlanes.Count
rc = [scriptcontext.doc.NamedConstructionPlanes[i].Name for i in range(count)]
return rc
def NamedViews():
"""Returns the names of all named views in the document
Returns:
list(str, ...): the names of all named views in the document
Example:
import rhinoscriptsyntax as rs
views = rs.NamedViews()
if views:
for view in views: print view
See Also:
AddNamedView
DeleteNamedView
RestoreNamedView
"""
count = scriptcontext.doc.NamedViews.Count
return [scriptcontext.doc.NamedViews[i].Name for i in range(count)]
def RenameView(old_title, new_title):
"""Changes the title of the specified view
Parameters:
old_title (str|guid): the title or identifier of the view to rename
new_title (str): the new title of the view
Returns:
str: the view's previous title if successful
None: on error
Example:
import rhinoscriptsyntax as rs
oldtitle = rs.CurrentView()
rs.renameview( oldtitle, "Current" )
See Also:
ViewNames
"""
if not old_title or not new_title: return scriptcontext.errorhandler()
old_id = rhutil.coerceguid(old_title)
foundview = None
allviews = scriptcontext.doc.Views.GetViewList(True, True)
for view in allviews:
if old_id:
if view.MainViewport.Id==old_id:
foundview = view
break
elif view.MainViewport.Name==old_title:
foundview = view
break
if foundview is None: return scriptcontext.errorhandler()
old_title = foundview.MainViewport.Name
foundview.MainViewport.Name = new_title
return old_title
def RestoreNamedCPlane(cplane_name, view=None):
"""Restores a named construction plane to the specified view.
Parameters:
cplane_name (str): name of the construction plane to restore
view: (str|guid, optional): the title or identifier of the view. If omitted, the current
active view is used
Returns:
str: name of the restored named construction plane if successful
None: on error
Example:
import rhinoscriptsyntax as rs
cplanes = rs.NamedCplanes()
if cplanes: rs.RestoreNamedCPlane( cplanes[0] )
See Also:
AddNamedCPlane
DeleteNamedCPlane
NamedCPlane
NamedCPlanes
"""
view = __viewhelper(view)
index = scriptcontext.doc.NamedConstructionPlanes.Find(cplane_name)
if index<0: return scriptcontext.errorhandler()
cplane = scriptcontext.doc.NamedConstructionPlanes[index]
view.MainViewport.PushConstructionPlane(cplane)
view.Redraw()
return cplane_name
def RestoreNamedView(named_view, view=None, restore_bitmap=False):
"""Restores a named view to the specified view
Parameters:
named_view (str): name of the named view to restore
view (str|guid, optional): title or id of the view to restore the named view.
If omitted, the current active view is used
restore_bitmap: (bool, optional): restore the named view's background bitmap
Returns:
str: name of the restored view if successful
None: on error
Example:
import rhinoscriptsyntax as rs
views = rs.NamedViews()
if views: rs.RestoreNamedView(views[0])
See Also:
AddNamedView
DeleteNamedView
NamedViews
"""
view = __viewhelper(view)
index = scriptcontext.doc.NamedViews.FindByName(named_view)
if index<0: return scriptcontext.errorhandler()
viewinfo = scriptcontext.doc.NamedViews[index]
if view.MainViewport.PushViewInfo(viewinfo, restore_bitmap):
view.Redraw()
return view.MainViewport.Name
return scriptcontext.errorhandler()
def RotateCamera(view=None, direction=0, angle=None):
"""Rotates a perspective-projection view's camera. See the RotateCamera
command in the Rhino help file for more details
Parameters:
view (str|guid, optional): title or id of the view. If omitted, current active view is used
direction(number, optional): the direction to rotate the camera where
0=right
1=left
2=down
3=up
angle: (number, optional): the angle to rotate. If omitted, the angle of rotation
is specified by the "Increment in divisions of a circle" parameter
specified in Options command's View tab
Returns:
bool: True or False indicating success or failure
Example:
import rhinoscriptsyntax as rs
rs.RotateCamera( angle=15 )
See Also:
RotateView
TiltView
"""
view = __viewhelper(view)
viewport = view.ActiveViewport
if angle is None:
angle = 2.0*math.pi/Rhino.ApplicationSettings.ViewSettings.RotateCircleIncrement
else:
angle = Rhino.RhinoMath.ToRadians( abs(angle) )
target_distance = (viewport.CameraLocation-viewport.CameraTarget)*viewport.CameraZ
axis = viewport.CameraY
if direction==0 or direction==2: angle=-angle
if direction==0 or direction==1:
if Rhino.ApplicationSettings.ViewSettings.RotateToView:
axis = viewport.CameraY
else:
axis = Rhino.Geometry.Vector3d.ZAxis
elif direction==2 or direction==3:
axis = viewport.CameraX
else:
return False
if Rhino.ApplicationSettings.ViewSettings.RotateReverseKeyboard: angle=-angle
rot = Rhino.Geometry.Transform.Rotation(angle, axis, Rhino.Geometry.Point3d.Origin)
camUp = rot * viewport.CameraY
camDir = -(rot * viewport.CameraZ)
target = viewport.CameraLocation + target_distance*camDir
viewport.SetCameraLocations(target, viewport.CameraLocation)
viewport.CameraUp = camUp
view.Redraw()
return True
def RotateView(view=None, direction=0, angle=None):
"""Rotates a view. See RotateView command in Rhino help for more information
Parameters:
view (str|guid, optional): title or id of the view. If omitted, the current active view is used
direction (number, optional): the direction to rotate the view where
0=right
1=left
2=down
3=up
angle (number): angle to rotate. If omitted, the angle of rotation is specified
by the "Increment in divisions of a circle" parameter specified in
Options command's View tab
Returns:
bool: True or False indicating success or failure
Example:
import rhinoscriptsyntax as rs
rs.RotateView( angle=90.0 )
See Also:
RotateCamera
TiltView
"""
view = __viewhelper(view)
viewport = view.ActiveViewport
if angle is None:
angle = 2.0*math.pi/Rhino.ApplicationSettings.ViewSettings.RotateCircleIncrement
else:
angle = Rhino.RhinoMath.ToRadians( abs(angle) )
if Rhino.ApplicationSettings.ViewSettings.RotateReverseKeyboard: angle = -angle
if direction==0: viewport.KeyboardRotate(True, angle)
elif direction==1: viewport.KeyboardRotate(True, -angle)
elif direction==2: viewport.KeyboardRotate(False, -angle)
elif direction==3: viewport.KeyboardRotate(False, angle)
else: return False
view.Redraw()
return True
def ShowGrid(view=None, show=None):
"""Shows or hides a view's construction plane grid
Parameters:
view (str|guid, optional): title or id of the view. If omitted, the current active view is used
show (bool, optional): The grid state to set. If omitted, the current grid display state is returned
Returns:
bool: If show is not specified, then the grid display state if successful
bool: If show is specified, then the previous grid display state if successful
Example:
import rhinoscriptsyntax as rs
view = rs.CurrentView()
if rs.ShowGrid(view)==False:
rs.ShowGrid( view, True )
See Also:
ShowGridAxes
ShowWorldAxes
"""
view = __viewhelper(view)
viewport = view.ActiveViewport
rc = viewport.ConstructionGridVisible
if show is not None and rc!=show:
viewport.ConstructionGridVisible = show
view.Redraw()
return rc
def ShowGridAxes(view=None, show=None):
"""Shows or hides a view's construction plane grid axes.
Parameters:
view (str|guid, optional): title or id of the view. If omitted, the current active view is used
show (bool, optional): The state to set. If omitted, the current grid axes display state is returned
Returns:
bool: If show is not specified, then the grid axes display state
bool: If show is specified, then the previous grid axes display state
Example:
import rhinoscriptsyntax as rs
view = rs.CurrentView()
if rs.ShowGridAxes(view)==False:
rs.ShowGridAxes( view, True )
See Also:
ShowGrid
ShowWorldAxes
"""
view = __viewhelper(view)
viewport = view.ActiveViewport
rc = viewport.ConstructionAxesVisible
if show is not None and rc!=show:
viewport.ConstructionAxesVisible = show
view.Redraw()
return rc
def ShowViewTitle(view=None, show=True):
"""Shows or hides the title window of a view
Parameters:
view (str|guid, optional): title or id of the view. If omitted, the current active view is used
show (bool, optional): The state to set.
Returns:
None
Example:
import rhinoscriptsyntax as rs
view = rs.CurrentView()
if rs.IsViewTitleVisible(view)==False:
rs.ShowViewTitle( view, True )
See Also:
IsViewTitleVisible
"""
view = __viewhelper(view)
if view is None: return scriptcontext.errorhandler()
view.TitleVisible = show
def ShowWorldAxes(view=None, show=None):
"""Shows or hides a view's world axis icon
Parameters:
view (str|guid, optional): title or id of the view. If omitted, the current active view is used
show: (bool, optional): The state to set.
Returns:
bool: If show is not specified, then the world axes display state
bool: If show is specified, then the previous world axes display state
Example:
import rhinoscriptsyntax as rs
view = rs.CurrentView()
if rs.ShowWorldAxes(view)==False:
rs.ShowWorldAxes( view, True )
See Also:
ShowGrid
ShowGridAxes
"""
view = __viewhelper(view)
viewport = view.ActiveViewport
rc = viewport.WorldAxesVisible
if show is not None and rc!=show:
viewport.WorldAxesVisible = show
view.Redraw()
return rc
def TiltView(view=None, direction=0, angle=None):
"""Tilts a view by rotating the camera up vector. See the TiltView command in
the Rhino help file for more details.
Parameters:
view (str|guid, optional): title or id of the view. If omitted, the current active view is used
direction (number, optional): the direction to rotate the view where
0=right
1=left
angle (number, optional): the angle to rotate. If omitted, the angle of rotation is
specified by the "Increment in divisions of a circle" parameter specified
in Options command's View tab
Returns:
bool: True or False indicating success or failure
Example:
import rhinoscriptsyntax as rs
rs.TiltView( angle=15 )
See Also:
RotateCamera
"""
view = __viewhelper(view)
viewport = view.ActiveViewport
if angle is None:
angle = 2.0*math.pi/Rhino.ApplicationSettings.ViewSettings.RotateCircleIncrement
else:
angle = Rhino.RhinoMath.ToRadians( abs(angle) )
if Rhino.ApplicationSettings.ViewSettings.RotateReverseKeyboard: angle = -angle
axis = viewport.CameraLocation - viewport.CameraTarget
if direction==0: viewport.Rotate(angle, axis, viewport.CameraLocation)
elif direction==1: viewport.Rotate(-angle, axis, viewport.CameraLocation)
else: return False
view.Redraw()
return True
def ViewCamera(view=None, camera_location=None):
"""Returns or sets the camera location of the specified view
Parameters:
view (str|guid, optional): title or id of the view. If omitted, the current active view is used
camera_location (point, optional): a 3D point identifying the new camera location.
If omitted, the current camera location is returned
Returns:
point: If camera_location is not specified, the current camera location
point: If camera_location is specified, the previous camera location
None: on error
Example:
import rhinoscriptsyntax as rs
view = rs.CurrentView()
camera = rs.GetPoint("Select new camera location")
if camera: rs.ViewCamera(view,camera)
See Also:
ViewCameraTarget
ViewTarget
"""
view = __viewhelper(view)
rc = view.ActiveViewport.CameraLocation
if camera_location is None: return rc
camera_location = rhutil.coerce3dpoint(camera_location)
if camera_location is None: return scriptcontext.errorhandler()
view.ActiveViewport.SetCameraLocation(camera_location, True)
view.Redraw()
return rc
def ViewCameraLens(view=None, length=None):
"""Returns or sets the 35mm camera lens length of the specified perspective
projection view.
Parameters:
view (str|guid, optional): title or id of the view. If omitted, the current active view is used
length (number, optional): the new 35mm camera lens length. If omitted, the previous
35mm camera lens length is returned
Returns:
number: If lens length is not specified, the current lens length
number: If lens length is specified, the previous lens length
Example:
import rhinoscriptsyntax as rs
view = rs.CurrentView()
if rs.IsViewPerspective(view):
length = rs.ViewCameraLens(view, 100)
See Also:
ViewCameraTarget
ViewCPlane
ViewDisplayModes
ViewProjection
ViewSize
"""
view = __viewhelper(view)
rc = view.ActiveViewport.Camera35mmLensLength
if not length: return rc
view.ActiveViewport.Camera35mmLensLength = length
view.Redraw()
return rc
def ViewCameraPlane(view=None):
"""Returns the orientation of a view's camera.
Parameters:
view (str|guid, optional): title or id of the view. If omitted, the current active view is used
Returns:
plane: the view's camera plane if successful
None: on error
Example:
import rhinocsriptsyntax as rs
view = rs.CurrentView()
target = rs.ViewTarget(view)
camplane = rs.ViewCameraPlane(view)
plane = rs.MovePlane(camplane, target)
rs.ViewCPlane( view, plane )
See Also:
ViewCamera
ViewTarget
"""
view = __viewhelper(view)
rc, frame = view.ActiveViewport.GetCameraFrame()