.NET

Reply
Valued Contributor
cjacobi
Posts: 55
Registered: ‎11-12-2012
Message 1 of 2 (215 Views)
Accepted Solution

Modifying Attribute alignment with UCS

215 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

           

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

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!

Valued Contributor
cjacobi
Posts: 55
Registered: ‎11-12-2012
Message 2 of 2 (195 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!

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Are You Going To Be @ AU 2014? Feel free to drop by our AU topic post and share your plans, plug a class that you're teaching, or simply check out who else from the community might be in attendance. Ohh and don't forgot to stop by the Autodesk Help | Learn | Collaborate booths in the Exhibit Hall and meet our community team if you get a chance!