Friday 20 February 2015

Making of Zoom To Selection Part2

...continued from part1

In the Module1, declare variables for Solid Edge, the Draft Document, Sheet and the Sheet Window as below:

11

Some of the other variables are:

12

The XMin, YMin, XMax and YMax variables are for storing the coordinates of the selected object's range in sheet coordinates. These need to be transformed to Window or Screen coordinates which are stored in XWin1, YWin1, XWin2 and YWin2.

X1, Y1, X2, Y2 are temporary variables.

Inside the Sub Main, some rudimentary checks are done to ensure Solid Edge is running and that a Draft document is currently active.

15

Note how a message box can still be displayed in a Console application by using the Imports System.Windows.Forms statement at the top of the code window.

If indeed there is a Draft document open, it is stored in oDoc and the current i.e .Active sheet into oSheet.

17

oSel is a selection set which holds all currently selected items in the sheet. Even if no object is selected, the selection set still exists with a count of 0.

The selection set is similar to the Documents collection which also exists with a count of 0 when no document if open.

Continued to Part 3...


Index of all Solid Edge Tips, Tutorials and Videos...


3 comments:

  1. Hello, I'm trying to reproduce this. But I always get the message ''nothing selected''. I'm stuck pretty at the beginning. Of course program cannot work like that

    ReplyDelete
  2. Please share your code, what you have written so far.
    Also, I believe you have selected something in Solid Edge to zoom to.

    ReplyDelete
  3. I have a draft open in SE which I try to zoom.

    First, I've put it in a public sub, since I want to integrate it in an app which is doing other things.

    I have declare all the variables in the Public Class. I've changed oDoc to oDraft because oDoc is already used elsewhere

    Public Class Form1
    Dim oApp As SolidEdgeFramework.Application = Nothing
    Dim oDraft As SolidEdgeDraft.DraftDocument = Nothing
    Dim oSheet As SolidEdgeDraft.Sheet = Nothing
    Dim oSheetWindow As SolidEdgeDraft.SheetWindow = Nothing
    Dim XMin As Double = 0, YMin As Double = 0
    Dim XMax As Double = 0, YMax As Double = 0
    Dim XWin1 As Double = 0, YWin1 As Double = 0
    Dim XWin2 As Double = 0, YWin2 As Double = 0
    Dim X1 As Double = 0, Y1 As Double = 0
    Dim X2 As Double = 0, Y2 As Double = 0
    Dim sCaption As String = "Zoom to Selection"
    Dim Rangecoords As List(Of Double) = New List(Of Double)
    Dim LLx As Double = 0
    Dim LLy As Double = 0
    Dim URx As Double = 0
    Dim URy As Double = 0
    ' Then my Private Sub is coming
    Private Sub Zoom to sheet()
    oApp = Marshal.GetActiveObject("SolidEdge.Application")
    oDraft = oApp.ActiveDocument

    oSheet = oDraft.ActiveSheet
    Dim oSel As SelectSet = Nothing
    oSel = oDraft.SelectSet
    If oSel.Count = 0 Then
    MessageBox.Show("Nothing selected")
    End If
    GetseedRange(oSel, Rangecoords)
    End Sub

    ReplyDelete