API, attach a note to a drawing view

Hi guys,

I'm currently making a macro to allow users to make dimenions ballooning on drawings. I mean, the user is able to select a dimension on a drawing and the macro create a note with a balloon format and a specif number. Next, I would like to group the note made with the dimension selected, but it seems I need to attach the note to the view of the dimension before.

I'm moving forward with my code, but I'm stopped because I can't find a way to get the drawing view of the selected dimension...
Also, I don't understand the difference between the entities "dimension" and "displaydimension"  available in API.

Please help me :-)

Below the function where I'm stopped (I'm french, so excuse me for the comments and the variable names in french) :

    Private Function ms_MouseLBtnDownNotify(ByVal X As Long, ByVal Y As Long, ByVal WParam As Long) As Long

   

        'si pas création de balloon en cours

            If PositionnementBalloonEnCours = False And ObjectEstPreSelectionné = True Then

               

                Set myNote = swModel.InsertNote(UserForm1.TextBoxNumero.value)

                Set MyDimension = MonObjectPreSelectionné

                If Not myNote Is Nothing Then

                   myNote.Angle = 0

                   boolstatus = myNote.SetBalloon(12, 0)

                   Set myAnnotation = myNote.GetAnnotation()

                   If Not myAnnotation Is Nothing Then

                    longstatus = myAnnotation.SetLeader3(swLeaderStyle_e.swNO_LEADER, 0, True, False, False, False)

                    boolstatus = myAnnotation.SetPosition(X, Y, Z)

                   End If

                End If

           

                UserForm1.TextBoxNumero.value = UserForm1.TextBoxNumero.value + 1

           

                PositionnementBalloonEnCours = True

               

          'si création de balloon en cours

            ElseIf PositionnementBalloonEnCours = True Then

               

                swModel.ClearSelection2 True

               

                'on attache le balloon à la vue (fonction attach to view)

                bool = myAnnotation.Select3(True, swSelData)

                bool = MyDimension.       'How to be able to select the dimension's drawing view before to attach the annotion to it ?

               

                bool = swModel.AttachAnnotation(swAttachAnnotationOption_View)

               

                'on attache le balloon à la dimension (fonction group)

               

               

                PositionnementBalloonEnCours = False

                Set myAnnotation = Nothing

               

            End If

           

    End Function

SolidworksApi macros
Answers 7
JB
JB 2017-04-02 Best Answer

Setting the "FocusLocked"  property of the view to "True" will force anything you create to belong to the view you are focused on.

Alternately, there are a lot of already available options for putting inspection balloons on dimensions.  Are you reinventing the wheel?  Some cost money, but what is the value of your time?  Or, here's just one (free) option:

DM
DM 2017-04-03

Thanks Josh for your quick reply.

Unfortunately, it seems the existing options and code don't fit my need. I'll would like to balloon whatever I want on the drawing (dimension, notes, geometric tolerance...).

The code I've made so far let the user click on the item he want, it create a note with a balloon format and it moves along with the mouse. With a  second click, the code freeze the note position. This way the user can balloon each item he wants on the drawing.

I don't know how to get the view of the object selected in the first time.

I'm trying to not reinvent the wheel :-), so I've looked over this forum to find some code examples with what I need. without success so far...

Thanks for your help.

PB
PB 2017-04-03

I've tried to find a simple way to find a dimension's view but came up short so far. A few things that might help:

  • A dimension is an annotation. Maybe you can get the view by using that.
  • You could go through all views and all dimensions to check if it is the same as the selected dimension. It's not very straightforward, but it'll probably work.
DM
DM 2017-04-03

Hi Peter,

I looked on annotation, dimension and displaydimension entities to see if there is a "GetView" or "GetDrawingview" procedure but it seems there is not :-(

I've been thinking about our 2nd proposal, but it was not really nice.. and time consuming I think. This is my backup solution.

I'll try to find the view through the model properties. I think I can get the model attached to the dimension selected and get the view of the model. I'll look in the API help if it's available...

But thanks a lot for your help.

JB
JB 2017-04-03

Dim swApp As SldWorks.SldWorks

Dim swDoc As SldWorks.ModelDoc2

Dim swSelMgr As SldWorks.SelectionMgr

Dim swDispDim As SldWorks.DisplayDimension

Dim swAnnot As SldWorks.Annotation

Dim swView As SldWorks.View

Sub main()

Set swApp = Application.SldWorks

Set swDoc = swApp.ActiveDoc

Set swSelMgr = swDoc.SelectionManager

Set swDispDim = swSelMgr.GetSelectedObject6(swSelMgr.GetSelectedObjectCount2(-1), -1)

Set swAnnot = swDispDim.GetAnnotation

Set swView = swAnnot.Owner

MsgBox swView.Name

End Sub

PB
PB 2017-04-04

Awesome, thanks

DM
DM 2017-04-04

Waouh, it was so simple... I like it.

Thank you very much.

It's the first time a write a question on this forum, I'm positively surprised of its efficiency.