@Anonymous
Hi I am utilizing your move grip point method, which is genius by the way. What I cant figure out is how did you compensate for the block rotation? I am using this to align dynamic block "callouts" (Dynamic Mleaders) I use the following to get the move to location: (the position under the first callout (selectedReferenceCallOut)).
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 dviewangle = GetCurrentDviewAngle()
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.RotateBy(acBlockReference.Rotation, Vector3d.ZAxis, acBlockReference.Position).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.GeometricExtents.MinPoint.RotateBy(acBlockReference.Rotation, Vector3d.ZAxis, acBlockReference.Position).Y + 0.16 ' - acBlockReference.Rotation
Else
moveToPoint3dY = acAttributeReference.MTextAttribute.GeometricExtents.MinPoint.RotateBy(acBlockReference.Rotation, Vector3d.ZAxis, acBlockReference.Position).Y ' - acBlockReference.Rotation
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
And the following to move the the other callouts (selectedCallOutsToMove) to the above move to location... It would move the first one, commit it, and then use the GetMoveToPoint3d on the callout just committed and continue that for each selectedCallOutsToMove. (Iteration left out of code for now as I am just trying to get it to work on one for now.)
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()
Dim dviewangle = GetCurrentDviewAngle()
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 adjustedGripPointLocation = acGripDataCollection(1).GripPoint.RotateBy(acBlockReference.Rotation, Vector3d.ZAxis, acBlockReference.Position)
Dim newMoveToVectors = adjustedGripPointLocation.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
It works great when the block is not rotated. I used the Rotate by to compensate for the block rotation and it gets it close but to the exact position.
