Saturday, 25 January 2014

Cust 36: Drawing Views: VB.Net

In this Solid Edge programming tutorial you learn using VB.Net how to:

• Create 4 standard drawing views: Front, Side, Top and Isometric.
• Specify a part/assembly document to create views.
• Access model links in a draft document.
• Obtain the range or bounding box of a drawing view.
• Align views to each other on the sheet.
• Calculate spacing between views.

image_thumb[11]

VB.Net version of this tutorial is here.
C++ with MFC version is here.

A list of all Solid Edge tutorials on this blog is here.

This tutorial should be read progressively beginning with the first post in the programming series.

Start Visual Studio and add a VB.Net Windows Forms Application project.

Add two Buttons, a text box to the form as below. Also add a OpenFileDialog control.

image_thumb[7]

Declare variables for Solid Edge, the drawing document, sheets, views, etc. as below:

Public Class Form1
    Dim oApp As SolidEdgeFramework.Application
    Dim oDocs As SolidEdgeFramework.Documents

    Dim oDocD As SolidEdgeDraft.DraftDocument
    Dim oDocP As SolidEdgePart.PartDocument

    Dim oSheet As SolidEdgeDraft.Sheet
    Dim oView As SolidEdgeDraft.DrawingView
    Dim oMlink As SolidEdgeDraft.ModelLink

    Dim sParFile As String, sDftFile As String

Note that the document is declared explicitly as a DraftDocument. This is unlike earlier tutorials where the document is declared as SolidEdgeFramework.Document.

Declaring the document as a DraftDocument enables to access the sheets and more drawing specific properties and methods.

Also note the variable oDocP which separately holds the part document for which the views are created.

Apart from these, oSheet holds the sheet on which the drawing sheet on which the views are created. A single variable oView is required for creating the four views and not four variables.

First step is to get the part file name using the Open file dialog named dOpen. Double click the button Select Part Document and add:

dOpen.Filter = "Solid Edge Part Files (*.par)|*.par"
dOpen.ShowDialog()
sParFile = dOpen.FileName
textBox1.Text = sParFile

The first line sets the filter to Solid Edge Part files. The next line displays the dialog using the ShowDialog() call. The third line stores the filename selected by the user and the fourth line displays the full file name in the text box.

A more detailed synopsis of File dialogs in Solid Edge is here.

Once the part file is specified, its time to kick Solid Edge into action via the button Create Views:

oApp = Marshal.GetActiveObject("SolidEdge.Application")
oDocs = oApp.Documents
oDocP = oDocs.Open(sParFile)

This accesses a running instance of Solid Edge using the GetActiveObject method and stores the documents collection into oDocs. It does not matter if any document is currently open or not. The code simply opens the specified part file by using the Open function of the Documents collection using the file name as the argument.

A draft document is then added to the documents collection i.e. a new draft document is created as below:

oDocD = oDocs.Add("SolidEdge.DraftDocument")

Once the draft document is in place, access its active sheet as below:

oSheet = oDocD.ActiveSheet

This sheet is required to place the drawing view on.

Next the link to the part document needs to be established. This is done as below:

oMlink = oDocD.ModelLinks.Add(sParFile)

Using this link, the first drawing view can be created as below:

oView = oSheet.DrawingViews.AddPartView(oMlink, SolidEdgeDraft.ViewOrientationConstants.igFrontView, 1, 0, 0, SolidEdgeDraft.PartDrawingViewTypeConstants.sePartDesignedView)

Views are added to the DrawingViews collection just like documents are added to the documents collection and sheets are added to the sheets collection.

The first argument is the model link established in the previous line. Next argument is the type of view and Solid Edge has a whole list of enums for this:

image_thumb[3]

The following three arguments specified as 1, 0 and 0 are the scale and x- and y-coordinate of the center of the view respectively. this creates the view with its center at the origin of the sheet.

image_thumb[6]

Next step is to create the other three views for which first the extents or bounding box or Range of the initial view is calculated as below:

Dim xMin As Double, yMin As Double, xMax As Double, yMax As Double
Call oView.Range(xMin, yMin, xMax, yMax)

Next the size of the view is calculated as below:

Dim xGap As Double, yGap As Double
xGap = xMax - xMin : yGap = yMax - yMin

Following this, the remaining views are placed with spacing between them as below:

oView = oSheet.DrawingViews.AddPartView(oMlink, SolidEdgeDraft.ViewOrientationConstants.igLeftView, 1, xGap * 2, 0, SolidEdgeDraft.PartDrawingViewTypeConstants.sePartDesignedView)

oView = oSheet.DrawingViews.AddPartView(oMlink, SolidEdgeDraft.ViewOrientationConstants.igTopView, 1, 0, yGap * 2, SolidEdgeDraft.PartDrawingViewTypeConstants.sePartDesignedView)

oView = oSheet.DrawingViews.AddPartView(oMlink, SolidEdgeDraft.ViewOrientationConstants.igTopFrontLeftView, 1, xGap * 2, yGap * 2, SolidEdgeDraft.PartDrawingViewTypeConstants.sePartDesignedView)

This is an unnamed draft document. A name is created for the Draft document, done by replacing the .PAR extension with .DFT as below:

sDftFile = sParFile.ToUpper.Replace("PAR", "DFT")

This string sDftFile is used to save the draft document.

oDocD.SaveAs(sDftFile)

and finally the part document is closed:

oDocP.Close(False)

Once again, A list of all Solid Edge on this blog tutorials is here.

Meanwhile, drop a comment below if you need any other drawing view technique illustrated.

clip_image002_thumb1_thumb_thumb_thu[1]_thumbAlso, drop a comment down below if you need the Visual Studio project files and if you liked the depth of this discussion, similar in-depth techniques are discussed in cMayoCAD where you create your own, brand new, fully functional CAD system with scripting capabilities using a geometric modeling kernel.

Download the detailed course contents for cMayoCAD here.

cMayoCAD242[2]