Rhinoscriptsyntax insert bug?

I’m trying to insert a block in python using a plane to define the rotation of the insertion.
When I manually try the insert command and its parameters, everything works fine, but when using python to execute the same commands, the inserted block is way off
Seen in the screenshot below, the executed command is exactly the same, but the resulting geometry is in different positions

the code I’m executing:

import rhinoscriptsyntax as rs

command = "_-Insert File=No \"{}\" Block {} 1 A {} {}".format(name, pln.Origin, pln.Origin+pln.XAxis, pln.Origin+pln.YAxis)

Recording of the process:

Rhino 7 SR28 2023-2-27 (Rhino 7, 7.28.23058.03001, Git hash:master @ 4ffc5d7156fbccf2a5d9fcc80e522b3851bc7f6c)
License type: Educational, build 2023-02-27
License details: Cloud Zoo

Windows 11 (10.0.22621 SR0.0) or greater (Physical RAM: 16Gb)

Computer platform: LAPTOP  - Plugged in [100% battery remaining]

Non-hybrid graphics configuration.
  Primary display and OpenGL: NVIDIA GeForce GTX 1060 (NVidia) Memory: 6GB, Driver date: 2-2-2023 (M-D-Y). OpenGL Ver: 4.6.0 NVIDIA 528.49
    > Integrated accelerated graphics device with 4 adapter port(s)
        - Windows Main Display is laptop's integrated screen or built-in port

Secondary graphics devices.
  Intel(R) HD Graphics 530 (Intel) Memory: 1GB, Driver date: 12-3-2021 (M-D-Y).
    > Integrated graphics device with 3 adapter port(s)
        - There are no monitors attached to this device. Laptop lid is probably closed

OpenGL Settings
  Safe mode: Off
  Use accelerated hardware modes: On
  Redraw scene when viewports are exposed: On
  Graphics level being used: OpenGL 4.6 (primary GPU's maximum)
  Anti-alias mode: 4x
  Mip Map Filtering: Linear
  Anisotropic Filtering Mode: High
  Vendor Name: NVIDIA Corporation
  Render version: 4.6
  Shading Language: 4.60 NVIDIA
  Driver Date: 2-2-2023
  Driver Version:
  Maximum Texture size: 32768 x 32768
  Z-Buffer depth: 24 bits
  Maximum Viewport size: 32768 x 32768
  Total Video Memory: 6 GB

Rhino plugins that do not ship with Rhino

Rhino plugins that ship with Rhino
  C:\Program Files\Rhino 7\Plug-ins\Commands.rhp	"Commands"	7.28.23058.3001
  C:\Program Files\Rhino 7\Plug-ins\rdk.rhp	"Renderer Development Kit"	
  C:\Program Files\Rhino 7\Plug-ins\RhinoRenderCycles.rhp	"Rhino Render"	7.28.23058.3001
  C:\Program Files\Rhino 7\Plug-ins\rdk_etoui.rhp	"RDK_EtoUI"	7.28.23058.3001
  C:\Program Files\Rhino 7\Plug-ins\rdk_ui.rhp	"Renderer Development Kit UI"	
  C:\Program Files\Rhino 7\Plug-ins\NamedSnapshots.rhp	"Snapshots"	
  C:\Program Files\Rhino 7\Plug-ins\IronPython\RhinoDLR_Python.rhp	"IronPython"	7.28.23058.3001
  C:\Program Files\Rhino 7\Plug-ins\RhinoCycles.rhp	"RhinoCycles"	7.28.23058.3001
  C:\Program Files\Rhino 7\Plug-ins\Grasshopper\GrasshopperPlugin.rhp	"Grasshopper"	7.28.23058.3001
  C:\Program Files\Rhino 7\Plug-ins\Toolbars\Toolbars.rhp	"Toolbars"	7.28.23058.3001
  C:\Program Files\Rhino 7\Plug-ins\3dxrhino.rhp	"3Dconnexion 3D Mouse"	
  C:\Program Files\Rhino 7\Plug-ins\Displacement.rhp	"Displacement"	
  C:\Program Files\Rhino 7\Plug-ins\RhinoBonusTools.rhp	"Rhino Bonus Tools"	
  C:\Program Files\Rhino 7\Plug-ins\AnimationTools.rhp	"AnimationTools"	

print command, and connect a text panel to out, to check exactly what is being sent to rs.command

seems correct?

What happens when you paste that into the Command box in Rhino?

Hi @victorlin,

If the block definition exists in the document, then there really isn’t any need to script the Insert command (sample below).

test_insert_block.gh (3.3 KB)

– Dale

_-Insert "Panel 200" Block 5,5,0 1 A 6,5,0 5,6,0
Pasting this command in the command box also doesn’t work, but I don’t understand why.
It seems to me that the cursor position somehow influences the command. If my cursor moves, the position it’s being inserted at will change.

thanks for proposing an alternative, it works well, I tweaked it slightly so I don’t have to define the rotation
xform = t.PlaneToPlane(rg.Plane.WorldXY, pln)
but question: if in the future, I’m trying to insert from file, I’ll again run into this issue?
Any idea why the command doesn’t work as I expected?

Hi @victorlin,

Currently, there is no API to insert blocks from files. Thus, you’ll need to script the Insert command.

– Dale

Hi Dale, that’s what i meant, if I want to insert blocks from files, I’ll need to script the Insert command, so this goes back to my original question of why doesn’t my command work when using the AxisAlign option.

Looking at the command
_-Insert "Panel 200" Block 5,5,0 1 A 6,5,0 5,6,0
and command history
I don’t see anything wrong with the command I’m issuing, so why is the behavior not as expected (not the same result as inputting the parameters one by one)?

I think this is what is happening:

When you enter the command manually the focus is on the command line. When you run the command from grasshopper the focus is not on the command line.

In pseudocode, the interpreter logic for the two axisAlign points is probably

if focus on command line then
    get position from command line
    get position from cursor

If the logic was changed to

if focus on viewport canvas then
    get position from cursor
    get position from command line

then the command would work as expected. One for @dale to rule on.


Footnote: I wonder whether there are other commands where this is true…


One follow up: The command seems to work ok in Grasshopper in the Rhino 8 WIP.

Second follow up: if you use alignment points related to a rotated plane then you get unwanted displacements when entering the command manually in either Rhino version. I think this is a bug but it could be that I am misunderstanding the command.