Author Topic: Jigging a block with Alignment parameter  (Read 6721 times)

0 Members and 1 Guest are viewing this topic.

Jeff H

  • Needs a day job
  • Posts: 6150
Jigging a block with Alignment parameter
« on: November 14, 2012, 12:01:21 PM »
Got A jig that helps with some additional tasks for inserting BlockReferences but does not take in consideration blocks with alignment parameters. Any ideas on how to approach jigging blocks with alignment parameters?

TheMaster

  • Guest
Re: Jigging a block with Alignment parameter
« Reply #1 on: November 14, 2012, 05:09:04 PM »
Got A jig that helps with some additional tasks for inserting BlockReferences but does not take in consideration blocks with alignment parameters. Any ideas on how to approach jigging blocks with alignment parameters?

The RXClass for BlockReference exposes an event that can be handled, but I've never used it myself, so I can't if that's a solution.

Jeff H

  • Needs a day job
  • Posts: 6150
Re: Jigging a block with Alignment parameter
« Reply #2 on: November 14, 2012, 05:24:18 PM »
Got A jig that helps with some additional tasks for inserting BlockReferences but does not take in consideration blocks with alignment parameters. Any ideas on how to approach jigging blocks with alignment parameters?

The RXClass for BlockReference exposes an event that can be handled, but I've never used it myself, so I can't if that's a solution.
Got A jig that helps with some additional tasks for inserting BlockReferences but does not take in consideration blocks with alignment parameters. Any ideas on how to approach jigging blocks with alignment parameters?

The RXClass for BlockReference exposes an event that can be handled, but I've never used it myself, so I can't if that's a solution.
I subscribed to the EntityAlignment event which was only raised when using AutoCADs "INSERT" command, but not when jigging a Block that contained one.

Glancing at and comparing a couple of BlockTableRecords and Reference's with MgdDbg that were dynamic, non-dynamic, dynamic with alignment parameter and dynamic without an alignment parameter , etc.... I did not see anything in its properties, entities it contained, and/or the block or entities it contained xdata or ExtensionDictionaries that indicated it had an alignment parameter

TheMaster

  • Guest
Re: Jigging a block with Alignment parameter
« Reply #3 on: November 14, 2012, 07:20:32 PM »
Got A jig that helps with some additional tasks for inserting BlockReferences but does not take in consideration blocks with alignment parameters. Any ideas on how to approach jigging blocks with alignment parameters?

The RXClass for BlockReference exposes an event that can be handled, but I've never used it myself, so I can't if that's a solution.
Got A jig that helps with some additional tasks for inserting BlockReferences but does not take in consideration blocks with alignment parameters. Any ideas on how to approach jigging blocks with alignment parameters?

The RXClass for BlockReference exposes an event that can be handled, but I've never used it myself, so I can't if that's a solution.
I subscribed to the EntityAlignment event which was only raised when using AutoCADs "INSERT" command, but not when jigging a Block that contained one.

Glancing at and comparing a couple of BlockTableRecords and Reference's with MgdDbg that were dynamic, non-dynamic, dynamic with alignment parameter and dynamic without an alignment parameter , etc.... I did not see anything in its properties, entities it contained, and/or the block or entities it contained xdata or ExtensionDictionaries that indicated it had an alignment parameter

Then in that case, a PointMonitor event handler might give you some useful information about what candidate alignment entities are in the aperture, and that might be how the INSERT command does it.

Autodesk probably has a special Jig-based class for placiong blocks that's used by the INSERT command, and if there is one, it's most certainly 'internal-use-only'.

Jeff H

  • Needs a day job
  • Posts: 6150
Re: Jigging a block with Alignment parameter
« Reply #4 on: November 15, 2012, 12:46:26 PM »
Need to go back and get a better fundamental understanding of geometry but can anyone help with how you would align to line?
Might help me better grasp the math or general idea.
 
Thanks

MexicanCustard

  • Swamp Rat
  • Posts: 705
Re: Jigging a block with Alignment parameter
« Reply #5 on: November 15, 2012, 12:56:10 PM »
Need to go back and get a better fundamental understanding of geometry but can anyone help with how you would align to line?
Might help me better grasp the math or general idea.
 
Thanks

What are we tying to align with a line? 
Revit 2019, AMEP 2019 64bit Win 10

Jeff H

  • Needs a day job
  • Posts: 6150
Re: Jigging a block with Alignment parameter
« Reply #6 on: November 15, 2012, 01:06:14 PM »
Need to go back and get a better fundamental understanding of geometry but can anyone help with how you would align to line?
Might help me better grasp the math or general idea.
 
Thanks

