Valued Contributor
Posts: 54
Registered: ‎11-12-2012
Message 1 of 2 (187 Views)
Accepted Solution

Modifying Attribute alignment with UCS

187 Views, 1 Replies
02-27-2013 05:39 AM

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




Dim myBRef AsBlockReference

                myBRef = Blockobj.GetObject(



Dim blockscale AsDouble = myBRef.ScaleFactors.X


If myBRef.AttributeCollection IsNothingThen




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




If alignatt Then

                                newx = myRetAttRef.attcoord.X - xmove

                                newy = myRetAttRef.attcoord.Y - ymove




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






Dim newpt AsPoint3d = NewPoint3d(newx, newy, 0)

                        myAttRef.Position = newpt

                        counter = counter + 1







Catch ex As Autodesk.AutoCAD.Runtime.Exception


"A problem has occured because " + ex.Message)










Valued Contributor
Posts: 54
Registered: ‎11-12-2012
Message 2 of 2 (167 Views)

Re: Modifying Attribute alignment with UCS

02-27-2013 11:04 AM in reply to: cjacobi

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!

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community