using System;
using System.Collections.Generic;
using System.Linq;
using Grasshopper.Kernel;
using Rhino;
using Rhino.DocObjects;
using Rhino.Geometry;
namespace LandoTools
{
public class DeconstructBlockReference : GH_Component
{
///
/// Initializes a new instance of the DeconstructBlockReference class.
///
public DeconstructBlockReference()
: base("DeconstructBlockReference", "Nickname",
"Description",
"LandoTools", "Blocks")
{
}
///
/// Registers all the input parameters for this component.
///
protected override void RegisterInputParams(GH_Component.GH_InputParamManager pManager)
{
pManager.AddGenericParameter("Blockreference", "R", "Blockreference to deconstruct", GH_ParamAccess.item);
}
///
/// Registers all the output parameters for this component.
///
protected override void RegisterOutputParams(GH_Component.GH_OutputParamManager pManager)
{
pManager.AddGenericParameter("Parent Block", "B", "Block of which this is a reference",
GH_ParamAccess.item);
pManager.AddPointParameter("Insertion Point", "Pt", "Insertion point of reference", GH_ParamAccess.item);
pManager.AddTransformParameter("Transformation", "X", "Transformation for this reference",
GH_ParamAccess.item);
pManager.AddGeometryParameter("Geometry", "G", "Transformed Geometry of this reference",
GH_ParamAccess.list);
}
///
/// This is the method that actually does the work.
///
/// The DA object is used to retrieve from inputs and store in outputs.
protected override void SolveInstance(IGH_DataAccess DA)
{
InstanceReferenceGeometry reference = null;
if (!DA.GetData(0, ref reference)) return;
RhinoDoc doc = Rhino.RhinoDoc.ActiveDoc;
var parent = doc.InstanceDefinitions.FindId(reference.ParentIdefId);
var transform = reference.Xform;
var insert = Point3d.Origin;
insert.Transform(transform);
var geometry = from x in parent.GetObjects() select x.Geometry;
foreach (var geometryBase in geometry)
{
geometryBase.Transform(transform);
}
DA.SetData(0, parent);
DA.SetData(1, insert);
DA.SetData(2, transform);
DA.SetDataList(3, geometry);
}
///
/// Provides an Icon for the component.
///
protected override System.Drawing.Bitmap Icon
{
get
{
//You can add image files to your project resources and access them like this:
// return Resources.IconForThisComponent;
return null;
}
}
///
/// Gets the unique ID for this component. Do not change this ID after release.
///
public override Guid ComponentGuid
{
get { return new Guid("98ba9215-22a9-49c8-b5ea-40c65b56308e"); }
}
}
}