Author Topic: MLeader Jigs  (Read 2477 times)

0 Members and 1 Guest are viewing this topic.

TJK44

  • Guest
MLeader Jigs
« on: March 21, 2012, 08:56:37 AM »
I am trying to create my own custom mleaders that display a selected blocks attributes. To get started I was looking at Keans post Here http://through-the-interface.typepad.com/through_the_interface/2007/09/creating-a-mult.html and noticed that when changed to an isometric view it doesnt behave like the AutoCAD multileader. Here's two screenshots showing what happens. First is when in TOP view, second is when view was changed to an ISO view.

This has to do with the UCS changing, but is there a way to make the leader ignore a UCS change?

Preferably what I would like to happen is the leader is always drawn looking like the view is set to TOP, even if drawing the leader in an iso view.

Thanks,

Ted

TJK44

  • Guest
Re: MLeader Jigs
« Reply #1 on: March 21, 2012, 11:46:40 AM »
I think the answer I'm looking for is located in this example. I'll have to modify it and see if it works.

TJK44

  • Guest
Re: MLeader Jigs
« Reply #2 on: March 21, 2012, 06:20:19 PM »
Modifying the code half worked, now when the jig is drawn in ISO view it does not jig properly. But the leader text always looks like it is in top view. Here is what I have so far from modifying the code to work with an MLeader, not sure if it's 100% correct way to have modified it.

Code: [Select]
Private Shared Sub AddRegAppId(ByVal db As Database)

            Using trans As Transaction =
              db.TransactionManager.StartTransaction()

                ' First create our RegAppId (if it doesn't already exist)
                Dim appTbl As RegAppTable =
                  trans.GetObject(db.RegAppTableId, OpenMode.ForRead)

                If Not appTbl.Has(mXdataName) Then
                    Dim appTblRec As New RegAppTableRecord
                    appTbl.UpgradeOpen()
                    appTblRec.Name = mXdataName
                    appTbl.Add(appTblRec)
                    trans.AddNewlyCreatedDBObject(appTblRec, True)
                End If
                trans.Commit()
            End Using
        End Sub

        <CommandMethod("ActivateBillboardOverrule")>
        Public Shared Sub ActivateOverrule()

            'We only want to create our overrule instance once,
            ' so we check if it already exists before we create it
            ' (i.e. this may be the 2nd time we've run the command)
            If myOverrule Is Nothing Then
                'Instantiate our overrule class
                myOverrule = New BillboardAttributesOverrule
                'Register the overrule
                Overrule.AddOverrule(
                  RXClass.GetClass(GetType(MLeader)),
                  myOverrule, False)
            End If

            'Specify which Attributes will be overruled
            myOverrule.SetXDataFilter(mXdataName)
            'Make sure overruling is turned on so our overrule works
            Overrule.Overruling = True

        End Sub

And the class

Code: [Select]
Public Class BillboardAttributesOverrule
        Inherits DrawableOverrule

        'Returning False from WorldDraw tells AutoCAD this entity has
        '  viewport dependent graphics.
        Public Overrides Function WorldDraw(ByVal drawable As Drawable,
                                        ByVal wd As WorldDraw) As Boolean
            Return False
        End Function

        ' Called for each viewport so entity can draw itself differently
        '  depending on the view.
        Public Overrides Sub ViewportDraw(ByVal drawable As Drawable,
                                      ByVal vd As ViewportDraw)
            ' Cast drawable to type AttributeReference (we know it's an
            '  AttributeReference because that's the only class we register our
            '  overrule for).
            Dim ml As MLeader = drawable
            ' Calculate the transformation matrix to rotate from the
            '  attribute's current orientation to the view.
            ' (Thank you to Gile from TheSwamp for correcting this
            ' transformation to account for insertion on a UCS rotated
            ' w.r.t. the WCS and for non-left-aligned justification).
            Dim org As Point3d
            'If ml.TextLocation = AttachmentPoint.BaseLeft Or
            'mt.FlowDirection = AttachmentPoint.BaseAlign Or
            ' mt.FlowDirection = AttachmentPoint.BaseFit Then
            '    org = mt.Location
            'Else
            '    org = mt.Location
            'End If
            org = ml.TextLocation
            Dim viewMat As Matrix3d =
              Matrix3d.PlaneToWorld(New Plane(org, vd.Viewport.ViewDirection)) *
              Matrix3d.WorldToPlane(New Plane(org, ml.Normal)) *
            Matrix3d.Rotation(-ml.BlockRotation, ml.Normal, org)

            ' Apply the transformation
            vd.Geometry.PushModelTransform(viewMat)
            'Draw the 'per viewport geometry
            MyBase.ViewportDraw(drawable, vd)
            ' Remove the transformation - we don't want any other objects
            '  to draw themselves in the view plane.
            vd.Geometry.PopModelTransform()

        End Sub


        ' This function tells AutoCAD to dynamically update the
        '  AttributeReference during view transitions (e.g. 3DORBIT).
        ' Comment it out to improve graphic update performance.
        Public Overrides Function SetAttributes(
                              ByVal drawable As Drawable,
                              ByVal traits As DrawableTraits) As Integer
            Return MyBase.SetAttributes(drawable, traits) Or 2048
        End Function

    End Class

SamR

  • Mosquito
  • Posts: 15
Re: MLeader Jigs
« Reply #3 on: May 24, 2012, 05:46:28 PM »
I had a similar problem. Although I wasn't looking at an isometric view.
The jig inserted a leader that didn't quite behave the same way as one that was manually inserted.

To fix it, before exiting the jig I took the properties and erased the entity.
Then inserted the leader using the properties from the jig.
« Last Edit: May 24, 2012, 05:50:02 PM by SamR »