I am working on a keynoting application and have run unto a confusing hurdle.
I am trying to search through a drawing for keynoting blocks which I can then build a schedule on the title block. Everything was going splendidly until a few days ago when only portions of the keynoting blocks were being found. I traced this back to how objects are selected through viewports. This was working as expected before.
I am doing this by selecting objects in paperspace then cycling through them. If a viewport is found it attempts to locate the area in modelspace which the viewport represents. I use the viewcenter along with viewheight & height for scale reference. It works perfectly in some drawings, however now I find that viewcenter is reporting back an incorrect location - somewhere down and left from where it should be. When I go back to some of the demo drawings I first tested the code on it still works correctly there.
Has anyone elese run into this issue?
I have too much code in this app to post here, so I am including only the portion in which the viewcenter lies to me.
ElseIf TypeOf thisEnt Is Viewport Then Dim myVP As Viewport = DirectCast(TransIn.GetObject(thisOID, OpenMode.ForRead), Viewport) 'If a window is provided make sure the viewport is within it... If Not windowPt1 = Nothing And Not windowPt2 = Nothing Then 'If all of the viewports four corners are outside the drawing area, don't include it If Tools.IsWithin(myVP.Bounds.Value.MinPoint, windowPt1, windowPt2) = False And _ Tools.IsWithin(myVP.Bounds.Value.MaxPoint, windowPt1, windowPt2) = False And _ Tools.IsWithin(New Point3d(myVP.Bounds.Value.MinPoint.X, myVP.Bounds.Value.MaxPoint.Y, 0), windowPt1, windowPt2) = False And _ Tools.IsWithin(New Point3d(myVP.Bounds.Value.MaxPoint.X, myVP.Bounds.Value.MinPoint.Y, 0), windowPt1, windowPt2) = False Then Continue For End If End If Dim scaleFactor As Double = myVP.ViewHeight / myVP.Height Dim myVPviewLL As New Point3d(myVP.ViewCenter.X - ((myVP.Width * scaleFactor) / 2), myVP.ViewCenter.Y - (myVP.ViewHeight / 2), 0) Dim myVPviewUR As New Point3d(myVP.ViewCenter.X + ((myVP.Width * scaleFactor) / 2), myVP.ViewCenter.Y + (myVP.ViewHeight / 2), 0) Dim myVPviewUL As New Point3d(myVP.ViewCenter.X - ((myVP.Width * scaleFactor) / 2), myVP.ViewCenter.Y + (myVP.ViewHeight / 2), 0) Dim myVPviewLR As New Point3d(myVP.ViewCenter.X + ((myVP.Width * scaleFactor) / 2), myVP.ViewCenter.Y - (myVP.ViewHeight / 2), 0) Dim myBT As BlockTable = DirectCast(TransIn.GetObject(HostApplicationServic
es.WorkingDatabase.BlockTableId, OpenMode.ForRead), BlockTable) Dim msBTR As BlockTableRecord = DirectCast(TransIn.GetObject(myBT(BlockTableRecord .ModelSpace), OpenMode.ForRead), BlockTableRecord) DeepDive(TransIn, msBTR, ProvideFeedbackIn, myVPviewLL, myVPviewUR) End If
Thank you for any help or direction anyone can give,
Is this specific to a drawing ?
Can you check the ViewCenter value using ArxDbg for that viewport ?
Also, does this post help ?
If you can please share a non-confidential sample drawing, I can take a look at it.
It's possible a custom ucs is in use where the origin has changed.
Matrix3d currentucsmatrix = ed.CurrentUserCoordinateSystem;
CoordinateSystem3d currentucs = currentucsmatrix.CoordinateSystem3d;
Vector2d currentucsvector = new Vector2d(currentucs.Xaxis.X, currentucs.Xaxis.Y);
if (currentucsvector.Angle != 0)
...reset ucs or ask user to do it
I am attaching two drawings - a good one and a bad one - named as such.
I ran into other strange issues with this & other drawings which were saveas of each other so it could be just related to this drawing. The other issues were related to layers which would show in MS, but not through a viewport (no, they were not frozen) and annotative objects which could not be displayed through the viewport under any circumstance. This led me to reconstruct the sheets from scratch.
I have also started new drawings where the problem exists. Maybe this traces back to a template?
Thank you for your help. Let me know if you find something in the drawings which I could plan for in my code or avoid in the future.
Sorry, I haven't figured out what is causing the offset in the ViewCenter values in the "Bad drawing.dwg" that you shared.
But if you switch to modelspace of the viewport and find the value using the "VIEWCTR" system variable, the values are right.
This can be done through code using Editor.SwitchToModelSpace() and then retrieve the VIEWCTR variable using Application.GetSystemVariable.
Hope this workaround helps.
For now I am going to avoid a workaround. Here's why...
This is not completely random, it appears to be drawing specific. Whether it is the result of a setting/variable or if it stems from a partially corrupt DWG is irrelevant. I just need to avoid these drawings.
I beleive this is only happening in drawings which were created from the same template. We have many, many templates so I have not yet narrowed it down to one. I feel as if once I weed out the offending drawings then we are good. In the meantime I have added a NoPlot 'X' to all viewport areas to give users a visual indicator of the area. If they don't match up the user will know.
Maybe one day I can turn this off, but it will make the command usable in the meantime.
Access a broad range of knowledge to help get the most out of your products and services.