Community
Civil 3D Customization
Welcome to Autodeskā€™s AutoCAD Civil 3D Forums. Share your knowledge, ask questions, and explore popular AutoCAD Civil 3D Customization topics.
cancel
Showing results forĀ 
ShowĀ Ā onlyĀ  | Search instead forĀ 
Did you mean:Ā 

Move Multiple Cogo Point Labels with Jig

5 REPLIES 5
Reply
Message 1 of 6
d_prontnicki
861 Views, 5 Replies

Move Multiple Cogo Point Labels with Jig

Hi,

I am trying to update a program I found to incorporate a Jig so the user can see what is happening. I am having some trouble getting it work correctly and was wondering if someone could help. The program allows a user to select a cogopoint or multiple and move the label, not the point, to a new location. As it stands without the jig it works. (Test 1) But you can not really see where you are moving it. Hence the Jig. I have only worked with Jigs twice before and that was for placing an object at a point. Not selecting a base point and second point. I think I need a DrawJig over an EntityJig. I have been playing with both with no luck. 

 

Test 1 is the found program updated to use with selection points vs the typed values in the found routine.

Test 4 is a really nice Jig for selecting multiple Entities I found and works great.

 

I have been playing with this for a while now and cant figure out to incorporate the two. 

 

Any help would be greatly appreciated.

 

Test 1:

Public Class test1

    <CommandMethod("test1")>
    Public Sub PointLabelMove()

        'Get the current document and editor
        Dim acCurDb As Database = Active.Database
        Dim acDocEd As Editor = Active.Editor
        Dim acDoc As Document = Active.Document

        Try

            'Start cogo point selection prompt option
            Dim cogopointPrompt As PromptSelectionOptions = New PromptSelectionOptions
            cogopointPrompt.MessageForAdding = vbLf & "Select Cogo Points to move labels: "

            'Set cogo point selection result
            Dim selectedCogoPoints As PromptSelectionResult = acDocEd.GetSelection(cogopointPrompt)

            'If selection is a cogo point
            If selectedCogoPoints.Status <> PromptStatus.OK Then Return

            'Set variables for prompt point options and results
            Dim pPtRes As PromptPointResult
            Dim pPtOpts As PromptPointOptions = New PromptPointOptions("")

            'Prompt for start point
            pPtOpts.Message = vbLf & "Specify base point: "
            pPtRes = acDoc.Editor.GetPoint(pPtOpts)
            Dim ptStart As Point3d = pPtRes.Value

            'Convert 3d point to 2d
            ptStart.Converttopoint2d

            'Get x and y values for start
            Dim ptStartX = ptStart.X
            Dim ptStartY = ptStart.Y

            'Exit if cancels command
            If pPtRes.Status = PromptStatus.Cancel Then Exit Sub

            'Prompt for end point
            pPtOpts.Message = vbLf & "Specify second point: "
            pPtOpts.UseBasePoint = True
            pPtOpts.BasePoint = ptStart
            pPtRes = acDoc.Editor.GetPoint(pPtOpts)
            Dim ptEnd As Point3d = pPtRes.Value

            'Convert 3d point to 2d
            ptEnd.Converttopoint2d

            'Get x and y values for end
            Dim ptEndX = ptEnd.X
            Dim ptEndY = ptEnd.Y

            'Exit if cancels command
            If pPtRes.Status = PromptStatus.Cancel Then Exit Sub

            'Start the transaction
            Using acTrans As Transaction = acCurDb.TransactionManager.StartTransaction()

                'If selection is not less then 0
                If selectedCogoPoints.Value.Count > 0 Then

                    For Each selectedCogoPoint As SelectedObject In selectedCogoPoints.Value

                        'Get cogo point reference objectid
                        Dim selectedCogoPointId As ObjectId = selectedCogoPoint.ObjectId
                        Dim selCogoPoint As CogoPoint = acTrans.GetObject(selectedCogoPointId, 1)

                        'Get cogo point label location
                        Dim cogoPointLabelY As Double = selCogoPoint.LabelLocation.Y + ptEndY - ptStartY
                        Dim cogoPointLabelX As Double = selCogoPoint.LabelLocation.X + ptEndX - ptStartX

                        'Set the new cogo point label location
                        Dim pointd As Point3d = New Point3d(selCogoPoint.Location.X, selCogoPoint.Location.Y, 0)
                        selCogoPoint.LabelLocation = New Point3d(cogoPointLabelX, cogoPointLabelY, 0)

                    Next

                End If

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

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

            End Using

        Catch ex As Exception

            'To Do...

        End Try

    End Sub

End Class

Test 4:

Public Class test4

    <CommandMethod("test4", CommandFlags.UsePickSet)>
    Public Sub Test()

        Dim doc = Application.DocumentManager.MdiActiveDocument
        Dim db = doc.Database
        Dim ed = doc.Editor

        Dim selection = ed.GetSelection()

        If selection.Status <> PromptStatus.OK Then Return

        Dim ptResult = ed.GetPoint(vbLf & "Base point: ")

        If ptResult.Status <> PromptStatus.OK Then Return

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

            Dim entities As Autodesk.AutoCAD.DatabaseServices.Entity() = New Autodesk.AutoCAD.DatabaseServices.Entity(selection.Value.Count - 1) {}

            For i As Integer = 0 To selection.Value.Count - 1

                entities(i) = CType(tr.GetObject(selection.Value(i).ObjectId, OpenMode.ForRead), Autodesk.AutoCAD.DatabaseServices.Entity)

            Next

            Dim jig = New MoveJig(entities, ptResult.Value.TransformBy(ed.CurrentUserCoordinateSystem))
            Dim result = ed.Drag(jig)

            If result.Status = PromptStatus.OK Then

                For Each ent In entities

                    ent.UpgradeOpen()
                    ent.TransformBy(jig.Displacement)

                Next

            End If

            tr.Commit()

            ed.UpdateScreen()
            ed.Regen()

        End Using

    End Sub

