Help with move command (Math) :)

David_Prontnicki
Collaborator
Collaborator

Help with move command (Math) :)

David_Prontnicki
Collaborator
Collaborator

Hi, I know I'm missing something simple. I have sub that moves a cogo point label, (this is not civil 3d related) and there is something funny about my pick point. When I select the base point and then the second point the label moves just fine except it is slightly off from my second pick point. I know it has to do with the base point of the label but I cant for the life of me figure out the correct math to compensate for it. There are two images attached showing my base point pick and second pick. In the second pick image, where the cross-hairs are is where I picked for placement. (I am picking the middle of the zero, and expect the middle of the zero to be at my second point.) Any help would be appreciated.

P.S. I have tried getting the vector from the label base point to first pick point and compensating that into the equation but that did work. (Most likely did it wrong)

 

<CommandMethod("mcptlbmov")>
    Public Sub CogoPointLabelMove()

        'Get the current document and editor
        Dim curDb As Database = Active.Database
        Dim docEd As Editor = Active.Editor

        Try

            'Create a typedvalue array to define the filter criteria
            Dim acTypValAr(0) As TypedValue
            acTypValAr.SetValue(New TypedValue(DxfCode.Start, "AECC_COGO_POINT"), 0)

            'Assign the filter criteria to a selectionfilter object
            Dim acSelFtr As New SelectionFilter(acTypValAr)

            'Start cogo point selection prompt option
            Dim promptSelectionOptions As New PromptSelectionOptions
            promptSelectionOptions.MessageForAdding = (vbLf & "Select COGO Points Labels to move: ")

            'Get prompt selection results
            Dim cogoPointPromptSelectionResult = docEd.GetSelection(promptSelectionOptions, acSelFtr)

            'Set selection set
            Dim cogoPointSelectionSet As SelectionSet = cogoPointPromptSelectionResult.Value

            'If selection are cogo points
            If cogoPointPromptSelectionResult.Status = PromptStatus.OK Then

                'Start base point prompt point option 
                Dim pointPromptOptions = New PromptPointOptions(vbLf & "Specify base point: ")
                Dim pointPromptResult = docEd.GetPoint(pointPromptOptions)

                'If pick point is valid
                If pointPromptResult.Status <> PromptStatus.OK Then

                    Return

                End If

                'Set value from point prompt result
                Dim firstSelectedPoint = pointPromptResult.Value

                'Start second point prompt point option
                pointPromptOptions.Message = vbLf & "Specify second point: "
                pointPromptOptions.UseBasePoint = True
                pointPromptOptions.BasePoint = firstSelectedPoint
                pointPromptResult = docEd.GetPoint(pointPromptOptions)

                'If pick point is valid
                If pointPromptResult.Status <> PromptStatus.OK Then

                    Return

                End If

                'Set value from point prompt result
                Dim secondSelectedPoint = pointPromptResult.Value

                'Get vector between fisrt and second selected 3d points
                Dim selectedVector As Vector3d = firstSelectedPoint.GetVectorTo(secondSelectedPoint)

                'Get x and y from vector as double
                Dim selectedVectorPointY As Double = selectedVector.Y
                Dim selectedVectorPointX As Double = selectedVector.X

                'Apply move to each selected cogo point
                For Each cogoPointSelectedObject In cogoPointSelectionSet

                    'Start the transaction
                    Using trans As Transaction = curDb.TransactionManager.StartTransaction()

                        'Set dbobject and open for write
                        Dim cogoPointDbOj As Autodesk.AutoCAD.DatabaseServices.DBObject = trans.GetObject(cogoPointSelectedObject.ObjectId, OpenMode.ForWrite)

                        'Set and cast point
                        Dim acCogoPoint As CogoPoint = TryCast(cogoPointDbOj, CogoPoint)

                        'Get cogo point label location and add vector
                        Dim newCogoPointLabelY As Double = acCogoPoint.LabelLocation.Y + selectedVectorPointY
                        Dim newCogoPointLabelX As Double = acCogoPoint.LabelLocation.X + selectedVectorPointX

                        'Set the new cogo point label location
                        acCogoPoint.LabelLocation = New Point3d(newCogoPointLabelX, newCogoPointLabelY, 0)

                        'Save the changes and dispose of the transaction
                        trans.Commit()

                    End Using

                Next

            End If

            'Regen and update screen
            docEd.UpdateScreen()
            docEd.Regen()

        Catch ex As Exception

Base Point SelectedBase Point Selected      Where Cross-Hairs are is Second Point SelectedWhere Cross-Hairs are is Second Point Selected

0 Likes
Reply
489 Views
3 Replies
Replies (3)

_gile
Mentor
Mentor

Your code is related to Civil3d, CogoPoint, CogoPoint.LabelLocation are Civil objects.

 

Doing a little search on the web, you should have found this topic is about what you're looking for.

 

To "move" a point, simply add a displacement vector to the point.

Try something like this (not tested, I do not know Civil3d).

acCogoPoint.ResetLabelLocation()
acCogoPoint.LabelLocation += selectedVector

 



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes

David_Prontnicki
Collaborator
Collaborator

@_gile wrote:

Your code is related to Civil3d, CogoPoint, CogoPoint.LabelLocation are Civil objects.

 


Gile, All I meant was I thought the issue was related to my approach on moving not necessary it being a cogo point. I understand they are civil based. I will move this post to the civil side.

 


Doing a little search on the web, you should have found this topic is about what you're looking for.

 


I did see this link, adding the reset label makes no difference so i left it out.

 


To "move" a point, simply add a displacement vector to the point.

Try something like this (not tested, I do not know Civil3d).

acCogoPoint.ResetLabelLocation()
acCogoPoint.LabelLocation += selectedVector

 


Thank you for showing me how to shorten my code, I did not know I could simply pass the vector to the label location. I appreciate that. Unfortunately  it still does not fix the issue. 

 

I also noticed that this approach will not work. Even my original approach does not work. The issue is if you move the label again it does not go anywhere near where you clicked. Works for the first move but from then it does not. I believe this is because I am adding the vector. I need to do this differently. I am just not sure how.

 

If this was for a single point I would simply set the location to the second pick point like:

 

'Set and cast point
                        Dim acCogoPoint As CogoPoint = TryCast(cogoPointDbOj, CogoPoint)

                        acCogoPoint.ResetLabelLocation()
                        acCogoPoint.LabelLocation = secondSelectedPoint

                        'Save the changes and dispose of the transaction
                        trans.Commit()


 Since I am doing this for multiple points; I need to get the difference between the two pick point and apply that difference to each selected cogo point label. The problem is, how do you apply when there is a negative or positive (no left or right, up, or down). 

 

What is the best approach to move multiple labels based on a base point and a second point, to be able to utilize the pick point prompt with "rubber band"?

 

0 Likes

_gile
Mentor
Mentor

Geometrically speaking, displacing a point is done by adding a displacement vector to the point.

 

If this does not work with the CogoPoint.LabelLocation, this is due a specific behavior of this object and I cannot help you further.



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes