Hi!
I’m looking for a way to create a custom object that could be used to store meta-information about the model (specifically a Plane and Vector2d), display this information as some geometry object that is derived from this (in this case some kind of a plane origin indicator curves and a rectangle) and keep these two connected that one would be created/moved/selected/deleted etc together the other.
I tried to make some approximation of what it should look like with black representing the geometry that is visible to the user and red representing the underlying data.
I guess I could store this data outside of the object table as just user data in the document and make it visible by display conduits with some commands, but it would make it much easier to handle this data it if these were represented as objects in the model space and I could manipulate these objects to manipulate the meta-information.
It seems that it should be something that is possible with the Rhino.Geometry.Custom classes, but I can’t find samples about this.
So there’s probably two separate questions in here:
- Is there a way to create a custom Rhino object that would internally contain two geometry objects and represent them in some other form in the document?
- How to make this element modifiable in the model space? Would it be possible to use custom grips for this?
Regards,
Taavi
Yes you can keep all your data in a class that inherits from UserData. Additionally you need a class that derives from CustomCurveObject which has your UserData applied and draws geometry accordingly.
The second part is harder though, maybe it is possible to create some custom grips I have no experience with those though
Edit: here I’d the sample that got me started with userdata Sample
On my phone right now I could post a code example tomorrow
Here is the promised sample i wrote when learning the concept. It’s quite simple but it should be a good start. Let me know if you need more help
public class MyCustomBrep : CustomBrepObject
{
public MyCustomBrep() { }
public MyCustomBrep(MyUserData data, Brep brep) : base(brep)
{
this.Geometry.UserData.Add(data);
}
protected override void OnDraw(DrawEventArgs e)
{
MyUserData data = Geometry.UserData.Find(typeof(MyUserData)) as MyUserData;
VolumeMassProperties vmp = VolumeMassProperties.Compute(this.BrepGeometry);
Sphere sphere = new Sphere(vmp.Centroid, data.Weight);
e.Display.DrawSphere(sphere, Color.Red);
base.OnDraw(e);
}
}
public class MyUserData : UserData
{
public double Weight { get; set; }
public MyUserData() {}
public MyUserData(double weight)
{
Weight = weight;
}
public override bool ShouldWrite
{
get
{
if (Weight > 0.0) return true;
return false;
}
}
public override string Description
{
get { return "Physical Properties"; }
}
public override string ToString()
{
return String.Format("weight={0}", Weight);
}
protected override void OnDuplicate(Rhino.DocObjects.Custom.UserData source)
{
MyUserData src = source as MyUserData;
if (src != null)
{
Weight = src.Weight;
}
}
}