Insert block to a given point Point3d(233.03, 110.70, 0.0)

This question is specially to Dale. But if anybody answer it, many thanks in advance !
Thanks to Dale for the code below !

//------------------------------------------------------------------------------------------------------------
protected override Result RunCommand(RhinoDoc doc, RunMode mode)
{
var idef = doc.InstanceDefinitions.Find(“Test”, true);
if (null != idef)
{
var xform = new Transform(1.0);
doc.Objects.AddInstanceObject(idef.Index, xform);
doc.Views.Redraw();
}
return Result.Success;
}
//------------------------------------------------------------------------------------------------------

//------------------------------------------------------------------------------------------------------
… Actually I need to insert the block on a specific point.

For example the given point is Point3d(233.03, 110.70, 0.0)

Please let me know a simplest way how to insert my block to this given point
Point3d(233.03, 110.70, 0.0).

… I found some sample code regarding transforming object to a mouse picked point and there were override methods. Simpler and shorted way is preferable. Many thanks in advance !

Block definitions are based at the world origin (0,0,0). So if you want to insert a block instance at a location, you need to transform it from the origin to that location:

protected override Result RunCommand(RhinoDoc doc, RunMode mode)
{
  var idef = doc.InstanceDefinitions.Find("Test", true);
  if (null != idef)
  {
    var pt = new Point3d(233.03, 110.70, 0.0);
    var dir = pt - Point3d.Origin;
    var xform = Transform.Translation(dir);
    doc.Objects.AddInstanceObject(idef.Index, xform);
    doc.Views.Redraw();
  }
  return Result.Success;
}
1 Like

Thanks a lot ! Dale :slight_smile: