AnsweredAssumed Answered

Block insertion points and transforms

Question asked by Todd Carpenter on Jan 18, 2019
Latest reply on Jan 18, 2019 by Todd Carpenter

First, apologies for the long description, I thought I understood transforms, but this latest issue is really giving me fits.

 

In a drawing, I'm inserting blocks (which are nothing more than a sketch point) into a drawing. The intent is to use as locators for dimensions. I finally figured out, the blocks positions are reported relative the view they are closest to (I haven't verified this with multiple views), but what I keep failing at, miserably so, is converting the block locations to drawing or sketch locations. Here's my starting point:

 

 

So the idea is, RD1 gets put in the same location as BLK4, RD2 to BLK5 and RD3 to BLK6. After running this bit of code:

 

// Get dimension information.
//
AnnObj = swSelMgr.GetSelectedObject6(1, -1);
DispDim = (DisplayDimension)AnnObj;
swAnn = (Annotation)DispDim.GetAnnotation();
oldPos = (double[])swAnn.GetPosition(); // relative to sheet origin.

//swMathPt = (MathPoint)swMathUtil.CreatePoint(swBlkIns.InstancePosition);

swModelToSketchXForm = (MathTransform)swSketch.ModelToSketchTransform;
swMathPt = (MathPoint)swMathPt.MultiplyTransform(swModelToSketchXForm);
//swDrawingToViewXForm = (MathTransform)DrawingToViewTransform(swView);
//swMathPt = (MathPoint)swMathPt.MultiplyTransform(swDrawingToViewXForm);
//swMathPt = (MathPoint)swMathPt.MultiplyTransform(swModelToSketchXForm);


double[] org = (double[])swView.Position; // relative to sheet origin.
NewX = ((double[])swMathPt.ArrayData)[0];
NewY = ((double[])swMathPt.ArrayData)[1];


//NewX = pointArray[0] * (1000 / 25.4);
//NewY = pointArray[1] * (1000 / 25.4);


swAnn.SetPosition2(NewX, NewY, 0);

 

I wind up here way off in outer space:

 

 

If I change to code to use the inverse, I get a bit closer:

 

// Get dimension information.
//
AnnObj = swSelMgr.GetSelectedObject6(1, -1);
DispDim = (DisplayDimension)AnnObj;
swAnn = (Annotation)DispDim.GetAnnotation();
oldPos = (double[])swAnn.GetPosition(); // relative to sheet origin.

//swMathPt = (MathPoint)swMathUtil.CreatePoint(swBlkIns.InstancePosition);

swModelToSketchXForm = (MathTransform)swSketch.ModelToSketchTransform;
swMathPt = (MathPoint)swMathPt.MultiplyTransform(swModelToSketchXForm.Inverse());
//swDrawingToViewXForm = (MathTransform)DrawingToViewTransform(swView);
//swMathPt = (MathPoint)swMathPt.MultiplyTransform(swDrawingToViewXForm);
//swMathPt = (MathPoint)swMathPt.MultiplyTransform(swModelToSketchXForm);


double[] org = (double[])swView.Position; // relative to sheet origin.
NewX = ((double[])swMathPt.ArrayData)[0];
NewY = ((double[])swMathPt.ArrayData)[1];


//NewX = pointArray[0] * (1000 / 25.4);
//NewY = pointArray[1] * (1000 / 25.4);


swAnn.SetPosition2(NewX, NewY, 0);

 

I wind up here:

 

Close, but no cigar.

 

What am I missing? Does InstancePosition return a location based on the model or the view? The documentation doesn't specify (but I'm guessing it would be different depending on depending on if they are model blocks or drawing blocks). Are model and view coordinate systems the same - I thought they were different? I have tried using the model to view to sketch method and wound up in outer space just like the second image.

 

Thanks for any input.

Outcomes