Author Topic: AutoCAD - First Plug-in Training  (Read 19007 times)

0 Members and 1 Guest are viewing this topic.

Jeff H

  • Needs a day job
  • Posts: 5926
Re: AutoCAD - First Plug-in Training
« Reply #60 on: February 05, 2012, 08:27:28 AM »
A nicer way (thanks to kaefer to remind me the Viewport.EyeToWorldTransform property)

Replace:
Code - C#: [Select]
  1.               Point3d org = attRef.Position;
  2.               Vector3d zVec = vd.Viewport.ViewDirection;
  3.               Vector3d yVec = vd.Viewport.CameraUpVector;
  4.               Vector3d xVec = yVec.CrossProduct(zVec).GetNormal();
  5.               Matrix3d viewMat =
  6.                   Matrix3d.AlignCoordinateSystem(
  7.                   Point3d.Origin, Vector3d.XAxis, Vector3d.YAxis, Vector3d.ZAxis,
  8.                   org, xVec, yVec, zVec) *
  9.                   Matrix3d.WorldToPlane(new Plane(org, attRef.Normal)) *
  10.                   Matrix3d.Rotation(-attRef.Rotation, attRef.Normal, org);

With:
Code - C#: [Select]
  1.               Point3d org = attRef.Position;
  2.               Matrix3d viewMat =
  3.                   Matrix3d.Displacement(vd.Viewport.CameraTarget.GetVectorTo(org)) *
  4.                   vd.Viewport.EyeToWorldTransform *
  5.                   Matrix3d.WorldToPlane(new Plane(org, attRef.Normal)) *
  6.                   Matrix3d.Rotation(-attRef.Rotation, attRef.Normal, org);

I might of had something wrong but the second version made attribute move way off.
 
But for rotating the attribute the same distance from block insertion the first version seems to work very well with one small change if attribute is set to Middle Center.
Just changed
Code - C#: [Select]
  1. Point3d org = attRef.Position;
  2.  
to
Code - C#: [Select]
  1. Point3d org = attRef.AlignmentPoint;
  2.  

This pic at bottom might help explain a little as the "A" stays centered in the rectangle & 'GFI' position.
 
 
 

Jeff H

  • Needs a day job
  • Posts: 5926
Re: AutoCAD - First Plug-in Training
« Reply #61 on: February 05, 2012, 08:53:57 AM »
Just wanted to add that with settings mentioned below the only thing I have found so far that throws a little wrench in it is using a dynamic block with rotation paramter, but alignment parameters, dview, perspective on, and much more works great!
 
Thanks again Gile!!!!

gile

  • Water Moccasin
  • Posts: 2135
  • Marseille, France
Re: AutoCAD - First Plug-in Training
« Reply #62 on: February 05, 2012, 10:54:11 AM »
Hi,

Effectively, it didn't care about the attribute justification.

Quote
the second version made attribute move way off.
Curiously, it needs a kind of regeneration which occurs on starting a 3d orbit.

Anyway, here's a "more traditional" way which seems to work (with attribute justification too):
Code: [Select]
            Point3d org = attRef.Justify == AttachmentPoint.BaseLeft ||
                attRef.Justify == AttachmentPoint.BaseAlign ||
                attRef.Justify == AttachmentPoint.BaseFit ?
                attRef.Position : attRef.AlignmentPoint;
            Matrix3d viewMat =
                Matrix3d.PlaneToWorld(new Plane(org, vd.Viewport.ViewDirection)) *
                Matrix3d.WorldToPlane(new Plane(org, attRef.Normal)) *
                Matrix3d.Rotation(-attRef.Rotation, attRef.Normal, org);
Speaking English as a French Frog

Jeff H

  • Needs a day job
  • Posts: 5926
Re: AutoCAD - First Plug-in Training
« Reply #63 on: February 05, 2012, 11:10:51 AM »
I can think of a couple of ways to make the rotation persistant or modify the actual AtrributeReference, but just seeing what ideas anyone had.
 
To sum up what would you think the best approach to modify the AttributeReference so when the drawing is opened with overrule not loaded it appears the same until of course it gets modified?
 

gile

  • Water Moccasin
  • Posts: 2135
  • Marseille, France
Re: AutoCAD - First Plug-in Training
« Reply #64 on: February 05, 2012, 12:25:44 PM »
Hi,

By my side, I think the overruling route is nice because it doesn't modify the attribute (or whatever it applys to) geometry.

I'd make it "persistant" adding a class which implements IExtensionApplication to the project (assuming the ActivateOverrule is static and defined in the Commands class) and registering the dll so that it's automatically loaded.

Code: [Select]
    public class ExtensionApplication : IExtensionApplication
    {
        public void Initialize()
        {
            Commands.ActivateOverrule();
        }

        public void Terminate() { }
    }
Speaking English as a French Frog

Jeff H

  • Needs a day job
  • Posts: 5926
Re: AutoCAD - First Plug-in Training
« Reply #65 on: February 05, 2012, 12:50:47 PM »
If you are wanting to send it to a client who does not have it loaded then all the attributes are every which way.
 
Also noticed that if I changed ModelSpace's Visual Style to anything other 2d Wireframe it would not move or be hidden during the jig, but once set it was placed correctly.
Overriding SetAttributes corrected the issue but had to use most expensive flag
Code - C#: [Select]
  1. public override int SetAttributes(Drawable drawable, DrawableTraits traits)
  2.        {
  3.            return base.SetAttributes(drawable, traits) + (int)DrawableAttributes.RegenDraw;
  4.        }
  5.