If there are any AutoCAD programmers on here I could use your help.
I have a method that moves a grip point to a certain location via GetVectorTo (get from two points). It works great when the view is set normally. But when you have a dview twist it does not work correctly. I know this is due to the XY plane but for the life of me I cant figure out how to adjust for it. I have been playing with it for days now and I am stumped. I posted to the Autodesk forums a few days ago but have not received any replies.
How do I adjust the point coordinates for selectedReferenceCallOutPosition and acGripDataCollection(1).GripPoint OR adjust the vectors, newMoveToVectors, to take into account the dview twist?
Code:
Private Sub MoveSelectedCallOuts(ByVal selectedReferenceCallOut As ObjectId, ByVal selectedReferenceCallOutPosition As Point3d, ByVal selectedCallOutsToMove As SelectionSet)
Try
Using acDocumentLock As DocumentLock = Active.Document.LockDocument()
Using acTranaction As Transaction = Active.Database.TransactionManager.StartTransaction()
For Each selectedCallOut In selectedCallOutsToMove
If selectedCallOut.ObjectId <> selectedReferenceCallOut Then
Dim callOutEntity As Entity = CType(acTranaction.GetObject(selectedCallOut.ObjectId, OpenMode.ForWrite), Entity)
Dim acBlockReference As BlockReference = TryCast(callOutEntity, BlockReference)
Dim acGripDataCollection As New GripDataCollection()
Dim updateGrip As New GripDataCollection()
Dim currentViewUnitSize As Double = 0
Dim gripSize As Integer = 0
Dim currentViewVector3d As Vector3d = acCurrentDocument.Editor.GetCurrentView().ViewDirection
Dim bitFlags As GetGripPointsFlags = GetGripPointsFlags.GripPointsOnly
acBlockReference.GetGripPoints(acGripDataCollection, currentViewUnitSize, gripSize, currentViewVector3d, bitFlags)
updateGrip.Add(acGripDataCollection(1))
Dim newMoveToVectors = acGripDataCollection(1).GripPoint.GetVectorTo(selectedReferenceCallOutPosition)
acBlockReference.MoveGripPointsAt(updateGrip, newMoveToVectors, MoveGripPointsFlags.Polar)
End If
Next
acTranaction.Commit()
End Using
End Using
Catch ex As Exception
MessageServices.DisplayError("Error Moving Call Outs!", "Please contact the CADD Department for help.", ex)
End Try
End Sub
UPDATE:
I have found that it has nothing to do with the DVIEW angle, It has to do with the block being rotated. If the block is in a DVIEW twist but not rotated it works as it should. How do I account for the block rotation? I have been playing with Matrices and TransformBy but to no avail. Below is the function to get the move to point.
Code:
Private Function GetMoveToPoint3d(ByVal selectedReferenceCallOut As ObjectId) As Point3d
Dim moveToPoint3d As Point3d
Dim moveToPoint3dX As Double
Dim moveToPoint3dY As Double
Try
Using acDocumentLock As DocumentLock = Active.Document.LockDocument()
Using acTranaction As Transaction = Active.Database.TransactionManager.StartTransaction()
Dim acBlockReference As BlockReference = CType(acTranaction.GetObject(selectedReferenceCallOut, OpenMode.ForRead), BlockReference)
'------------------------- Get X Position -------------------------
Dim acGripDataCollection As New GripDataCollection()
Dim currentViewUnitSize As Double = 0
Dim gripSize As Integer = 0
Dim currentViewVector3d As Vector3d = acCurrentDocument.Editor.GetCurrentView().ViewDirection
Dim bitFlags As GetGripPointsFlags = GetGripPointsFlags.GripPointsOnly
acBlockReference.GetGripPoints(acGripDataCollection, currentViewUnitSize, gripSize, currentViewVector3d, bitFlags)
moveToPoint3dX = acGripDataCollection(1).GripPoint.X
'------------------------- Get Y Position -------------------------
For Each acAttributeOjectId As ObjectId In acBlockReference.AttributeCollection
Dim acAttributeReference = CType(acTranaction.GetObject(acAttributeOjectId, OpenMode.ForRead), AttributeReference)
If acAttributeReference.Tag = "INSTALL" Then
If acAttributeReference.MTextAttribute.Visible = False Then
moveToPoint3dY = acAttributeReference.MTextAttribute.Bounds.Value.MinPoint.Y + 0.16
Else
moveToPoint3dY = acAttributeReference.MTextAttribute.Bounds.Value.MinPoint.Y
End If
End If
Exit For
Next
moveToPoint3d = New Point3d(moveToPoint3dX, moveToPoint3dY, 0)
acTranaction.Commit()
End Using
End Using
Return moveToPoint3d
Catch ex As Exception
MessageServices.DisplayError("Error Reading Block!", "Could not extract point X and Y positions.", ex)
Return Nothing
End Try
End Function