Cancel
Showing results for 
Search instead for 
Did you mean: 

Find out if a drawing view is selected using macro VBA

Creator
Creator

Hi @Tushar,

I found your post looking for a way to find out if a view was selected in my draft document, in this post you uploaded a macro that adds a callout showing the configuration name of the selected view, do you think you could help me by telling me which object did you use to get the view status?

thanks!

this the link where I found your macro 

https://community.plm.automation.siemens.com/t5/Solid-Edge-Forum/Callout-with-Configuration-Name/m-p...

6 REPLIES

Re: Find out if a drawing view is selected using macro VBA

Gears Phenom Gears Phenom
Gears Phenom

Hi @xRobin

 

Here's the module that handles the meaty part of the macro.

Would you be able to figure out what you seek ?

If not please let me know which part of the code you want to understand.

I'd be glad to help.

 

Imports System.Runtime.InteropServices
Imports System.Windows.Forms

Module Module1
    Dim oView As SolidEdgeDraft.DrawingView = Nothing
    Dim sCaption As String = "Config Callout"
    Dim oSheet As SolidEdgeDraft.Sheet = Nothing

    Sub Main()
        Dim oApp As SolidEdgeFramework.Application = Marshal.GetActiveObject("SolidEdge.Application")
        If oApp Is Nothing Then
            MessageBox.Show("Solid Edge Should be running.", sCaption, MessageBoxButtons.OK, MessageBoxIcon.Error)
            End
        End If

        If oApp.ActiveDocumentType <> SolidEdgeFramework.DocumentTypeConstants.igDraftDocument Then
            MessageBox.Show("A Draft document should be open.", sCaption, MessageBoxButtons.OK, MessageBoxIcon.Information)
            End
        End If

        Dim oDoc As SolidEdgeDraft.DraftDocument = oApp.ActiveDocument
        oSheet = oDoc.ActiveSheet

        Dim oSet As SolidEdgeFramework.SelectSet = oDoc.SelectSet
        If oSet.Count <> 1 Then
            MessageBox.Show("A single drawing view should be selected.", sCaption, MessageBoxButtons.OK, MessageBoxIcon.Information)
            End
        End If

        If Not TypeOf (oSet.Item(1)) Is SolidEdgeDraft.DrawingView Then
            MessageBox.Show("A single drawing view should be selected.", sCaption, MessageBoxButtons.OK, MessageBoxIcon.Information)
            End
        End If

        oView = oSet.Item(1)

        If oView.Configuration = String.Empty Then
            If MessageBox.Show("Configuration name for this view is <empty>." + vbCrLf + vbCrLf + "Add balloon ?", sCaption, MessageBoxButtons.YesNo, MessageBoxIcon.Question) = DialogResult.Yes Then
                AddBalloon()
            End If
        Else
            AddBalloon()
        End If
    End Sub

    Private Sub AddBalloon()
        Dim dXMin As Double = 0, dYMin As Double = 0, dXMax As Double = 0, dYMax As Double = 0
        Dim dXCen As Double = 0, dYCen As Double = 0

        oView.Range(dXMin, dYMin, dXMax, dYMax)

        Dim oBalloons As SolidEdgeFrameworkSupport.Balloons = oSheet.Balloons
        Dim oBall As SolidEdgeFrameworkSupport.Balloon = Nothing
        oBall = oBalloons.Add(dXMax, dYMax, 0)
        oBall.BalloonText = oView.Configuration

        If MessageBox.Show("Add leader to balloon ?" + vbCrLf + vbCrLf + "Free macro by:" + vbCrLf + "www.CADVertex.com", sCaption, MessageBoxButtons.YesNo, MessageBoxIcon.Question) = DialogResult.Yes Then
            oBall.Leader = True
        End If

    End Sub
End Module

Is this related to your other post for gathering view info and writing to title block?

Tell me your requirements, I can help you with it.

 

Re: Find out if a drawing view is selected using macro VBA

Creator
Creator

Thanks Tushar!

I will give a try at the end of the day, I'll share my results to get your opinion.

 

Thanks again

 

Re: Find out if a drawing view is selected using macro VBA

Creator
Creator

Hi @Tushar,

I'm tryin to migrate your code into VBA (im a beginner by the way), I was able to view and manipulate some labels and callouts in my Solid Edge Drawing but I couldn't get the view coordinates to add a new item, could you explaind me how to use the "range" function in VBA? you may want to take a look at my code and see how lost I am hehe

Thanks! 

Re: Find out if a drawing view is selected using macro VBA

Gears Phenom Gears Phenom
Gears Phenom

What problem are you facing with using the Range function ?

Note that it should be preceeded by Call when used in VBA:

 

Call objSEdgeView.Range dXMin, dYMin, dXMax, dYMax

 

and also note - no (brackets) since the function does not return a value.

 

dXMain,... etc will be assigned values after the function call since they are ByRef arguments

What else do you want to know ?

 

Also, use the Insert Code option instead of attaching files:

 

IC.png

Re: Find out if a drawing view is selected using macro VBA

Creator
Creator
Hi @Tushar,
Is there a way to create a connection between the Balloon and the view? I'm trying to access the view custom properties adding something like "%{Designer/CP|GP}" (in a multiple pages/parts document) in the balloon text but it wont work until the ballon is conected to the view

Re: Find out if a drawing view is selected using macro VBA

Gears Phenom Gears Phenom
Gears Phenom

Hi @xRobin

   

I'd request to close this discussion by marking all messages that were helpful as 'Accepted Solutions"

Then Start a new discussion on the Developer Forum about connecting the balloon to a view.

I have figured out a solution, and will provide it in the new message.

Thanks.

     

Best,

Tushar