Reply

How to get the Ranges of all Objects in a sheet, then extract values for comparison?

[ Edited ]

 

I'm looking for help on the Range property of Objects in a 2-D DFT file in SE20.

I need to be able to read the .range(XMinimum, YMinimum, XMaximum, YMaximum) double values

and then compare them with a programmatically defined box.

My end goal is to find all items located either fully or partially outside of the

drawing border and delete them before converting to DWG.

 

With help from Siemens support, I can use the SelectSet.AddAll, and loop thru each object, but am stuck on the range part.

 

So Questions are:

1. How to get the Range, without knowing specifically what object type it is?

   This will let me know the 2-d box that can hold the object.

2. How do I handle the double values of XMinimum, YMinimum, XMaximum, YMaximum?

   Can I assign these double values to a VB.Net datatype of RectangleF or each one to a variable?

   For example I want to compare:

   If XMinimum

      object.delete

   EndIf

   If YMinimum

      object.delete

   EndIf

 

Notes:

A. The Select Tool - Fence Filter is not exposed to the API. Otherwise this would easily solve my problem.

B. I have made an enhancement request : ER 6128649

   IR Description: API for selecting objects Inside/Overlapping/Outside fence without user interact

   Please add your name to this with Solid Edge Support to have it added.

C. I can't believe this simple function is not available by automation.

 

Thanks for any help.

- dave_illini

 

 

Posted by: Dave Bartimus
Post date: 4/2/2009 11:42:06 AM

2 REPLIES

RE: How to get the Ranges of all Objects in a sheet, then extract values for comparison?

[ Edited ]

 

OK,  I solved the big problem of getting the range values. 

I have 2 remaining logic problems.

1. How to handle items that do not have a Range? Such as Cutting Planes?

   And Unspecified error (Exception from HRESULT: 0x80004005(E_FAIL))?

2. How to handle projection views inside the border / generic rectangle that I want to keep,

   BUT the views they are projected from are outside of the border /generic rectangle.

   I need to delete everything outside, without deleting anything inside.

 

Here is my code I have so far that deletes anything partially or fully outside the sheet.

I'm Using Solid Edge V20 Update 13 on XP SP2

 

Option Explicit On

Imports System.Runtime.InteropServices

Imports SolidEdgeConstants

Imports SolidEdgeConstants.DetailCommandConstants

Imports SolidEdgeFramework

Imports System.Object

 

Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Dim objApp As SolidEdgeFramework.Application

        Dim objDoc As SolidEdgeDraft.DraftDocument

        Dim objSheet As SolidEdgeDraft.Sheet

        Dim objSelSet As SelectSet

        Dim objObject As Object

        Dim dbl_Current_Sheet_Width As Double

        Dim dbl_Current_Sheet_Height As Double

          Dim i As Integer

        Dim Xmin As Double

        Dim Ymin As Double

        Dim Xmax As Double

        Dim Ymax As Double

        Dim bDelete_Object As Boolean   

          objApp = GetObject(, "SolidEdge.Application")

        objDoc = Nothing

        objSheet = Nothing

      objDoc = objApp.ActiveDocument

 

        For Each objSheet In objDoc.Sections.WorkingSection.Sheets

            Call objSheet.Activate()

            objSelSet = objDoc.SelectSet

            dbl_Current_Sheet_Width = objSheet.SheetSetup.SheetWidth

            dbl_Current_Sheet_Height = objSheet.SheetSetup.SheetHeight

            'MessageBox.Show("Sheet Width: " & dbl_Current_Sheet_Width & " Sheet Height: " & dbl_Current_Sheet_Height)

 

            Call objSelSet.RemoveAll()

            Call objSelSet.AddAll()

 

            For Each objObject In objSelSet

                bDelete_Object = False

                Try

                    Call objObject.Range(Xmin, Ymin, Xmax, Ymax) 'You need to have variables for the function to return values.

                Catch ex As Exception

                    MessageBox.Show("Error with Range function on Sheet: " & objSheet.Name & vbCrLf & ex.Message)

                End Try

                'MessageBox.Show("XMin: " & Xmin & " YMin: " & Ymin & " XMax: " & Xmax & " YMax: " & Ymax)

                Select Case Xmax

                    Case Is

                        bDelete_Object = True

                    Case Is > dbl_Current_Sheet_Width

                        bDelete_Object = True

                End Select

                Select Case Xmin

                    Case Is

                        bDelete_Object = True

                    Case Is > dbl_Current_Sheet_Width

                        bDelete_Object = True

                End Select

                Select Case Ymax

                    Case Is

                        bDelete_Object = True

                    Case Is > dbl_Current_Sheet_Height

                        bDelete_Object = True

                End Select

                Select Case Ymin

                    Case Is

                        bDelete_Object = True

                    Case Is > dbl_Current_Sheet_Height

                        bDelete_Object = True

                End Select

 

                If bDelete_Object = False Then

                    objSelSet.Remove(objObject)

                End If

            Next objObject

            objSelSet.Delete() 'WARNING This deletes all objects fully or partially outside of the sheet width & height!

        Next objSheet

 

        Call objApp.StartCommand(DetailViewFit)

        Call objApp.StartCommand(DetailViewRefreshWindow)

    End Sub

End Class

 

Posted by: Dave Bartimus
Post date: 4/3/2009 5:49:18 AM

RE: How to get the Ranges of all Objects in a sheet, then extract values for comparison?

[ Edited ]

I found the Drop() and ConvertToIndependentDetailView() methods

to unlink any drawing views that I wish to delete.

I run this first, then SelectAll, then run my range comparing loop

and remove from the selection set anything inside the rectangle I want to keep.

What remains in the selection set are only items I want to delete.

This handles items that do not have a range property.

 

My only problem is batch processing more than one drawing

and closing files /cleaning up objects after each file.

I never had this issue until using the selection sets & iterating drawing views.

I'll post this on a new separate thread.

 

For Each objDrawingView In objDrawingViews

Select Case objDrawingView.DrawingViewType

Case igAuxiliaryView

objDrawingView.Drop()

Case igBrokenView

objDrawingView.Drop()

Case igDetailView

Call objDrawingView.ConvertToIndependentDetailView()

Case igIsometricView

objDrawingView.Drop()

Case igIsoXSectionView

objDrawingView.Drop()

Case igNullView

objDrawingView.Drop()

Case igPrincipleView

' No need to drop a principal view?

Case igRevolvedSectionView

objDrawingView.Drop()

Case igUserView

' No need to drop, because this is what a

'dropped view becomes.

Case igXSectionView

objDrawingView.Drop()

End Select

Next

 

Hopefully someone will find this of use.

 

Posted by: Dave Bartimus
Post date: 4/15/2009 6:40:31 AM