What are we tying to align with a line?
Looks like I left out a very important detail, but a block reference.
I not sure how to explain correctly because of the lack of my understaning of the fundamentals of the math, but the BlocktableRecord's X-axis to lie parallel with the line, and maybe if I get a understanding of that then maybe how to control the direction of y-axis

TheMaster

  • Guest
Re: Jigging a block with Alignment parameter
« Reply #7 on: November 15, 2012, 02:44:18 PM »
Need to go back and get a better fundamental understanding of geometry but can anyone help with how you would align to line?
Might help me better grasp the math or general idea.
 
Thanks

You can align with any curve using the direction defined by the value returned by a call to the curve's GetFirstDerivative() method, which is a vector that's tangent to the curve at the point/parameter argument. That vector can be used to compute a transformation matrix that can then be passed to TransformBy().


gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: Jigging a block with Alignment parameter
« Reply #8 on: November 15, 2012, 03:05:37 PM »
Hi,

You can set the block rotation before passig it to the Jig constructor. If you want the block to be on the line, you can use GetClosestPointTo with the line (passed to Jig ctor too).

Here's a little example (only working in 2d, for 3d lines another parameter should be neede to determinate the insterion plane).

Code - C#: [Select]
  1. using System;
  2. using Autodesk.AutoCAD.ApplicationServices;
  3. using Autodesk.AutoCAD.DatabaseServices;
  4. using Autodesk.AutoCAD.EditorInput;
  5. using Autodesk.AutoCAD.Geometry;
  6. using Autodesk.AutoCAD.Runtime;
  7. using AcAp = Autodesk.AutoCAD.ApplicationServices.Application;
  8.  
  9. namespace AlignBlockSample
  10. {
  11.     public class Commands
  12.     {
  13.         [CommandMethod("Test")]
  14.         public void Test()
  15.         {
  16.             Document doc = AcAp.DocumentManager.MdiActiveDocument;
  17.             Database db = doc.Database;
  18.             Editor ed = doc.Editor;
  19.             PromptEntityOptions opts = new PromptEntityOptions("\nSelect a line: ");
  20.             opts.SetRejectMessage("Only a line.");
  21.             opts.AddAllowedClass(typeof(Line), true);
  22.             PromptEntityResult per = ed.GetEntity(opts);
  23.             if (per.Status != PromptStatus.OK) return;
  24.             using (Transaction tr = db.TransactionManager.StartTransaction())
  25.             {
  26.                 Line line = (Line)tr.GetObject(per.ObjectId, OpenMode.ForRead);
  27.                 Vector3d vec = line.StartPoint.GetVectorTo(line.EndPoint);
  28.                 Double angle = Vector3d.XAxis.GetAngleTo(vec, Vector3d.ZAxis);
  29.                 BlockTable bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead);
  30.                 using (BlockReference br = new BlockReference(Point3d.Origin, bt["bloc"]))
  31.                 {
  32.                     br.TransformBy(Matrix3d.Rotation(angle, Vector3d.ZAxis, Point3d.Origin));
  33.                     BlockJig jig = new BlockJig(br, line);
  34.                     PromptResult pr = ed.Drag(jig);
  35.                     if (pr.Status == PromptStatus.OK)
  36.                     {
  37.                         BlockTableRecord btr = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
  38.                         btr.AppendEntity(br);
  39.                         tr.AddNewlyCreatedDBObject(br, true);
  40.                     }
  41.                 }
  42.                 tr.Commit();
  43.             }
  44.         }
  45.  
  46.         class BlockJig : EntityJig
  47.         {
  48.  
  49.             Point3d _dragPt;
  50.             BlockReference _br;
  51.             Line _line;
  52.  
  53.             public BlockJig(BlockReference br, Line line)
  54.                 : base(br)
  55.             {
  56.                 _br = br;
  57.                 _dragPt = br.Position;
  58.                 _line = line;
  59.             }
  60.  
  61.             protected override SamplerStatus Sampler(JigPrompts prompts)
  62.             {
  63.                 JigPromptPointOptions jppo = new JigPromptPointOptions("\nSpecify insertion point: ");
  64.                 PromptPointResult ppr = prompts.AcquirePoint(jppo);
  65.                 if (_dragPt.IsEqualTo(ppr.Value))
  66.                     return SamplerStatus.NoChange;
  67.                 else
  68.                     _dragPt = _line.GetClosestPointTo(ppr.Value, false);
  69.                 return SamplerStatus.OK;
  70.             }
  71.  
  72.             protected override bool Update()
  73.             {
  74.                 _br.Position = _dragPt;
  75.                 return true;
  76.             }
  77.         }
  78.     }
  79. }
  80.  
Speaking English as a French Frog

Jeff H

  • Needs a day job
  • Posts: 6150
Re: Jigging a block with Alignment parameter
« Reply #9 on: November 16, 2012, 05:21:55 PM »
Thanks guys,
 
