Cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted

DrawingView - How replace ModelLink?

Genius
Genius

Hello everyone.

Is it possible to replace the ModelLink of a DrawingView in the DraftDocument environment?

For example:

 

I have a DrawingView linked to a file called bolt1.par and I want to modify it to bolt2.par, holding the XY position and the DrawingView size, in addition to maintaining orientation of the view of the drawing.

 

 

Is it possible?



==========================
Kabir Costa
Industrial Designer
kabircosta@gmail.com
2 REPLIES

Re: DrawingView - How replace ModelLink?

Valued Contributor
Valued Contributor

The following vb code might do what you need (you can probably refactor this to be smaller):

        Dim draftDoc = seApp.ActiveDocument
        Dim newFilePath As String = "YourNewFileName"
        Dim dvs As DrawingViews = draftDoc.ActiveSheet.DrawingViews()
        Dim dv As DrawingView = dvs.Item(1) 'Or your own way of selecting the View
        Dim ml2 As ModelLink = dv.ModelLink
        For i = 1 To draftDoc.ModelLinks.Count
            'draftDoc.ModelLinks
            Dim ml1 As ModelLink = draftDoc.ModelLinks.Item(i)
            If ml1.FileName = ml2.FileName Then
                draftDoc.ModelLinks.Item(i).ChangeSource(newFilePath)
            End If
        Next

If your entire draft just contains a single ModelLink, then the following will do:

draftDoc.ModelLinks.Item(1).ChangeSource(newFilePath)
________[Oo\____/oO]________

The truth is .... I am Dutch

C# - VS Ex 2015 - Solid Edge ST10 MP3 - TC11.4
Key-User, IT-student, no admin rights

Re: DrawingView - How replace ModelLink?

Genius
Genius

@JanWillem, The code you entered works.

 

In C # the code is:

static void changeSource(string newFileReplace)
        {
            // Variables
            Application application = null;
            Documents documents = null;
            DraftDocument draftDocument = null;

            ModelLink modelLink1 = null;
            ModelLink modelLink2 = null;

            DrawingViews drawingViews = null;
            DrawingView drawingView = null;

            try
            {
                // Start
                OleMessageFilter.Register();
                application = SolidEdgeUtils.Connect(true);
                documents = application.Documents;

                // Get active document
                draftDocument = application.ActiveDocument as DraftDocument;

                // Get DrawingViews
                drawingViews = draftDocument.ActiveSheet.DrawingViews;

                // Get DrawingView
                drawingView = drawingViews.Item(1);

                // Get ModelLink
                modelLink1 = drawingView.ModelLink as ModelLink;

                for (int i = 1; i <= draftDocument.ModelLinks.Count; i++)
                {
                    modelLink2 = draftDocument.ModelLinks.Item(i);
                    if (modelLink1 == modelLink2)
                    {
                        draftDocument.ModelLinks.Item(i).ChangeSource(newFileReplace);
                    }
                }
                application.StartCommand((SolidEdgeCommandConstants)
                    SolidEdgeConstants.DetailCommandConstants.DetailDrawingViewsUpdateViews);


            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
            finally
            {
                OleMessageFilter.Unregister();
            }
        }


==========================
Kabir Costa
Industrial Designer
kabircosta@gmail.com