Hello,
I’m trying to do the sequence in C#:
Select Block in rhino and copy it to another point.
And all does not workong propely for Bocks. What am I doing wrong?
…
protected override Result RunCommand(RhinoDoc doc, RunMode mode)
{
//01 - Point variable
var pt0 = new Point3d(0, 0, 0);
var pt1 = new Point3d(10, 0, 0);
//02 - Selecting Block
var go = new GetObject();
go.SetCommandPrompt("Select Block");
go.GeometryFilter = ObjectType.InstanceReference;
go.SubObjectSelect = false;
go.Get();
if (go.CommandResult() != Result.Success)
return go.CommandResult();
//03 - Get the selected object
var PBlockBeam = go.Object(0).Object() as InstanceObject;
if (PBlockBeam == null)
return Result.Failure;
//04 - Vector
var MoveObject = new Vector3d (pt1 - pt0);
//05 - Copy the block to the destination point
var PBlockBeamCopy = PBlockBeam.DuplicateGeometry();
PBlockBeamCopy.Translate(MoveObject);
//06 - Add the copy to the document
doc.Objects.Add(PBlockBeamCopy);
doc.Views.Redraw();
return Result.Success;
}
Hello Dale,
No, unfortunately that’s not it. Your code is for moving.
I still can’t build a C# code to copy an element that is a block. I can do code for copying different elements, but copying a block from one point to another doesn’t work and I don’t know why.
//01 - Point variable
var pt0 = new Point3d(0, 0, 0);
var pt1 = new Point3d(10, 0, 0);
//02 - Selecting Block
var go = new GetObject();
go.SetCommandPrompt("Select Block");
go.GeometryFilter = ObjectType.InstanceReference;
go.SubObjectSelect = false;
go.Get();
if (go.CommandResult() != Result.Success)
return go.CommandResult();
//03 - Get the selected object
var PBlockBeam = go.Object(0).Object() as InstanceObject;
if (PBlockBeam == null)
return Result.Failure;
//04 - Vector
var MoveObject = new Vector3d(pt1 - pt0);
//06 - Create new Transform by multiplying the Translation, and the already existing transformation of the selected block
Transform transform = Transform.Translation(MoveObject) * PBlockBeam.InstanceXform;
//06 - Add new Instance object at the new Location
doc.Objects.AddInstanceObject(PBlockBeam.InstanceDefinition.Index, transform);
doc.Views.Redraw();
return Result.Success;
I have one more question regarding the above C# code.
Is it possible to save the new copied BLOCK as a variable.
I ask because I would then like to extend the CODE and rotate and scale the copied BLOCK?