.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Drawable Overrule (for all entities)

2 REPLIES 2
SOLVED
Reply
Message 1 of 3
BKSpurgeon
1542 Views, 2 Replies

Drawable Overrule (for all entities)

Hi there esteemed colleagues

 

  • I was wondering if it was possible to create an overrule, such that what ever you are drawing on the XY plane, that is flipped up and is also seen in the XZ plane in addition to the customary XY plane.
  • I would like this overrule to work for all entities.

 

  • Is there are more efficient way of doing this? Given this method I would have to reimplement the world draw method of every single entity?

 

Advice much appreciated.

 

using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Runtime; 

class PlaneOverrule : DrawableOverrule
    {
        public override bool WorldDraw(Drawable drawable, WorldDraw wd)
        {
            // we want to apply a transformation so that the entity
            // is displayed in the XZ plane in addition to the XY plane
            // (or rather it is displayed normal to the plane it is actually drawn on
            // in addition to the entity's customary world draw implementation )

            Line line = drawable as Line;
            Matrix3d matrix = Matrix3d.Rotation(Math.PI / 2, Vector3d.YAxis, Point3d.Origin);
            Point3d start = line.StartPoint.TransformBy(matrix);
            Point3d end = line.EndPoint.TransformBy(matrix);

            wd.Geometry.WorldLine(start, end);            

                // We want the entity to be displayed as it normally would be
            return base.WorldDraw(drawable, wd);
        }
    }



 public class Commands
    {
        private static PlaneOverrule overrule;

        [CommandMethod("OverrideToDifferentPlane")]
        public void OverrideToDifferentPlane()
        {
            if (overrule == null)
            {
                overrule = new PlaneOverrule();
                Overrule.AddOverrule(RXObject.GetClass(typeof(Line)), overrule, false);
            }
            else
            {
                Overrule.RemoveOverrule(RXObject.GetClass(typeof(Line)), overrule);
                overrule.Dispose();
                overrule = null;
            }

            Overrule.Overruling = !Overrule.Overruling;

            Application.DocumentManager.MdiActiveDocument.Editor.Regen();
        }
    }
2 REPLIES 2
Message 2 of 3

Hi,

 

try adding overrule to all the entities like

 

Overrule.AddOverrule(RXObject.GetClass(typeof(Entity)), overrule, false);

and try using "GetTransformedCopy" API entity get the transferred copy so that your code works for all entities. refer below code (i have not tested for the entities though)

class PlaneOverrule : DrawableOverrule
{

    public DBObjectCollection copyCollection = new DBObjectCollection();

    public override bool WorldDraw(Drawable drawable, WorldDraw wd)
    {
        // we want to apply a transformation so that the entity
        // is displayed in the XZ plane in addition to the XY plane
        // (or rather it is displayed normal to the plane it is actually drawn on
        // in addition to the entity's customary world draw implementation )

        Matrix3d matrix = Matrix3d.Rotation(Math.PI / 2, Vector3d.YAxis, Point3d.Origin);

        /* Line line = drawable as Line;
            Matrix3d matrix = Matrix3d.Rotation(Math.PI / 2, Vector3d.YAxis, Point3d.Origin);
            Point3d start = line.StartPoint.TransformBy(matrix);
            Point3d end = line.EndPoint.TransformBy(matrix);
            wd.Geometry.WorldLine(start, end);*/

        Entity ent1 = drawable as Entity;

        if(ent1.ObjectId != ObjectId.Null)
        {
            Entity copyEnt = ent1.GetTransformedCopy(matrix);
            copyEnt.WorldDraw(wd);
            //to dispose the entities later..
            copyCollection.Add(copyEnt);
        }
        // We want the entity to be displayed as it normally would be
        return base.WorldDraw(drawable, wd);
    }
}

public class Commands2
{
    private static PlaneOverrule overrule;

    [CommandMethod("OverrideToDifferentPlane")]
    public void OverrideToDifferentPlane()
    {
        if (overrule == null)
        {
            overrule = new PlaneOverrule();
            Overrule.AddOverrule(RXObject.GetClass(typeof(Entity)), overrule, false);
        }
        else
        {
            //dispose the entities
            foreach(DBObject obj in overrule.copyCollection)
            {
                obj.Dispose();
            }

            Overrule.RemoveOverrule(RXObject.GetClass(typeof(Entity)), overrule);

            overrule.Dispose();
            overrule = null;
        }

        Overrule.Overruling = !Overrule.Overruling;

        Application.DocumentManager.MdiActiveDocument.Editor.Regen();
    }
}


Virupaksha Aithal KM
Developer Technical Services
Autodesk Developer Network

Message 3 of 3

Excellent thank you. I will try this out.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Forma Design Contest


AutoCAD Beta