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

0 Members and 2 Guests 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?


Jeff H

  • Needs a day job
  • Posts: 6150
Re: Jigging a block with Alignment parameter
« Reply #15 on: November 21, 2012, 04:23:26 PM »
Yes but too much automation wanted to use built in 'Insert' command.

TheMaster

  • Guest
Re: Jigging a block with Alignment parameter
« Reply #16 on: November 21, 2012, 06:52:44 PM »
Yes but too much automation wanted to use built in 'Insert' command.

Ummmm.  Not sure I understand that. 

Jeff H

  • Needs a day job
  • Posts: 6150
Re: Jigging a block with Alignment parameter
« Reply #17 on: November 21, 2012, 07:27:51 PM »
Yes but too much automation wanted to use built in 'Insert' command.

Ummmm.  Not sure I understand that.
I am about to run out the door to take kid to movie, but I take that comment as red flag, which leads me to think I am approaching the problem incorrectly and will give a better explanation later today or tommorrow, and if you have the time hopefully I could get your or anyone else input on a basic overview how they might approach it.

TheMaster

  • Guest
Re: Jigging a block with Alignment parameter
« Reply #18 on: November 21, 2012, 08:59:08 PM »
Yes but too much automation wanted to use built in 'Insert' command.

Ummmm.  Not sure I understand that.
I am about to run out the door to take kid to movie, but I take that comment as red flag, which leads me to think I am approaching the problem incorrectly and will give a better explanation later today or tommorrow, and if you have the time hopefully I could get your or anyone else input on a basic overview how they might approach it.

Not a red flag, but I don't know what 'too much automation wanted' means exactly.

I can give you my input now, which is that it really doesn't pay to jump through as many hoops as would be necessary to support dynaic block alignment parameters in a jig, if the end result can be reached by scripting the INSERT command with little or no perceptible difference. If the underlying objective is to do it solely for the sake of the challenge, that's fine as long as whomever is paying for it also understands that.


Jeff H

  • Needs a day job
  • Posts: 6150
Re: Jigging a block with Alignment parameter
« Reply #19 on: November 26, 2012, 12:24:21 PM »
Basiclly what I got is inserting blocks so they are inserted on correct layer among other things where they want text to always stay horizontal. So I thought I would use a dymanic block with rotation parameter and action and add a user parameter to where they could set what they wanted the end result of text to be rotated at.
 
I guess another route would be to script insert command to get alignment parameter taken care of and once ended check if it contains user parameters and if so update it then, but it seems I keep hitting roadblocks getting it work from toolpalette and from Insert command so thought maybe roll my own where it called same command from tool palette.
 
P.S.
I do not feel near close enough to understanding API to charge anyone for my services, and just some automation for company I work for after regular hours. I leave that to you pros.

TheMaster

  • Guest
Re: Jigging a block with Alignment parameter
« Reply #20 on: November 26, 2012, 09:57:02 PM »
Basiclly what I got is inserting blocks so they are inserted on correct layer among other things where they want text to always stay horizontal. So I thought I would use a dymanic block with rotation parameter and action and add a user parameter to where they could set what they wanted the end result of text to be rotated at.
 
I guess another route would be to script insert command to get alignment parameter taken care of and once ended check if it contains user parameters and if so update it then, but it seems I keep hitting roadblocks getting it work from toolpalette and from Insert command so thought maybe roll my own where it called same command from tool palette.
 
P.S.
I do not feel near close enough to understanding API to charge anyone for my services, and just some automation for company I work for after regular hours. I leave that to you pros.

Another way to do that might be to script the INSERT command while a DrawableOverrule keeps the text heads-up. Of course, it could also keep the text heads-up whenever the block is edited in any way, if you wanted to do that as well.


Jeff H

  • Needs a day job
  • Posts: 6150
Re: Jigging a block with Alignment parameter
« Reply #21 on: November 27, 2012, 12:15:26 AM »
Basiclly what I got is inserting blocks so they are inserted on correct layer among other things where they want text to always stay horizontal. So I thought I would use a dymanic block with rotation parameter and action and add a user parameter to where they could set what they wanted the end result of text to be rotated at.

I guess another route would be to script insert command to get alignment parameter taken care of and once ended check if it contains user parameters and if so update it then, but it seems I keep hitting roadblocks getting it work from toolpalette and from Insert command so thought maybe roll my own where it called same command from tool palette.

P.S.
I do not feel near close enough to understanding API to charge anyone for my services, and just some automation for company I work for after regular hours. I leave that to you pros.

Another way to do that might be to script the INSERT command while a DrawableOverrule keeps the text heads-up. Of course, it could also keep the text heads-up whenever the block is edited in any way, if you wanted to do that as well.
Thanks Tony,

That was how I intially tried but one functionality that I was trying to add was to run through drawings for project and creating a legend in a 2 column table with one column being the block and the other using the description.

The other downfall and I can be wrong was to make the text persistent once saved. Most of the time the drawings are sent to a client and once they receive them I do not care if the text does not rotate and do not want worry about them having the code, so I thought using attributes would be the best so if the client rotated a block they had to could manually set attribute rotation to 0.
So through adding event for BeginSave and setting the rotation was one way, but using attributes(and probably due to the way i was doing it) was the grip points remained at the position that they would normally be drawn, and I did not investigate far enough if I needed to set some flag or add a grip overrule to make match.

Also I thought adding by using a Xdata which if attached to AttributeDefinition will be added to the AttributeReference using 'INSERT' command, which I thought also would give me the ability to add additional rotation values to rotate to the UCS, so 0 would be horizontal or if they wanted the text to always be 90 then 90, etc...
Well inserting a block from a tool palette does attach xdata from a AttributeDefinition to a AttributeReference, and 'ATTSYNC' kills the Xdata also.

So I thought if I have write a command to jig from tool palette might as well do use it for regular insertion.
Since I can not find or do not know where to find documentation to get a decent explanation of the fundamental workings of the graphics engine and how or what goes on that effects how a entity is drawn I said the hell with it and just use a dynamic block.
So I thought well why not just handle the rotation for insertion through a jig and when transformed using a TransformOverrule.
As far as Dynamic properties in a TransformOverrule just checking if DynamicBlockReferencePropertyCollection == null throws an error but as long as I bail out if IsNewObject == true it seemed to work.
Of course when I think I am just getting close other issues will pop up where a total hack or complete new plan attack will be in store.