.NET

.NET

Reply
Distinguished Contributor
JanetDavidson
Posts: 139
Registered: ‎08-23-2011
Message 1 of 5 (311 Views)
Accepted Solution

Drag and scale a block depends on cursor location

311 Views, 4 Replies
12-23-2011 06:51 AM

Hello,

I simplify the question. Let's say I want to insert block and  if cursor is in negative coordinates  block should be  2 times bigger,

other wise the same scale. At the same time when I drag the block Jig it should become bigger as well, in negative coordination.

Don't know how to do that. Any light or help would be appreciated. My real problem is how to drag and change the scale at the same time based on cursor location. Right now I am using point monitor to check the location.

Cheers and Merry Christmas

Janet.

 

Board Manager
StephenPreston
Posts: 372
Registered: ‎05-22-2006
Message 2 of 5 (293 Views)

Re: Drag and scale a block depends on cursor location

12-23-2011 06:11 PM in reply to: JanetDavidson

Sounds like you need to implement a jig (e.g. DrawJig class).

Cheers,

Stephen Preston
Autodesk Developer Network
Distinguished Contributor
JanetDavidson
Posts: 139
Registered: ‎08-23-2011
Message 3 of 5 (288 Views)

Re: Drag and scale a block depends on cursor location

12-23-2011 09:26 PM in reply to: StephenPreston

Thanks Stephen,
I am going to try that. Happy Holidays.

Janet.

 

Distinguished Contributor
JanetDavidson
Posts: 139
Registered: ‎08-23-2011
Message 4 of 5 (271 Views)

Re: Drag and scale a block depends on cursor location

12-25-2011 01:42 PM in reply to: StephenPreston

Stephen , I tried and it worked. Thanks.

I was trying to just drag the block and in the mean time tried to use transfomby scale matrix3d and it was not the proper way.

Happy holidays.

 

*Expert Elite*
Hallex
Posts: 1,569
Registered: ‎10-08-2008
Message 5 of 5 (259 Views)

Re: Drag and scale a block depends on cursor location

12-26-2011 12:08 AM in reply to: JanetDavidson

Try another way on your machine

Tested on attributed blocks (non-dynamic)

Imports System.Text
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.EditorInput
Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.Geometry

Namespace VBTemplate

    Public Class BlockReactor
        Implements Autodesk.AutoCAD.Runtime.IExtensionApplication
        '
        Private dm As DocumentCollection
        Private doc As Document
        Private db As Database
        Private ed As Editor

        Private counter As Integer

        ''' <summary>
        ''' Initializing the class members
        ''' </summary>
        Public Sub MyInitialize()
            dm = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager
            doc = dm.MdiActiveDocument
            db = doc.Database
            ed = doc.Editor
            counter = 0

        End Sub

        ''' <summary>
        ''' Method that will start this DLL 
        ''' </summary>
        Public Sub Initialize() Implements Autodesk.AutoCAD.Runtime.IExtensionApplication.Initialize

            'Variables initializing 
            If doc Is Nothing Then
                MyInitialize()
            End If

            Dim filt As SelectionFilter = New SelectionFilter(New TypedValue() {New TypedValue(0, "insert"), New TypedValue(66, 1)})

            Dim psr As PromptSelectionResult = ed.SelectAll(filt)

            If psr.Status = PromptStatus.OK Then


                If psr.Value.Count > 0 Then

                    ed.WriteMessage(vbLf & "Selected attributed blocks: {0}", psr.Value.Count)

                    For Each item As ObjectId In psr.Value.GetObjectIds()


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


                            Dim obj As DBObject = tr.GetObject(item, OpenMode.ForRead)

                            If TypeOf obj Is BlockReference Then

                                Dim bref As BlockReference = CType(tr.GetObject(item, OpenMode.ForRead), BlockReference)

                                AddHandler bref.Modified, AddressOf obj_Modified

                            End If

                        End Using

                    Next

                End If
            End If

            AddHandler doc.BeginDocumentClose, AddressOf doc_BeginDocumentClose
            ed.WriteMessage(vbLf + "Changed attributes may be stored in Database on close drawing" _
                            + vbLf + "Initialization done")


        End Sub

        ''' <summary>
        ''' Method that will start on closing document 
        ''' </summary>
        Public Sub Terminate() Implements Autodesk.AutoCAD.Runtime.IExtensionApplication.Terminate
            Dim filt As SelectionFilter = New SelectionFilter(New TypedValue() {New TypedValue(0, "insert"), New TypedValue(66, 1)})
            Dim res As PromptSelectionResult = ed.SelectAll(filt)
            Dim eids As ObjectId() = res.Value.GetObjectIds()

            For Each eid As ObjectId In eids
                Dim obj As Entity = DirectCast(eid.GetObject(OpenMode.ForRead, False), Entity)
                If eid.ObjectClass = RXClass.GetClass(GetType(BlockReference)) Then
                    Dim bref As BlockReference = DirectCast(TryCast(obj, BlockReference), BlockReference)
                    RemoveHandler obj.Modified, AddressOf obj_Modified 'unregister event
                  
                End If
            Next
        
            RemoveHandler doc.BeginDocumentClose, AddressOf doc_BeginDocumentClose 'unregister event
   
        End Sub

        Friend Sub obj_Modified(ByVal sender As Object, ByVal e As EventArgs)

            Dim bref As BlockReference = Nothing

            bref = DirectCast(sender, BlockReference)

            Dim p As Point3d = bref.Position

            Dim hdl As String = bref.Handle.ToString

            doc.SendStringToExecute("_SCALE " & "(handent " & Chr(34) & hdl & Chr(34) & ")" & vbCr & Chr(32) & p.X.ToString + "," & p.Y.ToString & Chr(32) & "2.0" & vbCr, False, False, False)

            RemoveHandler bref.Modified, AddressOf obj_Modified

            counter += 1

        End Sub

        Private Sub doc_BeginDocumentClose(ByVal sender As Object, ByVal e As DocumentBeginCloseEventArgs)

            Autodesk.AutoCAD.ApplicationServices.Application.ShowAlertDialog("Modified : " & counter.ToString & " blocks")
        
        End Sub

End Class

End NameSpace

 

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Announcements
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 or visit the Installation and Licensing Forum to get help installing your software.