I am pretty new at .NET so please any advice would be very helpfull.
I have created this function that is to move all the attributes based on a startpt and a newpt. If the last argrument to the function is true, all attributes move the same amount in the x & y direction(this part is working fine). If the argument is false. I want the attributes to align with the x value of the first attribute. It works unless the user has set a UCS. I need to align the attributes to the UCS not the WCS. Can't seem to figure out the right transformby to apply.
Public Sub MoveAttributes(ByVal Blockobj AsObjectId, ByVal stpnt AsPoint3d, ByVal endpt AsPoint3d, ByVal alignatt AsBoolean)
If Blockobj.IsNull ThenExit Sub
Dim attributeDistFactor AsDouble = 0.1371425
Dim xmove AsDouble = stpnt.X - endpt.X
Dim ymove AsDouble = stpnt.Y - endpt.Y
Dim basey AsDouble = 0
Dim basex AsDouble = 0
Dim newx AsDouble = 0
Dim newy AsDouble = 0
Dim acaddoc AsDocument = Application.DocumentManager.MdiActiveDocument
Dim ed AsEditor = acaddoc.Editor
Dim retList AsNewList(Ofattrefxy)
Using mytrans AsTransaction = acaddoc.TransactionManager.StartTransaction
Try
Dim myBRef AsBlockReference
myBRef = Blockobj.GetObject(
OpenMode.ForWrite)
Dim blockscale AsDouble = myBRef.ScaleFactors.X
If myBRef.AttributeCollection IsNothingThen
Else
Dim counter AsInteger = 0
ForEach myAttRefID AsObjectIdIn myBRef.AttributeCollection
Dim myAttRef AsAttributeReference = myAttRefID.GetObject(OpenMode.ForWrite)
Dim myRetAttRef AsNewattrefxy
myRetAttRef.attcoord = myAttRef.Position
If counter = 0 Then
basex = myRetAttRef.attcoord.X - xmove
newx = basex
basey = myRetAttRef.attcoord.Y - ymove
newy = basey
Else
If alignatt Then
newx = myRetAttRef.attcoord.X - xmove
newy = myRetAttRef.attcoord.Y - ymove
Else
Dim ucs AsMatrix3d = ed.CurrentUserCoordinateSystem.Inverse()
Dim basept AsPoint3d = NewPoint3d(0, 0, 0)
Dim normal AsVector3d = NewVector3d(0, 0, 1)
normal = normal.TransformBy(ucs)
Dim plane AsPlane = NewPlane(basept, normal)
Dim newpoint AsPoint3d = NewPoint3d(basex, basey - ((attributeDistFactor * blockscale) * counter), 0)
Dim adjPoint AsPoint3d = newpoint.TransformBy(ucs)
newx = adjPoint.X
newy = adjPoint.Y
EndIf
EndIf
Dim newpt AsPoint3d = NewPoint3d(newx, newy, 0)
myAttRef.Position = newpt
counter = counter + 1
Next
mytrans.Commit()
EndIf
Catch ex As Autodesk.AutoCAD.Runtime.Exception
ed.WriteMessage(
"A problem has occured because " + ex.Message)
Finally
mytrans.Dispose()
EndTry
EndUsing
EndSub
Solved! Go to Solution.
Solved by coralie.jacobi. Go to Solution.
I figured it out....I needed to take the insertion point of the first attribute, convert it to UCS coordinates, adjust the attribute location coordiantes, then convert it back to WCS.
It's amazing what a good night sleep will do!