failed to build a connection between two objects in a drawing sheet

Creator
Creator

Hi, i want to build a concentric relationship between the projection of a hole and a circle so that the change of hole position can make the circle move automatically, but it failed. The main codes are:

    'build a connection rationship
    Private Sub BuildRelation()
        'get the circel in the drawing sheet

        Dim objCircle As Circle2d = GetCircle()
        If objCircle Is Nothing Then
           Return
        End If

 

        'get the projection of a hole in the drawing sheet

        Dim dvCircle As DVCircle2d = GetDVCirlce()
        If dvCircle Is Nothing Then
           Return
        End If

 

        'build a concentric relationship between the circel and the projection
        Dim objApp As SolidEdgeFramework.Application = GetObject(, "SolidEdge.Application")
        Dim objDftDoc As SolidEdgeDraft.DraftDocument = objApp.ActiveDocument
        Dim objSheet As Sheet = objDftDoc.ActiveSheet
        Dim objRelas As SolidEdgeFrameworkSupport.Relations2d = objSheet.Relations2d

        Dim objRela As SolidEdgeFrameworkSupport.Relation2d

 

        'after the following function is carried out, the circle does not move.
        'The expected result should be that the circle moved and was concentric with the           projection of the hole, which has been tested using the SolidEdge command menus manually
        objRela = objRelas.AddConcentric(dvCircle, objCircle)
    End Sub

 

    'get the circle object
    Private Function GetCircle() As Circle2d
       Dim objApp As SolidEdgeFramework.Application = GetObject(, "SolidEdge.Application")
       Dim objDftDoc As SolidEdgeDraft.DraftDocument = objApp.ActiveDocument
       Dim objSheet As Sheet = objDftDoc.ActiveSheet

       Dim objCircles As Circles2d
       

       objCircles = objSheet.Circles2d
       If objCircles.Count = 0 Then
          MessageBox.Show("Circles count is 0")
          Return Nothing
       End If

 

       Dim objCircle As Circle2d = objCircles.Item(1)
       If objCircle Is Nothing Then
          MessageBox.Show("circle is nothing")
          Return Nothing
       End If


       Return objCircle
    End Function

   

    'get the projection of the hole
    Private Function GetDVCirlce() As DVCircle2d
        Dim objApp As SolidEdgeFramework.Application = GetObject(, "SolidEdge.Application")
        Dim objDftDoc As SolidEdgeDraft.DraftDocument = objApp.ActiveDocument
        Dim objSheet As Sheet = objDftDoc.ActiveSheet

        Dim objView As SolidEdgeDraft.DrawingView = objSheet.DrawingViews.Item(1)
        If objView Is Nothing Then
            MessageBox.Show("drawing view is nothing")
            Return Nothing
        End If


        Dim objMM As SolidEdgeDraft.ModelMember = objView.ModelMembers.Item(1)
        If objMM Is Nothing Then
              MessageBox.Show("model member is nothing")
              Return Nothing
         End If

 

        Dim dvCircle As DVCircle2d = objMM.DVCircles2d.Item(1)
        If dvCircle Is Nothing Then
            MessageBox.Show("dvcircle is nothing")
            Return Nothing
        End If


        Return dvCircle
    End Function


     The solidedge version is ST3.

     

     Any help is greatly appreciated.

 

     billy

2 REPLIES

Re: failed to build a connection between two objects in a drawing sheet

Solution Partner Phenom Solution Partner Phenom
Solution Partner Phenom

Hello billy,

you are trying to connect two circles that do not share the same coordate system.

The dvCircle object is a child of the DrawingView and the objCircle is a child of the Sheet.

The DrawingView can be moved and scaled on the sheet, while the Sheet coordinate system starts in the left bottom corner and is always 1:1 scale.

To make the relation between the two circles get a reference object from the DrawingView:

Dim objRef As SolidEdgeFramework.Reference = Nothing
objView.GetReferenceToGraphicMember(dvCircle, objRef)

objRela = objRelas.AddConcentric(objRef, objCircle)

Remember that objCircle does not follow the scale of the view. To achieve this, use a circle object in the View Sheet:

objView.Sheet.Circles2d

Then use the relations in the DrawingView:

Dim objdvRelas As SolidEdgeFrameworkSupport.Relations2d = objView.Sheet.Relations2d
objdvRelas.AddConcentric(dvCircle, objCircleInView)

Remark: 

I would recommend to get the SolidEdge Application object only once in your program. Pass the objApp or objDftDoc object as parameter to your functions.

 

Regards JB

regards

JB
VS2015, SE ST10

Re: failed to build a connection between two objects in a drawing sheet

Creator
Creator

Hello JB. Thank you. According to your proposals, i have solved the problem.