Cancel
Showing results for 
Search instead for 
Did you mean: 

How to get part dimension values in vb.net code

Hi All,

I have problem to get dimension value in solid edge part. Kindly help if any procedure or code is available. (Consider as a rectangle part).

I need get part dimension value of "Width", "Length" & "Thick".

Anybody help me

 

Regards,

Ramkumar

10 REPLIES 10

Re: How to get part dimension values in vb.net code

Creator
Creator
Hello
Possible solution
 
WARNING YOU MUST REGISTER THE SEFACET.DLL DLL in cmd: regsvr32 SEFacet.dll
Be careful the data is recovered in the plan.
 
BRUT 3.JPGBRUT 2.JPG
'----------------------------------------------------------------------
        ' Use the SEFacet API to compute the bbox of a part document without
        ' the need for a SE license.
        ' 
        ' NOTE:
        ' Register the SEFacet.dll in the "...\SDK\Readers" subfolder of the
        ' Solid Edge installation path and reference it in your project.
        '----------------------------------------------------------------------
        Dim ofd As OpenFileDialog = New OpenFileDialog()
        ofd.DefaultExt = ".par"
        ofd.Filter = "Solid Edge Part Document (*.par)|*.par||"
        ofd.InitialDirectory = "C:\TEMP"
        If ofd.ShowDialog() <> System.Windows.Forms.DialogResult.OK Then
            Exit Sub
        End If
        ' Create an instance to the SEFacet API
        Dim objType As Type = Type.GetTypeFromProgID("SEFacet.FacetReader")
        Dim objReader As SEFACETLib.FacetReader = Activator.CreateInstance(objType)
        Dim bbox() As Double = {9999, 9999, 9999, -9999, -9999, -9999}
        Dim vx, vy, vz As Double ' The vertex coordinates
        Dim nx, ny, nz As Double ' The vertex normal
        Dim tu, tv As Double ' The vertex texture parameter
        objReader.Open(ofd.FileName)
        Dim nBodies As Integer = objReader.BodyCount
        For bodyIdx As Integer = 1 To nBodies
            Dim nFaces As Integer = objReader.BodyFaceCount(bodyIdx)
            For faceIdx As Integer = 1 To nFaces
                Dim nStrips As Integer = objReader.BodyFaceStripCount(bodyIdx, faceIdx)
                For stripIdx As Integer = 1 To nStrips
                    Dim nVertices As Integer = objReader.BodyFaceStripVertCount(bodyIdx, faceIdx, stripIdx)
                    For vertexIdx As Integer = 1 To nVertices
                        objReader.GetBodyFaceStripVertex(bodyIdx, faceIdx, stripIdx, vertexIdx, vx, vy, vz, nx, ny, nz, tu, tv)
                        ' Update the bounding box
                        If vx < bbox(0) Then
                            bbox(0) = vx
                        ElseIf vx > bbox(3) Then
                            bbox(3) = vx
                        End If
                        If vy < bbox(1) Then
                            bbox(1) = vy
                        ElseIf vy > bbox(4) Then
                            bbox(4) = vy
                        End If
                        If vz < bbox(2) Then
                            bbox(2) = vz
                        ElseIf vz > bbox(5) Then
                            bbox(5) = vz
                        End If
                    Next
                Next
            Next
        Next
        objReader.Close()
        ' Write out the final stock size in millimeters
        Debug.WriteLine(String.Format("Dim X:  {0:0.00} mm", (bbox(3) - bbox(0)) * 1000.0))
        Debug.WriteLine(String.Format("Dim Y:  {0:0.00} mm", (bbox(4) - bbox(1)) * 1000.0))
        Debug.WriteLine(String.Format("Dim Z:  {0:0.00} mm", (bbox(5) - bbox(2)) * 1000.0))

 

Re: How to get part dimension values in vb.net code

Solution Partner Genius Solution Partner Genius
Solution Partner Genius

Another possible solution (it needs a SE license and opening the file in Solid Edge)

is to use the Range or GetRange method depending if you are relating to an Occurrence or a Part document:

 

Part document. Look for GetRange:

Public Sub GetRange( _
   ByRef MinRangePoint() As Double, _
   ByRef MaxRangePoint() As Double _
) 

 

If it is an Occurrence look for Range method:

Public Sub Range( _
   ByRef x_min As Double, _
   ByRef y_min As Double, _
   ByRef z_min As Double, _
   ByRef x_max As Double, _
   ByRef y_max As Double, _
   ByRef z_max As Double _
) 

This is only valid if part is aligned to the default coordinate system. Oherwise values are the bounding box that contains the part and it could be bigger that the part dimensions themselves.

Julian Guillo
Pixel Sistemas SL
Spain

Re: How to get part dimension values in vb.net code

Solution Partner Genius Solution Partner Genius
Solution Partner Genius

Note: This must be done opening Solid Edge.
The fastest way to open a new Solid Edge is to do it invisible. Something like:

oSE=CreateObject("SolidEdge.Application")
oSE.Visible=False
oSE.DisplayAlerts=False
oSE.Interactive=False

'Do your stuff
oPar=oSE.Documents.Open("<path se file>")
oPar.models.Item(1).GetRange(p1,p2)

'Close and quit
oPar.Close(False)
oSE.Quit
Julian Guillo
Pixel Sistemas SL
Spain

Re: How to get part dimension values in vb.net code

Gears Honored Contributor Gears Honored Contributor
Gears Honored Contributor

Hi @lmb_ramkumar_g 

 

Presuming that the synchronous part is open in Solid Edge, the following function will list all those dimensions in the image including the thickness of 25:

 

Sub ListAllPartDimension()
        Dim seApp As SolidEdgeFramework.Application
        Dim sePart As SolidEdgePart.PartDocument
        Dim seDimensions As SolidEdgeFrameworkSupport.Dimensions
        Dim seDimension As SolidEdgeFrameworkSupport.Dimension
        Dim sePMI As SolidEdgeFrameworkSupport.PMI = Nothing

        seApp = GetObject(, "Solidedge.Application")
        sePart = seApp.ActiveDocument
        sePart.PMI_ByModelState(sePMI)
        seDimensions = sePMI.Dimensions

        For Each seDimension In seDimensions
            Debug.Print("Name = " + seDimension.VariableTableName + " Value = " + seDimension.Value.ToString)
        Next
End Sub

Hope you find this useful.

 

Regards,

Tushar Suradkar

www.SurfAndCode.IN

www.CADVertex.com

 

Re: How to get part dimension values in vb.net code

Valued Contributor
Valued Contributor

Nothing is marked as the answer.  Can the originator mark one correct?  If there's still a question, could you clarify whether you are trying to get Solid Edge dimension objects, and the values of those, or if you want the overall box size of the part?

------------------
Alan Baljeu
Owner, Cornerstone Intelligent Software
Developer of custom CAD software

Re: How to get part dimension values in vb.net code

Hi AlanBaljen,

 

If it’s square or rectangle object need width, length & thick or if it’s cylindrical object need diameter and length of the object or if it’s hollow cylindrical need dimeter, thick and length of the object. This my requirement.

 

Ramkumar

Re: How to get part dimension values in vb.net code

Valued Contributor
Valued Contributor

It sounds like you don't have dimensions on those objects.  In that case you need to drill down to the face and edge geometry from the body level.  You can test if a face is cylindrical or planar.  If it's a cylinder you can get the radius.  But the length will be found by inquiring about the end points.  If it's planar, you can look for edges and if those are lines you can measure the distance between points.

 

The difficulty with this problem is you need to assume the geometry is the kind you expect (or write a lot of code to validate). For example, a planar face could be a square.  Or a triangle.  Or have a combination of arcs and lines and other stuff.  So you can assume a rectangle and measure points, or just measure the overall without considering the shape, or validate that it is a rectangle and measure the lines.

 

Is this explanation closer to what you want to achieve?

------------------
Alan Baljeu
Owner, Cornerstone Intelligent Software
Developer of custom CAD software

Re: How to get part dimension values in vb.net code

Hi Alan,

 

Thanks for reply. How to check whether the object is planar or cylindrical. If example code available....

Ramkumar 

Re: How to get part dimension values in vb.net code

Gears Honored Contributor Gears Honored Contributor
Gears Honored Contributor

What steps have you taken so far?

Is any code written already?