With your info I might be able to get something going.
Now to go back and look over PointMonitor.

BlackBox

  • King Gator
  • Posts: 3770
Re: Jigging a block with Alignment parameter
« Reply #10 on: November 16, 2012, 06:18:36 PM »
Now to go back and look over PointMonitor.

You probably have better resources than I, so FWIW, Tony's correction of Kean's old post here (scroll down), was very helpful to me in starting an (albeit an unfinished) 'mouse hover' plug-in over at CT.


** Edit to add - Seems only fitting to say "Thanks, Tony!" as the man's following this thread too. :beer:
"How we think determines what we do, and what we do determines what we get."

TheMaster

  • Guest
Re: Jigging a block with Alignment parameter
« Reply #11 on: November 16, 2012, 08:28:42 PM »
Now to go back and look over PointMonitor.

You probably have better resources than I, so FWIW, Tony's correction of Kean's old post here (scroll down), was very helpful to me in starting an (albeit an unfinished) 'mouse hover' plug-in over at CT.


** Edit to add - Seems only fitting to say "Thanks, Tony!" as the man's following this thread too. :beer:

YW :beer:


Jeff H

  • Needs a day job
  • Posts: 6150
Re: Jigging a block with Alignment parameter
« Reply #13 on: November 20, 2012, 04:35:56 PM »
First before I get ahead of myself and not too get too in depth for now but in general is okay to think of GetFirstDerivative() as a First Derivative test as it looks at the points just to each side and returns a vector tangent at that point.(Which Tony already better explained).
 
Just playing with code from Link posted previously.
I know this is not the way to do it but I just do not remember, or to state it correctly  instead of actually learning the material for Calculus I,II,III  I just remembered what I had needed to pass the test(I really regret it now). 
 
Just messing around with and to my suprise for straight curves functions much like a block with alignment parameter but could someone point in the right direction or to material to help understand the math involved.
 
This falls flat on its face in numerous situations
Code - C#: [Select]
  1.  if (Bref.Position.X < pnt.X || Bref.Position.Y < pnt.Y)
  2. {
  3. dir = dir.Negate();
  4. }

Code - C#: [Select]
  1.  
  2.                  case 1:
  3.                     Bref.Position = mPosition.TransformBy(UCS);
  4.                     if (mIsDynamicAlignment)
  5.                     {
  6.                         if (!mObjectIdToAlignWith.IsNull)
  7.                         {
  8.                             if (mObjectIdToAlignWith.ObjectClass.IsDerivedFrom(RXClass.GetClass(typeof(Curve))))
  9.                             {
  10.                                 Curve curve = (Curve)Bref.Database.TransactionManager.TopTransaction.GetObject(mObjectIdToAlignWith, OpenMode.ForRead);
  11.                                 Point3d pnt = curve.GetClosestPointTo(Bref.Position, false);
  12.                                 Vector3d dir = curve.GetFirstDerivative(pnt).TransformBy(UCS.Inverse());
  13.                                 if (Bref.Position.X < pnt.X || Bref.Position.Y < pnt.Y)
  14.                                 {
  15.                                     dir = dir.Negate();
  16.                                 }
  17.                                 mAlignmentAngle = Vector3d.XAxis.GetAngleTo(dir, Vector3d.ZAxis);
  18.                                 Bref.Rotation = mAlignmentAngle   mAngleOffset;
  19.                             }
  20.                         }
  21.                         else
  22.                         {
  23.                             Bref.Rotation = 0.0;
  24.                         }
  25.                         foreach (DynamicBlockReferenceProperty props in Bref.DynamicBlockReferencePropertyCollection)
  26.                         {
  27.                             if (props.PropertyName == "TextRotation")
  28.                             {
  29.                                 props.Value = Bref.Rotation == 0.0 ? 0.0 : ((360.0 - (Bref.Rotation * (180.0 / System.Math.PI))) * (System.Math.PI / 180.0));
  30.                             }
  31.                         }
  32.                     }
  33.  

TheMaster

  • Guest
Re: Jigging a block with Alignment parameter
« Reply #14 on: November 21, 2012, 03:05:46 PM »
First before I get ahead of myself and not too get too in depth for now but in general is okay to think of GetFirstDerivative() as a First Derivative test as it looks at the points just to each side and returns a vector tangent at that point.(Which Tony already better explained).
 
Just playing with code from Link posted previously.
I know this is not the way to do it but I just do not remember, or to state it correctly  instead of actually learning the material for Calculus I,II,III  I just remembered what I had needed to pass the test(I really regret it now). 
 
Just messing around with and to my suprise for straight curves functions much like a block with alignment parameter but could someone point in the right direction or to material to help understand the math involved.
 

Have you considered using Command( "._INSERT", "blockname"...) to solve this problem?