-
Notifications
You must be signed in to change notification settings - Fork 73
Expand file tree
/
Copy pathobject.py
More file actions
executable file
·1920 lines (1790 loc) · 68.2 KB
/
object.py
File metadata and controls
executable file
·1920 lines (1790 loc) · 68.2 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 Rhino
import utility as rhutil
import System.Guid, System.Enum
from layer import __getlayer
from view import __viewhelper
import math
def CopyObject(object_id, translation=None):
"""Copies object from one location to another, or in-place.
Parameters:
object_id (guid): object to copy
translation (vector, optional): translation vector to apply
Returns:
guid: id for the copy if successful
None: if not able to copy
Example:
import rhinoscriptsyntax as rs
id = rs.GetObject("Select object to copy")
if id:
start = rs.GetPoint("Point to copy from")
if start:
end = rs.GetPoint("Point to copy to", start)
if end:
translation = end-start
rs.CopyObject( id, translation )
See Also:
CopyObjects
"""
rc = CopyObjects(object_id, translation)
if rc: return rc[0]
def CopyObjects(object_ids, translation=None):
"""Copies one or more objects from one location to another, or in-place.
Parameters:
object_ids ([guid, ...])list of objects to copy
translation (vector, optional): list of three numbers or Vector3d representing
translation vector to apply to copied set
Returns:
list(guid, ...): identifiers for the copies if successful
Example:
import rhinoscriptsyntax as rs
objectIds = rs.GetObjects("Select objects to copy")
if objectIds:
start = rs.GetPoint("Point to copy from")
if start:
end = rs.GetPoint("Point to copy to", start)
if end:
translation = end-start
rs.CopyObjects( objectIds, translation )
See Also:
CopyObject
"""
if translation:
translation = rhutil.coerce3dvector(translation, True)
translation = Rhino.Geometry.Transform.Translation(translation)
else:
translation = Rhino.Geometry.Transform.Identity
return TransformObjects(object_ids, translation, True)
def DeleteObject(object_id):
"""Deletes a single object from the document
Parameters:
object_id (guid): identifier of object to delete
Returns:
bool: True of False indicating success or failure
Example:
import rhinoscriptsyntax as rs
id = rs.GetObject("Select object to delete")
if id: rs.DeleteObject(id)
See Also:
DeleteObjects
"""
object_id = rhutil.coerceguid(object_id, True)
rc = scriptcontext.doc.Objects.Delete(object_id, True)
if rc: scriptcontext.doc.Views.Redraw()
return rc
def DeleteObjects(object_ids):
"""Deletes one or more objects from the document
Parameters:
object_ids ([guid, ...]): identifiers of objects to delete
Returns:
number: Number of objects deleted
Example:
import rhinoscriptsyntax as rs
object_ids = rs.GetObjects("Select objects to delete")
if object_ids: rs.DeleteObjects(object_ids)
See Also:
DeleteObject
"""
rc = 0
id = rhutil.coerceguid(object_ids, False)
if id: object_ids = [id]
for id in object_ids:
id = rhutil.coerceguid(id, True)
if scriptcontext.doc.Objects.Delete(id, True): rc+=1
if rc: scriptcontext.doc.Views.Redraw()
return rc
def FlashObject(object_ids, style=True):
"""Causes the selection state of one or more objects to change momentarily
so the object appears to flash on the screen
Parameters:
object_ids ([guid, ...]) identifiers of objects to flash
style (bool, optional): If True, flash between object color and selection color.
If False, flash between visible and invisible
Returns:
None
Example:
import rhinoscriptsyntax as rs
objs = rs.ObjectsByLayer("Default")
if objs: rs.FlashObject(objs)
See Also:
HideObjects
SelectObjects
ShowObjects
UnselectObjects
"""
id = rhutil.coerceguid(object_ids, False)
if id: object_ids = [id]
rhobjs = [rhutil.coercerhinoobject(id, True, True) for id in object_ids]
if rhobjs: scriptcontext.doc.Views.FlashObjects(rhobjs, style)
def HideObject(object_id):
"""Hides a single object
Parameters:
object_id (guid): id of object to hide
Returns:
bool: True of False indicating success or failure
Example:
import rhinoscriptsyntax as rs
id = rs.GetObject("Select object to hide")
if id: rs.HideObject(id)
See Also:
HideObjects
IsObjectHidden
ShowObject
ShowObjects
"""
return HideObjects(object_id)==1
def HideObjects(object_ids):
"""Hides one or more objects
Parameters:
object_ids ([guid, ...]): identifiers of objects to hide
Returns:
number: Number of objects hidden
Example:
import rhinoscriptsyntax as rs
ids = rs.GetObjects("Select objects to hide")
if ids: rs.HideObjects(ids)
See Also:
HideObjects
IsObjectHidden
ShowObject
ShowObjects
"""
id = rhutil.coerceguid(object_ids, False)
if id: object_ids = [id]
rc = 0
for id in object_ids:
id = rhutil.coerceguid(id, True)
if scriptcontext.doc.Objects.Hide(id, False): rc += 1
if rc: scriptcontext.doc.Views.Redraw()
return rc
def IsLayoutObject(object_id):
"""Verifies that an object is in either page layout space or model space
Parameters:
object_id (guid): id of an object to test
Returns:
bool: True if the object is in page layout space
bool: False if the object is in model space
Example:
import rhinoscriptsyntax as rs
id = rs.GetObject("Select object")
if id:
if rs.IsLayoutObject(id):
print "The object is in page layout space."
else:
print "The object is in model space."
See Also:
IsObject
IsObjectReference
"""
rhobj = rhutil.coercerhinoobject(object_id, True, True)
return rhobj.Attributes.Space == Rhino.DocObjects.ActiveSpace.PageSpace
def IsObject(object_id):
"""Verifies the existence of an object
Parameters:
object_id (guid): an object to test
Returns:
bool: True if the object exists
bool: False if the object does not exist
Example:
import rhinoscriptsyntax as rs
#Do something here...
if rs.IsObject(id):
print "The object exists."
else:
print "The object does not exist."
See Also:
IsObjectHidden
IsObjectInGroup
IsObjectLocked
IsObjectNormal
IsObjectReference
IsObjectSelectable
IsObjectSelected
IsObjectSolid
"""
return rhutil.coercerhinoobject(object_id, True, False) is not None
def IsObjectHidden(object_id):
"""Verifies that an object is hidden. Hidden objects are not visible, cannot
be snapped to, and cannot be selected
Parameters:
object_id (guid): The identifier of an object to test
Returns:
bool: True if the object is hidden
bool: False if the object is not hidden
Example:
import rhinoscriptsyntax as rs
# Do something here...
if rs.IsObjectHidden(id):
print "The object is hidden."
else:
print "The object is not hidden."
See Also:
IsObject
IsObjectInGroup
IsObjectLocked
IsObjectNormal
IsObjectReference
IsObjectSelectable
IsObjectSelected
IsObjectSolid
"""
rhobj = rhutil.coercerhinoobject(object_id, True, True)
return rhobj.IsHidden
def IsObjectInBox(object_id, box, test_mode=True):
"""Verifies an object's bounding box is inside of another bounding box
Parameters:
object_id (guid): identifier of an object to be tested
box ([point, point, point, point, point, point, point, point]): bounding box to test for containment
test_mode (bool, optional): If True, the object's bounding box must be contained by box
If False, the object's bounding box must be contained by or intersect box
Returns:
bool: True if object is inside box
bool: False is object is not inside box
Example:
import rhinoscriptsyntax as rs
box = rs.GetBox()
if box:
rs.EnableRedraw(False)
object_list = rs.AllObjects()
for obj in object_list:
if rs.IsObjectInBox(obj, box, False):
rs.SelectObject( obj )
rs.EnableRedraw( True )
See Also:
BoundingBox
GetBox
"""
rhobj = rhutil.coercerhinoobject(object_id, True, True)
box = rhutil.coerceboundingbox(box, True)
objbox = rhobj.Geometry.GetBoundingBox(True)
if test_mode: return box.Contains(objbox)
union = Rhino.Geometry.BoundingBox.Intersection(box, objbox)
return union.IsValid
def IsObjectInGroup(object_id, group_name=None):
"""Verifies that an object is a member of a group
Parameters:
object_id (guid): The identifier of an object
group_name (str, optional): The name of a group. If omitted, the function
verifies that the object is a member of any group
Returns:
bool: True if the object is a member of the specified group. If a group_name
was not specified, the object is a member of some group.
bool: False if the object is not a member of the specified group. If a
group_name was not specified, the object is not a member of any group
Example:
import rhinoscriptsyntax as rs
id = rs.GetObject("Select object")
if id:
name = rs.GetString("Group name")
if name:
result = rs.IsObjectInGroup(id, name)
if result:
print "The object belongs to the group."
else:
print "The object does not belong to the group."
See Also:
IsObject
IsObjectHidden
IsObjectLocked
IsObjectNormal
IsObjectReference
IsObjectSelectable
IsObjectSelected
IsObjectSolid
"""
rhobj = rhutil.coercerhinoobject(object_id, True, True)
count = rhobj.GroupCount
if count<1: return False
if not group_name: return True
index = scriptcontext.doc.Groups.Find(group_name)
if index<0: raise ValueError("%s group does not exist"%group_name)
group_ids = rhobj.GetGroupList()
for id in group_ids:
if id==index: return True
return False
def IsObjectLocked(object_id):
"""Verifies that an object is locked. Locked objects are visible, and can
be snapped to, but cannot be selected
Parameters:
object_id (guid): The identifier of an object to be tested
Returns:
bool: True if the object is locked
bool: False if the object is not locked
Example:
import rhinoscriptsyntax as rs
# Do something here...
if rs.IsObjectLocked(object):
print "The object is locked."
else:
print "The object is not locked."
See Also:
IsObject
IsObjectHidden
IsObjectInGroup
IsObjectNormal
IsObjectReference
IsObjectSelectable
IsObjectSelected
IsObjectSolid
"""
rhobj = rhutil.coercerhinoobject(object_id, True, True)
return rhobj.IsLocked
def IsObjectNormal(object_id):
"""Verifies that an object is normal. Normal objects are visible, can be
snapped to, and can be selected
Parameters:
object_id (guid): The identifier of an object to be tested
Returns:
bool: True if the object is normal
bool: False if the object is not normal
Example:
import rhinoscriptsyntax as rs
#Do something here...
if rs.IsObjectNormal(object):
print "The object is normal."
else:
print "The object is not normal."
See Also:
IsObject
IsObjectHidden
IsObjectInGroup
IsObjectLocked
IsObjectReference
IsObjectSelectable
IsObjectSelected
IsObjectSolid
"""
rhobj = rhutil.coercerhinoobject(object_id, True, True)
return rhobj.IsNormal
def IsObjectReference(object_id):
"""Verifies that an object is a reference object. Reference objects are
objects that are not part of the current document
Parameters:
object_id (guid): The identifier of an object to test
Returns:
bool: True if the object is a reference object
bool: False if the object is not a reference object
Example:
import rhinoscriptsyntax as rs
id = rs.GetObject("Select object")
if rs.IsObjectReference(id):
print "The object is a reference object."
else:
print "The object is not a reference object."
See Also:
IsObject
IsObjectHidden
IsObjectInGroup
IsObjectLocked
IsObjectNormal
IsObjectSelectable
IsObjectSelected
IsObjectSolid
"""
rhobj = rhutil.coercerhinoobject(object_id, True, True)
return rhobj.IsReference
def IsObjectSelectable(object_id):
"""Verifies that an object can be selected
Parameters:
object_id (guid): The identifier of an object to test
Returns:
bool: True or False
Example:
import rhinoscriptsyntax as rs
# Do something here...
if rs.IsObjectSelectable(object):
rs.SelectObject( object )
See Also:
IsObject
IsObjectHidden
IsObjectInGroup
IsObjectLocked
IsObjectNormal
IsObjectReference
IsObjectSelected
IsObjectSolid
"""
rhobj = rhutil.coercerhinoobject(object_id, True, True)
return rhobj.IsSelectable(True,False,False,False)
def IsObjectSelected(object_id):
"""Verifies that an object is currently selected.
Parameters:
object_id (guid): The identifier of an object to test
Returns:
int: 0, the object is not selected
int: 1, the object is selected
int: 2, the object is entirely persistently selected
int: 3, one or more proper sub-objects are selected
Example:
import rhinoscriptsyntax as rs
object = rs.GetObject()
if rs.IsObjectSelected(object):
print "The object is selected."
else:
print "The object is not selected."
See Also:
IsObject
IsObjectHidden
IsObjectInGroup
IsObjectLocked
IsObjectNormal
IsObjectReference
IsObjectSelectable
IsObjectSolid
"""
rhobj = rhutil.coercerhinoobject(object_id, True, True)
return rhobj.IsSelected(False)
def IsObjectSolid(object_id):
"""Determines if an object is closed, solid
Parameters:
object_id (guid): The identifier of an object to test
Returns:
bool: True if the object is solid, or a mesh is closed.
bool: False otherwise.
Example:
import rhinoscriptsyntax as rs
id = rs.GetObject("Select object")
if rs.IsObjectSolid(id):
print "The object is solid."
else:
print "The object is not solid."
See Also:
IsObject
IsObjectHidden
IsObjectInGroup
IsObjectLocked
IsObjectNormal
IsObjectReference
IsObjectSelectable
IsObjectSelected
"""
rhobj = rhutil.coercerhinoobject(object_id, True, True)
geom = rhobj.Geometry
geometry_type = geom.ObjectType
if geometry_type == Rhino.DocObjects.ObjectType.Mesh:
return geom.IsClosed
if (geometry_type == Rhino.DocObjects.ObjectType.Surface or
geometry_type == Rhino.DocObjects.ObjectType.Brep or
geometry_type == Rhino.DocObjects.ObjectType.Extrusion):
return geom.IsSolid
return False
def IsObjectValid(object_id):
"""Verifies an object's geometry is valid and without error
Parameters:
object_id (guid): The identifier of an object to test
Returns:
bool: True if the object is valid
Example:
import rhinoscriptsyntax as rs
id = rs.GetObject("Select object")
if rs.IsObjectValid(id):
print "The object is valid."
else:
print "The object is not valid."
See Also:
IsObject
"""
rhobj = rhutil.coercerhinoobject(object_id, True, True)
return rhobj.IsValid
def IsVisibleInView(object_id, view=None):
"""Verifies an object is visible in a view
Parameters:
object_id (guid): the identifier of an object to test
view (str, optional): he title of the view. If omitted, the current active view is used.
Returns:
bool: True if the object is visible in the specified view, otherwise False. None on error
Example:
import rhinoscriptsyntax as rs
obj = rs.GetObject("Select object")
if rs.IsObject(obj):
view = rs.CurrentView()
if rs.IsVisibleInView(obj, view):
print "The object is visible in", view, "."
else:
print "The object is not visible in", view, "."
See Also:
IsObject
IsView
"""
rhobj = rhutil.coercerhinoobject(object_id, True, True)
viewport = __viewhelper(view).MainViewport
bbox = rhobj.Geometry.GetBoundingBox(True)
return rhobj.Visible and viewport.IsVisible(bbox)
def LockObject(object_id):
"""Locks a single object. Locked objects are visible, and they can be
snapped to. But, they cannot be selected.
Parameters:
object_id (guid): The identifier of an object
Returns:
bool: True or False indicating success or failure
Example:
import rhinoscriptsyntax as rs
id = rs.GetObject("Select object to lock")
if id: rs.LockObject(id)
See Also:
IsObjectLocked
LockObjects
UnlockObject
UnlockObjects
"""
return LockObjects(object_id)==1
def LockObjects(object_ids):
"""Locks one or more objects. Locked objects are visible, and they can be
snapped to. But, they cannot be selected.
Parameters:
object_ids ([guid, ...]): list of Strings or Guids. The identifiers of objects
Returns:
number: number of objects locked
Example:
import rhinoscriptsyntax as rs
ids = rs.GetObjects("Select objects to lock")
if ids: rs.LockObjects(ids)
See Also:
IsObjectLocked
LockObject
UnlockObject
UnlockObjects
"""
id = rhutil.coerceguid(object_ids, False)
if id: object_ids = [id]
rc = 0
for id in object_ids:
id = rhutil.coerceguid(id, True)
if scriptcontext.doc.Objects.Lock(id, False): rc += 1
if rc: scriptcontext.doc.Views.Redraw()
return rc
def MatchObjectAttributes(target_ids, source_id=None):
"""Matches, or copies the attributes of a source object to a target object
Parameters:
target_ids ([guid, ...]): identifiers of objects to copy attributes to
source_id (guid, optional): identifier of object to copy attributes from. If None,
then the default attributes are copied to the target_ids
Returns:
number: number of objects modified
Example:
import rhinoscriptsyntax as rs
targets = rs.GetObjects("Select objects")
if targets:
source = rs.GetObject("Select object to match")
if source: rs.MatchObjectAttributes( targets, source )
See Also:
GetObject
GetObjects
"""
id = rhutil.coerceguid(target_ids, False)
if id: target_ids = [id]
source_attr = Rhino.DocObjects.ObjectAttributes()
if source_id:
source = rhutil.coercerhinoobject(source_id, True, True)
source_attr = source.Attributes.Duplicate()
rc = 0
for id in target_ids:
id = rhutil.coerceguid(id, True)
if scriptcontext.doc.Objects.ModifyAttributes(id, source_attr, True):
rc += 1
if rc: scriptcontext.doc.Views.Redraw()
return rc
def MirrorObject(object_id, start_point, end_point, copy=False):
"""Mirrors a single object
Parameters:
object_id (guid): The identifier of an object to mirror
start_point (point): start of the mirror plane
end_point (point): end of the mirror plane
copy (bool, optional): copy the object
Returns:
guid: Identifier of the mirrored object if successful
None: on error
Example:
import rhinoscriptsyntax as rs
obj = rs.GetObject("Select object to mirror")
if obj:
start = rs.GetPoint("Start of mirror plane")
end = rs.GetPoint("End of mirror plane")
if start and end:
rs.MirrorObject( obj, start, end, True )
See Also:
MirrorObjects
"""
rc = MirrorObjects(object_id, start_point, end_point, copy)
if rc: return rc[0]
def MirrorObjects(object_ids, start_point, end_point, copy=False):
"""Mirrors a list of objects
Parameters:
object_ids ([guid, ...]): identifiers of objects to mirror
start_point (point): start of the mirror plane
end_point (point): end of the mirror plane
copy (bool, optional): copy the objects
Returns:
list(guid, ...): List of identifiers of the mirrored objects if successful
Example:
import rhinoscriptsyntax as rs
objs = rs.GetObjects("Select objects to mirror")
if objs:
start = rs.GetPoint("Start of mirror plane")
end = rs.GetPoint("End of mirror plane")
if start and end:
rs.MirrorObjects( objs, start, end, True )
See Also:
MirrorObject
"""
start_point = rhutil.coerce3dpoint(start_point, True)
end_point = rhutil.coerce3dpoint(end_point, True)
vec = end_point-start_point
if vec.IsTiny(0): raise Exception("start and end points are too close to each other")
normal = scriptcontext.doc.Views.ActiveView.ActiveViewport.ConstructionPlane().Normal
vec = Rhino.Geometry.Vector3d.CrossProduct(vec, normal)
vec.Unitize()
xf = Rhino.Geometry.Transform.Mirror(start_point, vec)
rc = TransformObjects(object_ids, xf, copy)
return rc
def MoveObject(object_id, translation):
"""Moves a single object
Parameters:
object_id (guid): The identifier of an object to move
translation (vector): list of 3 numbers or Vector3d
Returns:
guid: Identifier of the moved object if successful
None: on error
Example:
import rhinoscriptsyntax as rs
id = rs.GetObject("Select object to move")
if id:
start = rs.GetPoint("Point to move from")
if start:
end = rs.GetPoint("Point to move to")
if end:
translation = end-start
rs.MoveObject(id, translation)
See Also:
MoveObjects
"""
rc = MoveObjects(object_id, translation)
if rc: return rc[0]
def MoveObjects(object_ids, translation):
"""Moves one or more objects
Parameters:
object_ids ([guid, ...]): The identifiers objects to move
translation (vector): list of 3 numbers or Vector3d
Returns:
list(guid, ...): identifiers of the moved objects if successful
Example:
import rhinoscriptsyntax as rs
ids = rs.GetObjects("Select objects to move")
if ids:
start = rs.GetPoint("Point to move from")
if start:
end = rs.GetPoint("Point to move to")
if end:
translation = end-start
rs.MoveObjects( ids, translation )
See Also:
MoveObject
"""
translation = rhutil.coerce3dvector(translation, True)
xf = Rhino.Geometry.Transform.Translation(translation)
rc = TransformObjects(object_ids, xf)
return rc
def ObjectColor(object_ids, color=None):
"""Returns of modifies the color of an object. Object colors are represented
as RGB colors. An RGB color specifies the relative intensity of red, green,
and blue to cause a specific color to be displayed
Parameters:
object_ids ([guid, ...]): id or ids of object(s)
color (color, optional): the new color value. If omitted, then current object
color is returned. If object_ids is a list, color is required
Returns:
color: If color value is not specified, the current color value
color: If color value is specified, the previous color value
number: If object_ids is a list, then the number of objects modified
Example:
import rhinoscriptsyntax as rs
objs = rs.GetObjects("Select objects to change color")
if objs:
color = rs.GetColor(0)
if color:
for obj in objs: rs.ObjectColor( obj, color )
See Also:
ObjectColorSource
ObjectsByColor
"""
id = rhutil.coerceguid(object_ids, False)
rhino_object = None
rhino_objects = None
if id:
rhino_object = rhutil.coercerhinoobject(id, True, True)
else:
rhino_objects = [rhutil.coercerhinoobject(id, True, True) for id in object_ids]
if len(rhino_objects)==1:
rhino_object = rhino_objects[0]
rhino_objects = None
if color is None:
#get the color
if rhino_objects: raise ValueError("color must be specified when a list of rhino objects is provided")
return rhino_object.Attributes.DrawColor(scriptcontext.doc)
color = rhutil.coercecolor(color, True)
if rhino_objects is not None:
for rh_obj in rhino_objects:
attr = rh_obj.Attributes
attr.ObjectColor = color
attr.ColorSource = Rhino.DocObjects.ObjectColorSource.ColorFromObject
scriptcontext.doc.Objects.ModifyAttributes( rh_obj, attr, True)
scriptcontext.doc.Views.Redraw()
return len(rhino_objects)
rc = rhino_object.Attributes.DrawColor(scriptcontext.doc)
attr = rhino_object.Attributes
attr.ObjectColor = color
attr.ColorSource = Rhino.DocObjects.ObjectColorSource.ColorFromObject
scriptcontext.doc.Objects.ModifyAttributes( rhino_object, attr, True )
scriptcontext.doc.Views.Redraw()
return rc
def ObjectColorSource(object_ids, source=None):
"""Returns of modifies the color source of an object.
Parameters:
object_ids ([guid, ...]): single identifier of list of identifiers
source (number, optional) = new color source
0 = color from layer
1 = color from object
2 = color from material
3 = color from parent
Returns:
if color source is not specified, the current color source
is color source is specified, the previous color source
if color_ids is a list, then the number of objects modifief
Example:
import rhinoscriptsyntax as rs
objs = rs.GetObjects("Select objects to reset color source")
if objs:
for obj In objs: rs.ObjectColorSource(obj, 0)
See Also:
ObjectColor
"""
id = rhutil.coerceguid(object_ids, False)
if id:
rhobj = rhutil.coercerhinoobject(id, True, True)
rc = int(rhobj.Attributes.ColorSource)
if source is not None:
rhobj.Attributes.ColorSource = System.Enum.ToObject(Rhino.DocObjects.ObjectColorSource, source)
rhobj.CommitChanges()
scriptcontext.doc.Views.Redraw()
return rc
else:
rc = 0
source = System.Enum.ToObject(Rhino.DocObjects.ObjectColorSource, source)
for id in object_ids:
rhobj = rhutil.coercerhinoobject(id, True, True)
rhobj.Attributes.ColorSource = source
rhobj.CommitChanges()
rc += 1
if rc: scriptcontext.doc.Views.Redraw()
return rc
def ObjectDescription(object_id):
"""Returns a short text description of an object
Parameters:
object_id = identifier of an object
Returns:
A short text description of the object if successful.
Example:
import rhinoscriptsyntax as rs
obj = rs.GetObject("Select object")
if obj:
description = rs.ObjectDescription(obj)
print "Object description:" , description
See Also:
ObjectType
"""
rhobj = rhutil.coercerhinoobject(object_id, True, True)
return rhobj.ShortDescription(False)
def ObjectGroups(object_id):
"""Returns all of the group names that an object is assigned to
Parameters:
object_id ([guid, ...]): identifier of an object(s)
Returns:
list(str, ...): list of group names on success
Example:
import rhinoscriptsyntax as rs
obj = rs.GetObject("Select object")
if obj:
groups = rs.ObjectGroups(obj)
if groups:
for group in groups: print "Object group: ", group
else:
print "No groups."
See Also:
ObjectsByGroup
"""
rhino_object = rhutil.coercerhinoobject(object_id, True, True)
if rhino_object.GroupCount<1: return []
group_indices = rhino_object.GetGroupList()
rc = [scriptcontext.doc.Groups.GroupName(index) for index in group_indices]
return rc
def ObjectLayer(object_id, layer=None):
"""Returns or modifies the layer of an object
Parameters:
object_id ([guid, ...]) the identifier of the object(s)
layer (str, optional): name of an existing layer
Returns:
str: If a layer is not specified, the object's current layer
str: If a layer is specified, the object's previous layer
number: If object_id is a list or tuple, the number of objects modified
Example:
import rhinoscriptsyntax as rs
id = rs.GetObject("Select object")
if id: rs.ObjectLayer(id, "Default")
See Also:
ObjectsByLayer
"""
if type(object_id) is not str and hasattr(object_id, "__len__"):
layer = __getlayer(layer, True)
index = layer.LayerIndex
for id in object_id:
obj = rhutil.coercerhinoobject(id, True, True)
obj.Attributes.LayerIndex = index
obj.CommitChanges()
scriptcontext.doc.Views.Redraw()
return len(object_id)
obj = rhutil.coercerhinoobject(object_id, True, True)
if obj is None: return scriptcontext.errorhandler()
index = obj.Attributes.LayerIndex
rc = scriptcontext.doc.Layers[index].FullPath
if layer:
layer = __getlayer(layer, True)
index = layer.LayerIndex
obj.Attributes.LayerIndex = index
obj.CommitChanges()
scriptcontext.doc.Views.Redraw()
return rc
def ObjectLayout(object_id, layout="", return_name=True):
"""Returns or changes the layout or model space of an object
Parameters:
object_id (guid): identifier of the object
layout (str|guid, optional): to change, or move, an object from model space to page
layout space, or from one page layout to another, then specify the
title or identifier of an existing page layout view. To move an object
from page layout space to model space, just specify None
return_name[opt] = If True, the name, or title, of the page layout view
is returned. If False, the identifier of the page layout view is returned
Returns:
str: if layout is not specified, the object's current page layout view
str: if layout is specified, the object's previous page layout view
None: if not successful
Example:
import rhinoscriptsyntax as rs
obj = rs.GetObject("Select object")
if obj: rs.ObjectLayout(obj, "Page 1")
See Also:
IsLayoutObject
IsLayout
ViewNames
"""
rhobj = rhutil.coercerhinoobject(object_id, True, True)
rc = None
if rhobj.Attributes.Space==Rhino.DocObjects.ActiveSpace.PageSpace:
page_id = rhobj.Attributes.ViewportId
pageview = scriptcontext.doc.Views.Find(page_id)
if return_name: rc = pageview.MainViewport.Name
else: rc = pageview.MainViewport.Id
if layout is None: #move to model space
rhobj.Attributes.Space = Rhino.DocObjects.ActiveSpace.ModelSpace
rhobj.Attributes.ViewportId = System.Guid.Empty
rhobj.CommitChanges()
scriptcontext.doc.Views.Redraw()
else:
if layout:
layout = scriptcontext.doc.Views.Find(layout, False)
if layout is not None and isinstance(layout, Rhino.Display.RhinoPageView):
rhobj.Attributes.ViewportId = layout.MainViewport.Id
rhobj.Attributes.Space = Rhino.DocObjects.ActiveSpace.PageSpace
rhobj.CommitChanges()
scriptcontext.doc.Views.Redraw()
return rc
def ObjectLinetype(object_ids, linetype=None):
"""Returns of modifies the linetype of an object
Parameters:
object_ids ({guid, ...]): identifiers of object(s)
linetype (str, optional): name of an existing linetype. If omitted, the current
linetype is returned. If object_ids is a list of identifiers, this parameter
is required
Returns:
str: If a linetype is not specified, the object's current linetype
str: If linetype is specified, the object's previous linetype
number: If object_ids is a list, the number of objects modified
Example:
import rhinoscriptsyntax as rs
obj = rs.GetObject("Select object")
if obj: rs.ObjectLinetype(obj, "Continuous")
See Also:
ObjectLinetypeSource
"""
id = rhutil.coerceguid(object_ids, False)
if id:
rhino_object = rhutil.coercerhinoobject(id, True, True)
oldindex = scriptcontext.doc.Linetypes.LinetypeIndexForObject(rhino_object)
if linetype:
newindex = scriptcontext.doc.Linetypes.Find(linetype)
rhino_object.Attributes.LinetypeSource = Rhino.DocObjects.ObjectLinetypeSource.LinetypeFromObject
rhino_object.Attributes.LinetypeIndex = newindex
rhino_object.CommitChanges()
scriptcontext.doc.Views.Redraw()
return scriptcontext.doc.Linetypes[oldindex].Name
newindex = scriptcontext.doc.Linetypes.Find(linetype)
if newindex<0: raise Exception("%s does not exist in LineTypes table"%linetype)