Solved! Go to solution

Modifing caption of selected draft view with

I am just starting out playing with, and I am trying to make a program that will modify the caption of the current selected view(s)


Imports SolidEdgeFramework
Imports System.Runtime.InteropServices

Class MainWindow

    Private Sub Check_Click(sender As Object, e As RoutedEventArgs) Handles Check.Click

        Dim objApplication As SolidEdgeFramework.Application = Nothing
        Dim objDraft As SolidEdgeDraft.DraftDocument = Nothing
        Dim objSheet As SolidEdgeDraft.Sheet = Nothing
        Dim objModelLinks As SolidEdgeDraft.ModelLinks = Nothing
        Dim objDrawingViews As SolidEdgeDraft.DrawingViews = Nothing
        Dim objDrawingView As SolidEdgeDraft.DrawingView = Nothing

        ' Connect to a running instance of Solid Edge
        objApplication = Marshal.GetActiveObject("SolidEdge.Application")

        ' Get a reference to the documents collection
        objDraft = objApplication.ActiveDocument

        ' Get a reference to the active sheet
        objSheet = objDraft.ActiveSheet

        ' Get a reference to the model links collection
        objModelLinks = objDraft.ModelLinks

        ' Get a reference to the drawing views collection
        objDrawingViews = objSheet.DrawingViews

        ' Assign a caption
        objDrawingViews.CaptionDefinitionTextPrimary = "FRONT VIEW"

        ' Ensure caption is displayed
        objDrawingViews.DisplayCaption = True

    End Sub
End Class

I have tried copying and modifying code from a few different sources but they all use different syntax. Some use the "GetActiveObject" differently, or set up the dims completly differently and I'm not sure where the root cause of the issue it. In the code above I am getting an error with "CaptionDefinitionTextPrimary". I tried playing around with .selectset but that didn't seem to work.


Any help you could give or good references to look at would be great.


Accepted by topic author tfw1401
‎02-24-2016 06:05 PM

Re: Modifing caption of selected draft view with

SolidEdgeDraft.DrawingViews contains a collection of all the drawing views on the sheet, not the selected drawing views, as you require.


Also, you cannot set the properties of each drawing view by trying to use a drawing view property against the drawing views collection. They're two different types of object, with their own methods and properties. That's why you're getting an error.


To put this more simply, forget the select views requirement for a minute. This would have worked...



        'Iterate each drawing view in the drawing views collection
        For Each objDrawingView In objDrawingViews
            ' Assign a caption
            objDrawingViews.CaptionDefinitionTextPrimary = "FRONT VIEW"
            ' Ensure caption is displayed
            objDrawingViews.DisplayCaption = True


However, as you only want to set the caption for selected drawuing views, you have to do something like this...


        ' Get the currently selected Solid Edge entities
        Dim objSelectSet As SolidEdgeFramework.SelectSet = objApplication.ActiveSelectSet
        ' Iterate the selected Solid Edge entities, looking for selected drawing views
        For Each objSelectSetItem In objSelectSet
            ' Is this selected entity a drawing view
            objDrawingView = TryCast(objSelectSetItem, SolidEdgeDraft.DrawingView)
            If objDrawingView IsNot Nothing Then 'this must be a drawing view
                ' Set the drawing view caption
                objDrawingView.CaptionDefinitionTextPrimary = "FRONT VIEW"
                ' Display the drawing view caption
                objDrawingView.DisplayCaption = True
            End If