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

Conversions and Transformations - Blog Article Part 2

Gears Honored Contributor Gears Honored Contributor
Gears Honored Contributor

Hello, Solid Edge developers,

 

Delighted to announce that Part 2 of the article series "Conversions and Transformations using the Solid Edge API" is now live:

 

https://community.plm.automation.siemens.com/t5/Solid-Edge-Blog/Conversions-and-Transformations-usin...

   

This part explains the conversion of sheet coordinates to view coordinates by developing a new macro:

"Zoom to Selected Objects"

 

   

CAT0_Teaser_Part2.png

  

This is the second of the 4 part series.

  

Regards,

Tushar Suradkar

www.CADVertex.com

www.SurfAndCode.IN

 

Join the Solid Edge User Group on FaceBook:

https://www.facebook.com/groups/solidedgeusers/

3 REPLIES 3

Re: Conversions and Transformations - Blog Article Part 2

Genius
Genius

Hi @Tushar ,

 

First of all Thanks for the Knowledge sharing with the Biginers.

 

Now come to the point.

In the Code, you consider selectset as "sSet",ok. Next, code need User input as selection of line, arc....etc.,ok.

Then this code shows the object in the selection set. here you showed as "oSel", I hope it's a spell mistake(you decleared as "sSet"), but I deleared as "oSel" only.

oSel.Item(1).Range(XMin, YMin, XMax, YMax)

In the above code how you got the range? for me After Item(1) showing some other strings.

I followed the same code while i'm practiceing. Hope I have added required references.

So, I'm using console application. Please find the below reference.

 

siemens.png

Can you Please tell, where I'm doing mistake.

 

Thanks & Regards

V.Sudheer

Re: Conversions and Transformations - Blog Article Part 2

Gears Honored Contributor Gears Honored Contributor
Gears Honored Contributor

Hi Sudheer,

  

The Range function from the article need not be included in the code.

It is a built-in method of 2D objects in Draft.

  

Here's the complete code that you can try copy-pasting in a console application with the required Solid Edge references added to the project.

Also add a reference to System.Windows.Forms for the MessageBox function, else you can change it to simply MsgBox.

  

 

Imports System.Runtime.InteropServices
Imports SolidEdgeFramework
Imports SolidEdgeFrameworkSupport
Imports System.Windows.Forms

Module Module1
    Dim oApp As SolidEdgeFramework.Application
    Dim oDoc As SolidEdgeDraft.DraftDocument
    Dim oSheet As SolidEdgeDraft.Sheet

    Dim oSheetWindow As SolidEdgeDraft.SheetWindow
    Dim XMin As Double = 0, YMin As Double = 0
    Dim XMax As Double = 0, YMax As Double = 0

    Dim XWin1 As Long, YWin1 As Long
    Dim XWin2 As Long, YWin2 As Long

    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"

    Sub Main()
        On Error Resume Next

        oApp = Marshal.GetActiveObject("SolidEdge.Application")
        'If oApp Is Nothing Then
            'MessageBox.Show("Solid Edge should be running.", sCaption, MessageBoxButtons.OK, MessageBoxIcon.Information)
            'End
        'End If

        'If oApp.ActiveDocumentType <> SolidEdgeFramework.DocumentTypeConstants.igDraftDocument Then
            'MessageBox.Show("Works in Draft only.", sCaption, MessageBoxButtons.OK, MessageBoxIcon.Information)
            'End
        'End If

        oDoc = oApp.ActiveDocument
        oSheet = oDoc.ActiveSheet

        Dim oSel As SelectSet = Nothing
        oSel = oDoc.SelectSet

        If oSel.Count = 0 Then
            MessageBox.Show("Nothing selected.", sCaption, MessageBoxButtons.OK, MessageBoxIcon.Information)
            End
        End If

        oSel.Item(1).Range(XMin, YMin, XMax, YMax)

        For i = 1 To oSel.Count
            oSel.Item(i).Range(X1, Y1, X2, Y2)
            If X1 < XMin Then
                XMin = X1
            End If

            If Y1 < YMin Then
                YMin = Y1
            End If

            If X2 > XMax Then
                XMax = X1
            End If

            If Y2 > YMax Then
                YMax = Y2
            End If
        Next

        oSheetWindow = oApp.ActiveWindow

        oSheetWindow.ModelToWindow(XMin, YMin, XWin1, YWin1)
        oSheetWindow.ModelToWindow(XMax, YMax, XWin2, YWin2)

'Draw a diagonal line to visualize the window corner points 'Dim seLines2D As Lines2d = oSheet.Lines2d 'seLines2D.AddBy2Points(XMin, YMin, XMax, YMax) If XWin1 = XWin2 Then XWin2 *= 1.1 End If If YWin1 = YWin2 Then YWin2 *= 1.1 End If oSheetWindow.ZoomArea(XWin1, YWin1, XWin2, YWin2) End Sub End Module

Hope this helps.

Kindly let me know.

 

Regards,

Tushar

 

Re: Conversions and Transformations - Blog Article Part 2

Genius
Genius

Hi @Tushar,

 

Yah, it is working fine. Thanks for the Details.

 

Regards

V.Sudheer