Place Textbox in drawingview sketch on mouseposition

Place Textbox in drawingview sketch on mouseposition

Anonymous
Not applicable
573 Views
3 Replies
Message 1 of 4

Place Textbox in drawingview sketch on mouseposition

Anonymous
Not applicable

Hi,

 

'm trying to place a textbox in a drawingview sketch on the mouseposition.

 

The problem is that the position of the textbox seems to be at the center of the drawingview and not on the mouseposition.

 

What's wrong?

 

 

VB.Net Code:

        Private Sub mobjDrawNumbersFactoryCmd_OnExecute(Context As NameValueMap) Handles mobjDrawNumbersFactoryCmd.OnExecute
StartAgain:
            'get startnumber
            Dim answ As String = InputBox("Startnumber: ",, "1")
            Dim number As Integer

            Try
                number = CInt(answ)
            Catch ex As Exception
                m_inventorApplication.CommandManager.PromptMessage(answ & " is not a number!", MsgBoxStyle.OkOnly + MsgBoxStyle.Exclamation, "Waarschuwing!", MsgBoxResult.Ok)
                GoTo StartAgain
            End Try

            'get drawingdocument
            Dim oDrawDoc As Inventor.DrawingDocument = m_inventorApplication.ActiveDocument
            'get active sheet
            Dim oSheet As Inventor.Sheet = oDrawDoc.ActiveSheet

            Dim insertionpoint3D As Inventor.Point = Nothing
            Dim oSketch As Inventor.Sketch = Nothing
            Dim selectedDrawingView As DrawingView = Nothing

            'check in which drawingview the numbers got to be placed
            For Each drawingView As DrawingView In oSheet.DrawingViews
                Dim pointCenter As Point2d = drawingView.Position
                Dim point1 As Point2d = m_inventorApplication.TransientGeometry.CreatePoint2d((pointCenter.X - drawingView.Width / 2), (pointCenter.Y - drawingView.Height / 2))
                Dim point2 As Point2d = m_inventorApplication.TransientGeometry.CreatePoint2d((point1.X + drawingView.Width), (point1.Y + drawingView.Height))
                'get insertionpoint first number
                Dim oSelect As New clsSelect
                insertionpoint3D = oSelect.Pick(Inventor.SelectionFilterEnum.kAllPointEntities, "Place number: 1")

                If insertionpoint3D.X >= point1.X _
                    And insertionpoint3D.Y >= point1.Y _
                    And insertionpoint3D.X <= point2.X _
                    And insertionpoint3D.Y <= point2.Y Then

                    selectedDrawingView = drawingView
                    Exit For
                End If
            Next

            'check if there is already a sketch with this name
            Dim sketchNumber As Int32 = 1
            Dim sketchName As String = "Numbers-" & sketchNumber

            If selectedDrawingView Is Nothing Then selectedDrawingView = oSheet.DrawingViews(1)

            For Each oSketch In selectedDrawingView.Sketches
                If oSketch.Name = sketchName Then
                    sketchNumber = sketchNumber + 1
                    sketchName = "Numbers-" & sketchNumber
                End If
            Next

            'add a new sketch in drawingview
            oSketch = selectedDrawingView.Sketches.Add()
            oSketch.Name = sketchName
            oSketch.Edit()

            Dim isStopped As Boolean

            'define a new textbox
            Dim aTextbox As Inventor.TextBox

            Do While isStopped = False
                m_inventorApplication.UserInterfaceManager.DoEvents()

                'check if user presses ESC
                Try
                    'define insertionpoint 2D
                    Dim insertionpoint2D As Inventor.Point2d = m_inventorApplication.TransientGeometry.CreatePoint2d(insertionpoint3D.X, insertionpoint3D.Y)
                    'draw textbox
                    aTextbox = oSketch.TextBoxes.AddFitted(insertionpoint2D, number)

                Catch ex As Exception
                    isStopped = True
                End Try

                number = number + 1

                'get next insertionpoint
                Dim oSelect As New clsSelect
                insertionpoint3D = oSelect.Pick(Inventor.SelectionFilterEnum.kAllPointEntities, "Place number: " & number)
            Loop

            'close sketchedit
            oSketch.ExitEdit()


        End Sub

 

0 Likes
Accepted solutions (1)
574 Views
3 Replies
Replies (3)
Message 2 of 4

chandra.shekar.g
Autodesk Support
Autodesk Support

Hi @Anonymous,

 

Instead of creating sketch to DrawingView Object, create sketch to Sheet Object. Actually, picked points with respect to Sheet not DrawingViews.

 

Or picked points need to interpolate from sheet level to drawing view as described in the following.

 

 

X = PickedPoint.X - DrawingView.Position.X 
Y = PickedPoint.Y - DrawingView.Position.YDim

oPt as Point2doPt = TransientGeometry.CreatePoint2d(X, Y)

oSketch.TextBoxes.AddFitted(oPt, "Some Text")

Please feel free to contact if there is any doubt.

 

If solves problem, click on "Accept as solution" / give a "Kudo".

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



Message 3 of 4

Anonymous
Not applicable

Hi Chandra,

 

thanks for your reply.

 

I've to put the sketch and the textbox on the drawingview level because if the user moves the drawingview the textboxes must move with them.

(If I put the sketch on sheet level and the user moves the drawingview the sketch doesn't move with them.)

 

So I tried your suggestion to interpolate the pick point from sheet level to drawingview level but with no result.

 

I altered my code with this:               (drawingViewCenter = drawingView.Position)

  

'Dim insertionpoint2D As Point2d = m_inventorApplication.TransientGeometry.CreatePoint2d(insertionpoint3D.X, insertionpoint3D.Y)
'interpolate insertionpoint from sheet level to drawingview level
Dim X As Double = insertionpoint3D.X - drawingViewCenter.X
Dim Y As Double = insertionpoint3D.Y - drawingViewCenter.Y
Dim insertionpoint2D As Point2d = m_inventorApplication.TransientGeometry.CreatePoint2d(X, Y)

'draw textbox
aTextbox = oSketch.TextBoxes.AddFitted(insertionpoint2D, number, aStyle)

 

'm I missing something?

 

kind regards.

 

Geert

Inventor PRO 2017

 

 

 

0 Likes
Message 4 of 4

Anonymous
Not applicable
Accepted solution

Hi Chandra,

 

I've just found it.

You set me just on the right track to say that the pick point lies on the sheet level.

 

The solution is:

 

Dim insertionpoint2D As Point2d = m_inventorApplication.TransientGeometry.CreatePoint2d(insertionpoint3D.X, insertionpoint3D.Y)
'interpolate insertionpoint from sheet level to drawingview level
insertionpoint2D = selectedDrawingView.SheetToDrawingViewSpace(insertionpoint2D)
'draw textbox
aTextbox = oSketch.TextBoxes.AddFitted(insertionpoint2D, number, aStyle)

'now it works fine.

 

Thanks again!

 

kind regards,

 

Geert

0 Likes