.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Drag and scale a block depends on cursor location

4 REPLIES 4
SOLVED
Reply
Message 1 of 5
JanetDavidson
701 Views, 4 Replies

Drag and scale a block depends on cursor location

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.

 

4 REPLIES 4
Message 2 of 5

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

Cheers,

Stephen Preston
Autodesk Developer Network
Message 3 of 5

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

Janet.

 

Message 4 of 5

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.

 

Message 5 of 5
Hallex
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

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost