Replacing Points with Block - Need a Mac Solution

I’d like to be able to replace selected points with a block. I found this older Windows script and wonder if there is a way to convert it to work in the Mac version or if there is another script to do the same thing.

' Replaces points with blocks
Sub ReplacePointsWithBlocks
 
  ' Select points to replace with a block
  Dim arrObjects
  arrObjects = Rhino.GetObjects("Select points to replace with a block", 1, True, True)
  If Not IsArray(arrObjects) Then Exit Sub
 
  ' Get the names of all block definitions in the document    
  Dim arrBlocks
  arrBlocks = Rhino.BlockNames(True)
  If Not IsArray(arrBlocks) Then
    Rhino.Print "No block definitions found in the document."
    Exit Sub
  End If
 
  ' Select a block name from a list
  Dim strBlock
  strBlock = Rhino.ListBox(arrBlocks, "Select block", "Replace Points")
  If IsNull(strBlock) Then Exit Sub
 
  ' Turn off redrawing (faster)
  Rhino.EnableRedraw True      
 
  ' Process each selected point object
  Dim strObject, arrPoint
  For Each strObject In arrObjects
    ' Get the point object's coordinates
    arrPoint = Rhino.PointCoordinates(strObject)
    ' Insert the block at that location
    Rhino.InsertBlock strBlock, arrPoint
  Next
 
  ' Delete all of the point objects
  Rhino.DeleteObjects arrObjects   
 
  ' Turn redrawing back on     
  Rhino.EnableRedraw True      
 
End Sub

Hi @JEFF_DEAN,

This works in Rhino 8:

#! python 3
import rhinoscriptsyntax as rs

def ReplacePointsWithBlocks():
    arrObjects = rs.GetObjects("Select points to replace with a block", 1, True, True)
    if not arrObjects:
        return

    arrBlocks = rs.BlockNames(True)
    if not arrBlocks:
        print("No block definitions found in the document.")
        return

    strBlock = rs.ListBox(arrBlocks, "Select block", "Replace Points")
    if not strBlock:
        return

    for strObject in arrObjects:
        arrPoint = rs.PointCoordinates(strObject)
        rs.InsertBlock(strBlock, arrPoint)

    rs.DeleteObjects(arrObjects)
    rs.Redraw()

if __name__ == "__main__":
    ReplacePointsWithBlocks()    

ReplacePointsWithBlocks.py (681 Bytes)

– Dale

Thanks, Dale

When I add the script to the Command section for a new toolbar button and save it, clicking on the button just makes the sidebar toolset refresh, but doesn’t open a dialog to select points. Am I missing something in how to implement it?

Jeff

@JEFF_DEAN - your button macro should look like this:

_-ScriptEditor _Run "ReplacePointsWithBlocks.py"

Make sure to specify the full path to the .py file.

– Dale