Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
baleti committed Dec 15, 2024
0 parents commit 712d9ce
Show file tree
Hide file tree
Showing 178 changed files with 4,626 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import Rhino.PlugIns as rp
import rhinoscriptsyntax as rs

pl_cmd = dict()
query_string = rs.GetString(message="name of the command")

for plkv in rp.PlugIn.GetInstalledPlugIns():
guid = plkv.Key
name = plkv.Value
pl_info = rp.PlugIn.GetPlugInInfo(guid)
pl_cmd[name] = [cmd for cmd in pl_info.CommandNames]

for pl in pl_cmd:
for pl_com
if query_string in pl:
print pl
print "\t" + str(pl_cmd[pl])
52 changes: 52 additions & 0 deletions $$/DupLayersSublayersAndObjs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
"""Duplicates a layer and all its sublayers incuding objects
Script by Mitch Heynick 20 April 2014"""

import rhinoscriptsyntax as rs
import scriptcontext as sc

def CopyObjectsToLayer(objs,layer):
copies=rs.CopyObjects(objs)
rs.ObjectLayer(copies,layer)

def UniqueLayerCopyName(layer,top):
#Extract main level name; add - Copy to top level layer name only
layers=rs.LayerNames()
nameList=layer.split("::")
newName=nameList[-1]
if top: newName+=" - Copy"
if newName in layers:
i=0
while True:
i+=1
testName=newName+"({})".format(i)
if not testName in layers: return testName
return newName

def DupAllSubLayers(layer,layerCopy):
subs=rs.LayerChildren(layer)
if subs:
for sub in subs:
color=rs.LayerColor(sub)
objs=rs.ObjectsByLayer(sub)
name=UniqueLayerCopyName(sub,False)
addLayer=rs.AddLayer(name,color,parent=layerCopy)
CopyObjectsToLayer(objs,addLayer)
rs.ExpandLayer(addLayer,rs.IsLayerExpanded(sub))
DupAllSubLayers(sub,addLayer)

def DupLayersSublayersAndObjs():
layer=rs.GetLayer()
if layer==None: return
#do initial run with selected layer
color=rs.LayerColor(layer)
objs=rs.ObjectsByLayer(layer)
parentLayer=rs.ParentLayer(layer)


copyName=UniqueLayerCopyName(layer,True)
layerCopy=rs.AddLayer(copyName,color,parent=parentLayer)
CopyObjectsToLayer(objs,layerCopy)
rs.ExpandLayer(layerCopy,rs.IsLayerExpanded(layer))
DupAllSubLayers(layer,layerCopy)

DupLayersSublayersAndObjs()
14 changes: 14 additions & 0 deletions $$/FlipCamera-NOT-WORKING-DUE-TO-VIEWPORTS-STRETCHING-FRUSTUMS.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@

import scriptcontext as sc

vp = sc.doc.Views.ActiveView.ActiveViewport
p1 = vp.CameraLocation
p2 = vp.CameraTarget
vecDir = p2-p1
p1 = p1 + (vecDir*2)
vecDir.Reverse()

vp.SetCameraLocations(p2, p1)
sc.doc.Views.Redraw()


8 changes: 8 additions & 0 deletions $$/PrintAllAsSeparatePagesMultiprocess-SUPERSEDED.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import os
import subprocess
import rhinoscriptsyntax as rs

with open(os.environ['TEMP'] + "\\printing-madness" + ".cmd", "w") as madness:
madness.write('start /min "" "C:\\Program Files\\Rhino 8 WIP\\System\\Rhino.exe" /nosplash /runscript="-RunPythonScript (G:\\0000 CAD LIBRARY\\Scripts\\rhino\\_PrintAllAsSeparatePages.py) -Exit No" ' + chr(34) + rs.DocumentPath() + "\\" + rs.DocumentName() + chr(34))
madness.flush()
subprocess.Popen(madness.name, shell=True)
31 changes: 31 additions & 0 deletions $$/RemapCplaneCopyGUI.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import rhinoscriptsyntax as rs
import scriptcontext as sc

#doesn't work when this section turned on - try using transforms instead:

#selected_obj = rs.coercerhinoobject(rs.GetObject(preselect=True))
#if str(selected_obj.ObjectType) == "InstanceReference":
# selected_obj_name = selected_obj.InstanceDefinition.Name
#else:
# selected_obj_name = ""

named_cplanes = [i.Name for i in list(sc.doc.NamedConstructionPlanes.GetEnumerator())]
selected_cplane_from = rs.ComboListBox(sorted(named_cplanes), "Cplane to Map from")
selected_cplane_to = rs.ComboListBox(sorted(named_cplanes), "Cplane to Map to")


#doesn't work when this section turned on - try using transforms instead:
#message_from = "Name: " + selected_obj_name + "\n" + "Cplane to Map from"
#message_to = "Name: " + selected_obj_name + "\n" + "Cplane to Map to"

#selected_cplane_from = rs.ComboListBox(sorted(named_cplanes), message=message_from)
#selected_cplane_to = rs.ComboListBox(sorted(named_cplanes), message=message_to)


current_cplane = rs.ViewCPlane()
rs.RestoreNamedCPlane(selected_cplane_from)

rs.Command("RemapCplane Copy=Yes Cplane " + chr(34) + selected_cplane_to + chr(34))

#restore previous Cplane
rs.ViewCPlane(plane=current_cplane)
9 changes: 9 additions & 0 deletions $$/RemapCplaneGUI-WIP.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import rhinoscriptsyntax as rs
import scriptcontext as sc

named_cplanes = [i.Name for i in list(sc.doc.NamedConstructionPlanes.GetEnumerator())]
selected_cplane_to = rs.ComboListBox(named_cplanes, "Cplane to Map to")
selected_cplane_from = rs.ComboListBox(named_cplanes, "Cplane to Map from")

rs.ViewCPlane(plane=selected_cplane_to)
rs.Command("RemapCplane Cplane " + selected_cplane)
15 changes: 15 additions & 0 deletions $$/RemapCplaneGUI.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# needs a FROM Cplane - could use NamedCplaneGUI.py

import rhinoscriptsyntax as rs
import scriptcontext as sc

#world_top_cplane = rs.PlaneFromPoints("0,0,0", "1,0,0", "0,1,0")

named_cplanes = [i.Name for i in list(sc.doc.NamedConstructionPlanes.GetEnumerator())]
selected_cplane_to = rs.ComboListBox(sorted(named_cplanes), "Cplane to Map to")

#rs.coerceplane()

#rs.ViewCPlane(plane=world_top_cplane)
rs.Command("RemapCplane Cplane " + chr(34) + selected_cplane_to + chr(34))
#rs.Command("Cplane Undo Enter")
5 changes: 5 additions & 0 deletions $$/ReopenThisFileWithoutSaving-WIP.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# can't get it to work when file isn't saved, below commands return None
import rhinoscriptsyntax as rs

document_location = rs.DocumentPath() + rs.DocumentName()
rs.Command("Open No " + chr(34) + document_location + chr(34))
38 changes: 38 additions & 0 deletions $$/SelColorOnlyInBlocks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import rhinoscriptsyntax as rs
import scriptcontext as sc
import Rhino

selected_colors = list()

# get colors of blocks' sub-objects
# looping through all objects due to: https://discourse.mcneel.com/t/let-selcolor-command-select-objects-inside-blocks/151883/12
for object in sc.doc.Objects:
if type(object) == Rhino.DocObjects.InstanceObject:
sub_object_ids = object.GetSelectedSubObjects()
if sub_object_ids:
for sub_object_id in sub_object_ids:
sub_object = object.InstanceDefinition.GetObjects()[sub_object_id.Index]
sub_object_color = sub_object.Attributes.DrawColor(sc.doc)
selected_colors.append(sub_object_color)

# get colors of other objects
for object_id in rs.SelectedObjects():
object = rs.coercerhinoobject(object_id)
object_color = object.Attributes.DrawColor(sc.doc)
selected_colors.append(object_color)

def _SelColor(object):
for sub_object_id, sub_object in enumerate(object.InstanceDefinition.GetObjects()):
if type(sub_object) == Rhino.DocObjects.InstanceObject:
_SelColor(sub_object)
if sub_object.Attributes.DrawColor(sc.doc) in selected_colors:
object.SelectSubObject(Rhino.Geometry.ComponentIndex(Rhino.Geometry.ComponentIndexType.InstanceDefinitionPart, sub_object_id), True, True, True)

# select objects by color recursively, even though doesn't work for nested blocks
# https://discourse.mcneel.com/t/let-selcolor-command-select-objects-inside-blocks/151883/13
for object in sc.doc.Objects:
if type(object) == Rhino.DocObjects.InstanceObject:
_SelColor(object)

rs.EnableRedraw()
rs.Redraw()
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import scriptcontext as sc
import rhinoscriptsyntax as rs

object_ids = rs.GetObjects(preselect=True)

if object_ids:
object_layers = []
for object_id in object_ids:
object_layers.append(rs.ObjectLayer(object_id))

rs.ObjectsByLayer(object_layers)
15 changes: 15 additions & 0 deletions $$/SelLayerByObject-GOT-A-BIT-CONFUSED-HERE.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import scriptcontext as sc
import rhinoscriptsyntax as rs

object_id = rs.GetObject(preselect=True)
object_layer = rs.ObjectLayer(object_id)
a=rs.ObjectsByLayer(object_layer)
a

#this won't work - rs.ObjectsByLayer doesn't accept lists
#if object_ids:
# object_layers = []
# for object_id in object_ids:
# object_layers.append(rs.ObjectLayer(object_id))
#
# rs.ObjectsByLayer(object_layers)
40 changes: 40 additions & 0 deletions $$/SelMaterialOnlyInBlocks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import rhinoscriptsyntax as rs
import scriptcontext as sc
import Rhino

selected_materials = list()

# get materials of blocks' sub-objects
# looping through all objects due to: https://discourse.mcneel.com/t/let-selcolor-command-select-objects-inside-blocks/151883/12
for object in sc.doc.Objects:
if type(object) == Rhino.DocObjects.InstanceObject:
sub_object_ids = object.GetSelectedSubObjects()
if sub_object_ids:
for sub_object_id in sub_object_ids:
sub_object = object.InstanceDefinition.GetObjects()[sub_object_id.Index]
if sub_object.RenderMaterial:
sub_object_material = sub_object.RenderMaterial.Id
selected_materials.append(sub_object_material)

# get materials of other objects
for object_id in rs.SelectedObjects():
object = rs.coercerhinoobject(object_id)
if object.RenderMaterial:
object_material = object.RenderMaterial.Id
selected_materials.append(object_material)

def _SelMaterial(object):
for sub_object_id, sub_object in enumerate(object.InstanceDefinition.GetObjects()):
if type(sub_object) == Rhino.DocObjects.InstanceObject:
_SelMaterial(sub_object)
if sub_object.RenderMaterial and sub_object.RenderMaterial.Id in selected_materials:
object.SelectSubObject(Rhino.Geometry.ComponentIndex(Rhino.Geometry.ComponentIndexType.InstanceDefinitionPart, sub_object_id), True, True, True)

# select objects by material recursively, even though doesn't work for nested blocks
# https://discourse.mcneel.com/t/let-selcolor-command-select-objects-inside-blocks/151883/13
for object in sc.doc.Objects:
if type(object) == Rhino.DocObjects.InstanceObject:
_SelMaterial(object)

rs.EnableRedraw()
rs.Redraw()
9 changes: 9 additions & 0 deletions $$/SelectAllObjsOnObjLayers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import rhinoscriptsyntax as rs

def SelectAllObjsOnObjLayers():
objs=rs.GetObjects("Select objects",preselect=True)
if not objs: return
rs.EnableRedraw(False)
layers=[rs.ObjectLayer(obj) for obj in objs]
for layer in layers: rs.ObjectsByLayer(layer,True)
SelectAllObjsOnObjLayers()
93 changes: 93 additions & 0 deletions $$/SetAllLayerPrintWidths-Chetwoods-Standard-ctb-TOO-SLOW.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
import rhinoscriptsyntax as rs
import re

#find layers that have one of the codes in the name
layers = [layer for layer in rs.LayerNames() if ">" not in layer and
re.search("AR[0-9]+", layer)]

def SetAllLayerPrintWidths():
for layer in layers:
[rs.LayerPrintWidth(layer, width=v) for k, v in ctb_printwidths.items()
if k in layer]

#codes extracted from template files
ctb_printwidths={
"AR000": 0.05,
"AR001": 0.05,
"AR002": 0.05,
"AR003": 0.1,
"AR004": 0.05,
"AR006": 0.05,
"AR007": 0.18,
"AR008": 0.05,
"AR009": 0.05,
"AR031": 0.1,
"AR035": 0.05,
"AR036": 0.05,
"AR042": 0.05,
"AR061": 0.05,
"AR062": 0.05,
"AR063": 0.05,
"AR070": 0.1,
"AR071": 0.05,
"AR075": 0.05,
"AR169": 0.1,
"AR211": 0.18,
"AR214": 0.1,
"AR216": 0.15,
"AR219": 0.1,
"AR221": 0.18,
"AR229": 0.05,
"AR231": 0.05,
"AR232": 0.25,
"AR237": 0.18,
"AR240": 0.15,
"AR241": 0.15,
"AR272": 0.18,
"AR277": 0.15,
"AR281": 0.18,
"AR282": 0.15,
"AR283": 0.15,
"AR310": 0.05,
"AR314": 0.1,
"AR315": 0.15,
"AR318": 0.1,
"AR319": 0.25,
"AR324": 0.15,
"AR325": 0.15,
"AR340": 0.1,
"AR351": 0.15,
"AR371": 0.15,
"AR413": 0.18,
"AR414": 0.1,
"AR420": 0.15,
"AR431": 0.05,
"AR439": 0.15,
"AR471": 0.05,
"AR520": 0.05,
"AR522": 0.05,
"AR525": 0.18,
"AR610": 0.18,
"AR611": 0.1,
"AR630": 0.1,
"AR640": 0.05,
"AR661": 0.15,
"AR664": 0.1,
"AR680": 0.05,
"AR683": 0.1,
"AR711": 0.1,
"AR731": 0.1,
"AR741": 0.05,
"AR783": 0.1,
"AR785": 0.05,
"AR900": 0.25,
"AR901": 0.05,
"AR902": 0.05,
"AR904": 0.05,
"AR905": 0.05,
"AR906": 0.05,
"AR907": 0.1,
"AR908": 0.1,
"AR910": 0.05}

SetAllLayerPrintWidths()
Loading

0 comments on commit 712d9ce

Please sign in to comment.