In this Solid Edge programming tutorial you learn using VB.Net how to:
• Create new drawing sheets. CSharp version is here. A list of all Solid Edge tutorials is here. Most tutorials use Visual Studio 2010. |
This tutorial should be read progressively beginning with the first post in the programming series.
Start Visual Studio and add a Visual Basic Windows Forms Application project.
Add several Buttons, a check box and a listbox to the form as shown.
Declare variables for Solid Edge, the drawing document and the sheets, etc. as below:
Imports System.Runtime.InteropServices
Public Class Form1
Dim oApp As SolidEdgeFramework.Application
Dim oDoc As SolidEdgeDraft.DraftDocument
Dim oSheets As SolidEdgeDraft.Sheets
Dim oSheet As SolidEdgeDraft.Sheet
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.
In the Form's Load event, access a running instance of Solid Edge using the GetActiveObject method:
oApp = Marshal.GetActiveObject("SolidEdge.Application")
oDoc = oApp.ActiveDocument
oSheets = oDoc.Sheets
oSheet = oDoc.ActiveSheet
A draft document should be active when running this program since no error checking is implemented. Store this drawing in oDoc using the ActiveDocument property of Solid Edge.
Also store all sheets in oSheets. This is the sheets collection of the drawing. A single sheet can only be accessed through the sheets collection. As an exception, the active sheet can also be accessed directly from the draft document as in last line above.
Double click the button for Add New Sheet:
oSheet = oSheets.AddSheet()
cmdSheets_Click(cmdSheets, New System.EventArgs())
AddSheet adds a new sheet to the sheets collection, the first optional argument being the sheet name.
The second optional argument is the sheet type for which Solid Edge provides an enumerated list like SolidEdgeDraft.SheetSectionTypeConstants.igWorkingSection and the last two optional arguments specify the sheets between which the newly added sheet will be inserted.
Since all the arguments are optional, Solid Edge adds a new sheet with an automatically incrementing sheet number.
In the second line, the listbox is being updated via the button List all Sheets, whose click event is called from the Click event of the Add Sheet button.
The Click event of the List all Sheets button looks like this:
lstSheets.Items.Clear()
For Each oSh as SolidEdgeDraft.Sheet In oDoc.Sections.WorkingSection.Sheets
lstSheets.Items.Add(oSh.Name)
First the listbox is cleared and then in a For Each loop, the listbox is added with names of the sheets accessed from the sheets collection of the drawing.
Counting the number of sheets via the Count Sheets button is as easy as:
MessageBox.Show(oDoc.Sections.WorkingSection.Sheets.Count.ToString)
A draft document has two sections: Working and Background. The above statements displays the sheets in the working section.
The size of the sheet is a property under the SheetSetup which can be accessed as below from the Sheet Size button:
oSheet = oSheets.Item(lstSheets.SelectedItem)
MessageBox.Show(oSheet.SheetSetup.SheetSizeOption.ToString)
To activate the sheets via the Activate Sheets button:
oSheets.Item(lstSheets.SelectedItem).Activate()
In the above line of code, oSheets.Item(lstSheets.SelectedItem) represents a single sheet from the sheets collection.
Finally, a sheet can be removed via the Remove Sheet button as below:
oSheets.Item(lstSheets.SelectedItem).Delete()
cmdSheets_Click(cmdSheets, New System.EventArgs())
The technique for removing a sheet is same as activating. Here additionally the listbox needs to be updated by first clearing all the items and then flooding the list with the sheet names from the drawing again.
A single sheet can be exported to various formats like dwg, dxf,igs or dgn. The draft document's SaveAs method does this with the option set to Active Sheet Only.
To set this option, select File > Save As and in the Save As dialog, select DXF from the Save as type list. Then click the Options button.
In the Solid Edge to AutoCAD Translation Wizard that appears, click Next >.
In the Sheet Options panel, select the Active Sheet Only option.
Finish the wizard and run the program. Since the option is now set as active sheet in the ini file, the automation program takes this current setting and saves the current document to DXF with only the contents of the currently active sheet.
A single drawing sheet in Solid Edge has many more properties and methods like dimensions, drawing views, text boxes, sketches, layers, etc. Bookmark this blog to read more about these in subsequent posts.
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 sheet technique illustrated.
Also, drop a comment 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.
No comments:
Post a Comment