End Class

Public Class MoveJig
    Inherits DrawJig

    Protected basePt As Point3d

    Protected entities As Autodesk.AutoCAD.DatabaseServices.Entity()

    Public Sub New(ByVal entities As Autodesk.AutoCAD.DatabaseServices.Entity(), ByVal basePt As Point3d)
        Me.entities = entities
        Me.basePt = basePt
    End Sub

    Public Property Displacement As Matrix3d

    Protected Overrides Function Sampler(ByVal prompts As JigPrompts) As SamplerStatus
        Dim options = New JigPromptPointOptions(vbLf & "Second point: ")
        options.UserInputControls = UserInputControls.Accept3dCoordinates
        options.BasePoint = basePt
        options.UseBasePoint = True
        options.Cursor = CursorType.RubberBand
        Dim result = prompts.AcquirePoint(options)
        If basePt.DistanceTo(result.Value) < Tolerance.[Global].EqualPoint Then Return SamplerStatus.NoChange
        Displacement = Matrix3d.Displacement(result.Value - basePt)
        Return SamplerStatus.OK
    End Function

    Protected Overrides Function WorldDraw(ByVal draw As WorldDraw) As Boolean
        Dim geo = draw.Geometry
        If geo IsNot Nothing Then
            geo.PushModelTransform(Displacement)
            For Each ent In entities
                geo.Draw(ent)
            Next

            geo.PopModelTransform()
        End If

        Return True
    End Function
End Class
5 REPLIES 5
Message 2 of 6
norman.yuan
in reply to: d_prontnicki

CogoPoint, as we see in AutoCAD editor, is an compound entity (one CogoPoint, derived from DBPoint, and one Label), and itself provides very flexible capability for user to drag its label around. However, I can hardly imagine a case where a user want to drag labels of multiple CogoPoints at the same time, with the same Vector of moving. Well, one may find such a need, but it is very unusual, I'd say.

 

Anyway, your Jig code, if it works at all, would let user drag the CogoPoint as an entity as whole, not the label, for sure, because the entities members in your Jig is the CogoPoint, not its label. 

 

Since you want is to Jig the Label, not the point, so you need to find the label as the entity and try it in the Jig (not sure if it works or not).

Norman Yuan

Drive CAD With Code

EESignature

Message 3 of 6
d_prontnicki
in reply to: norman.yuan

Hi Norman,

 

Thank you for the reply. This request stemmed from a post on this forum that a user found:

https://forums.autodesk.com/t5/civil-3d-forum/dragging-multiple-labels-at-once/td-p/5745926

 

This is actually very practical, for example, if I have a stretch of road with say 50 TC shots, instead of dragging 50 labels individually and trying to line them up to be on the same parallel I could use this and move them all at the same time. That's just one of many examples. The problem with the program as it stands, is it asks for an X and Y offset to be entered. The users say they never know what that is and it would be easier if a jig could be used.

 

As for selecting the label as an entity, that is where I am having trouble. I cant seem to get the label as an entity in and of its self.

 

The other idea I had was, if possible, was to pass the drag location to LabelLocation X and Y as a double like the original program. Just not sure how to do that. And on top of that the Jig I found uses a matrix not "point locations" X, Y. 

 

Thanks,

Dave

Message 4 of 6
norman.yuan
in reply to: d_prontnicki

Ah, I can see your need is validMan Happy

 

It should be not difficult to find labels of selected CogoPoints, and then try to jig them. Since I never thought doing it until now, I'd do some quick try first before I can offer useful opinions on this. I'll see if I can get something out in the coming weekend and post back.

Norman Yuan

Drive CAD With Code

EESignature

Message 5 of 6
d_prontnicki
in reply to: norman.yuan

Thank you very much, I really appreciate it!!
Message 6 of 6
norman.yuan
in reply to: d_prontnicki

OK, I gave it a try during the weekend and came out something.

Firstly, I previously have done some code to manipulate labels in Civil3D, but never done anything to CogoPoint's label. It turns out, CogoPoint label is different from other labels in Civil3D, in spite the similar looks: CogoPoint's label is part of CogoPoint, not a separate label entity that points a point entity with "FeatureId". So, the usual Jig approach does not work properly if we only want to move the label, but not the point itself.

 

So, I have to settle with different approach. Because these is plenty of code and descriptions, I decide to post the study at my blog, instead of here, to make it easier to read:

http://drive-cad-with-code.blogspot.ca/2018/04/move-civil3d-cogopoints-label-in-jig.html

 

 

Norman Yuan

Drive CAD With Code

EESignature

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

Post to forums  

Rail Community


Ā 

Autodesk Design & Make Report

Ā