Cancel
Showing results for 
Search instead for 
Did you mean: 

Migrating from the SolidWorks API - Part 1

Gears Honored Contributor Gears Honored Contributor
Gears Honored Contributor

 

The makers of Solid Edge have left no stone unturned to make your transition from SolidWorks to Solid Edge effortless and streamlined. Not only that Synchronous Technology readily recognizes features of imported models, fully associative SolidWorks drawing migration is a reality since ST9.

 

This is pretty cool stuff for people coming from SolidWorks to Solid Edge where the data migration wizard not only migrate all your parts and assemblies including FOA, FOP, materials, thread table etc, but also drawings are fully associatively, such that if you change the part in SE, the converted drawing will also update, as if you created it natively in Solid Edge.

 

The auto-magic part ends there. If you have created any SolidWorks macros for automating routine tasks in the past and missing them, recreating them is a piece of cake. A little insight into the Solid Edge API equivalents of those in SolidWorks is the key to this migration. To know, read on...

 

References

 

Unlike SolidWorks where a single reference to the type library takes care of all environments, Solid Edge has one each for the Part, Draft, Assembly. Reference to the Solid Edge Framework Type Library is mandatory.

 

Besides this, there are specialized libraries for gathering installation data, another one just for the File Properties, besides those for the Design Manager or Revision Manager or older versions of Solid Edge and Geometry Type Library for accessing. Read a detailed article about the Geometry API.

 

TCW01.png

 

The FrameWorkSupport Library is also a general library, though not mandatory and supplements the Framework library by hosting objects which are common across various environments like Dimensions, Lines, etc.

 

The Constants libraries are similar for both SolidWorks and Solid Edge, in that they should be added separately, when necessary.

 

The image below illustrates the need to use the Imports statement for each Type Library if you want to use the functions and properties within:

 

TCW03.png 

 

 TipIcon.pngTip: If you are not sure which Type Library needs to be included for a project, there is no harm in referencing and importing all Solid Edge libraries.

 

Application Object

 

In SolidWorks the Application object is handled as below:

Dim swApp as SldWorks.SldWorks = Nothing

swApp = CreateObject("SldWorks.Application")
swApp.Visible = True

 

In Solid Edge the class and program ID are consistent:

Dim seApp as SolidEdgeFramework.Application = Nothing

seApp = CreateObject("SolidEdge.Application")
seApp.Visible = True

Also note that just as in SW, the application object must be explicitly made visible.

 

Note another difference in the style, for example, displaying the status bar: 

swApp.DisplayStatusBar(True) ' or False

seApp.StatusBarVisible = True ' or False

 

And, for exiting or quitting the application: 

swApp.ExitApp()

seApp.Quit()

 

Document Access

 

SolidWorks has a document type for different documents: 

Dim swAsmDoc As AssemblyDoc = Nothing
Dim swPartDoc As PartDoc = Nothing
Dim swDrawDoc As DrawingDoc = Nothing

 

Similarly, Solid Edge has: 

Dim seAsmDoc As SolidEdgeAssembly.AssemblyDocument = Nothing
Dim sePartDoc As SolidEdgePart.PartDocument = Nothing
Dim seDraftDoc As SolidEdgeDraft.DraftDocument = Nothing

 

SolidWorks general document which is ModelDoc2 has the Solid Edge Equivalent as SolidEdgeDocument and further can be assigned to the active document irrespective of its type as below:

Dim swDoc as ModelDoc2 = swApp.Activedoc

Dim seDoc As SolidEdgeFramework.SolidEdgeDocument = seApp.ActiveDocument

 TipIcon.png

 

 Tip: The API help is available online here and locally in the SDK folder

 

TCW02.png 

 

Document Type

 

A SolidWorks document has a method GetType which returns a unique number depending on the type of SolidWorks document as below:

 

TCW04.png 

1 for SolidWorks Part document.

2 for SolidWorks Assembly document.

3 for SolidWorks Drawing document.

 

In Solid Edge, you would use one of the following techniques to determine the active document type:

 

1. Directly from the Solid Edge application, when the active document is not yet assigned to a variable:

 

 TCW06.png

 

Here's a full list of the document types in Solid Edge:

 

 TCW05.png

 

2. Determine the type of a document in a variable:

 

 TCW07.png

 

Creating New Documents

 

Creating a New document in SolidWorks followed a similar pattern and was a straightforward affair: 

Dim swAsmDoc As AssemblyDoc = swApp.NewAssembly
Dim swPartDoc As PartDoc = swApp.NewPart
Dim swDrawDoc As DrawingDoc = swApp.NewDrawing(1)

 where the argument for New Drawing was one of these:

 

TCW08.png

 

In Solid Edge, you must not lose sight of the collection concept. Documents are always added to the Documents collection, which in turn belongs to the SE Application: 

Dim seAsmDoc As SolidEdgeAssembly.AssemblyDocument = seApp.Documents.Add("SolidEdge.AssemblyDocument")
Dim sePartDoc As SolidEdgePart.PartDocument = seApp.Documents.Add("SolidEdge.PartDocument")
Dim seDraftDoc As SolidEdgeDraft.DraftDocument = seApp.Documents.Add("SolidEdge.DraftDocument")

 

The Add method in Solid Edge has an optional argument for the template that can take care of the sheet size format for a drawing. 

Public Function Add( _
   Optional ByVal ProgID As Variant, _
   Optional ByVal TemplateDoc As Variant _
) As Object

 

Saving Documents

 

In SolidWorks an already saved file could be saved, after any changes, using the Save method:

swDoc.Save()

and could be SavedAs using

 

swDoc.SaveAs(sNewFileName)

 

 

Similar looking methods are also used in Solid Edge:

seDoc.Save()
'and
seDoc.SaveAs(sNewFileName)

 

Exporting Document to Other Format

 

In both SolidWorks and Solid Edge, simply changing the extension to the desired type does the trick, and only the syntax differs:

Dim iErr As Integer
Dim iWarns As Integer
 
swDoc = swApp.ActiveDoc()
Dim sFile As String = swDoc.GetPathName()
Dim sExpFile As String = IO.Path.ChangeExtension(swDoc.GetTitle, ".STL")
swDoc.SaveAs4(sExpFile, SwConst.swSaveAsVersion_e.swSaveAsCurrentVersion, SwConst.swSaveAsOptions_e.swSaveAsOptions_Silent, iErr, iWarns)

 

In Solid Edge you would achieve the same in lesser lines: 

seDoc = seApp.ActiveDocument
Dim sExpFile As String = System.IO.Path.ChangeExtension(seDoc.FullName, ".STL")
seDoc.SaveAs(sExpFile)

 TipIcon.png

 Tip: SolidWorks has some tools like a macro recorder and a VBA editor, which has no equivalent in Solid Edge. Similarly, Solid Edge has a unique and equally helpful tool in the form of Solid Edge Spy.

 

Saving As Image

 

In SolidWorks the swDoc.SaveBMP method took care of creating an image of the current document.

Also using a PNG or JPG extension in the SaveAs4 method described above creates the image files in respective formats.

 

In Solid Edge, the Save As dialog does not have image file formats listed in the file types list.

To Save As an Image in Solid Edge, follow these methods:

 

3D Documents: Part, Sheetmetal, Assembly

Dim seView As SolidEdgeFramework.View = Nothing
seView = seApp.ActiveWindow.View
seView.SaveAsImage("C:\Temp\sFileName.JPG", 1600, 900, , , , SolidEdgeFramework.SeImageQualityType.seImageQualityHigh)

where the numbers are the width and height of the image and the last argument decides the quality of the output image:

 

seImageQualityLow = 1

seImageQualityMedium = 2

seImageQualityHigh = 3

 

The above method works only for a 3D document like the Part, Sheetmetal or Assembly.

 

For Draft Document

 

For a Draft document the method of saving an image is as below:

Dim seDraftdoc As SolidEdgeDraft.DraftDocument = seApp.ActiveDocument
Dim seWindow As SolidEdgeDraft.SheetWindow = seDraftdoc.Windows.Item(1)
seWindow.SaveAsImage("C:\Temp\sFileName.JPG", 1600, 900, , , , SolidEdgeFramework.SeImageQualityType.seImageQualityHigh)

 

Count and Iterate through Documents

 

To count the number of documents open, SolidWorks has a direct function:

Dim iCount As Integer = swApp.GetDocumentCount()

 

In Solid Edge the Documents collection tells the count: 

Dim iCount As Integer = seApp.Documents.Count

 

Solid Edge has the concept of collections which is entirely missing in SolidWorks. Hence SolidWorks uses a For loop with a pointer from the first document to get the next document:

 

Dim sFileName As String
Dim swCurDoc As ModelDoc2 = swApp.GetFirstDocument

While Not swCurDoc Is Nothing
  sFileName = swCurDoc.GetTitle()
  MessageBox.Show (sFileName)
  swCurDoc = swCurDoc.GetNext()
End While

 

This becomes very easy and simple in Solid Edge due to the Documents collection:

For Each seDoc As SolidEdgeDocument In seApp.Documents
  MessageBox.Show(seDoc.FullName)
Next

  

Close Document

 

For closing a document in SolidWorks two methods are used:

swApp.CloseDoc(sFileName)
swDoc.Close()

 

The equivalents in Solid Edge are:

seApp.Documents.CloseDocument(FileName, True)

where the second argument is about saving changes before saving, and

seDoc.Close(False)

where the argument is to Save the document or not.

 

For closing all documents in SolidWorks,

swApp.CloseAllDocuments(True)

where the Boolean argument is about closing unsaved document as well, while in Solid Edge, the same is achieved via the Documents collection:

seApp.Documents.Close

 

Activate a Document

 

For activating one of the open documents in SolidWorks,

swApp.ActivateDoc(sFileName)

 

To activate a document in Solid Edge, first it must be located in or accessed from the Documents collection:

seDoc = seApp.Documents.Item(3)
seDoc.Activate

 

Instead of the index, the full name can also be used:

seDoc = seApp.Documents.Item("C:\Program Files\Solid Edge\Training\plate.par")
seDoc.Activate

or directly like this:

seDoc = seApp.Documents.Item(3).Activate
'or
seApp.Documents.Item("C:\Program Files\Solid Edge\Training\plate.par").Activate

where the index starts from 1

 

This introductory part covered:

 

  1. References.
  2. Application declaration and access.
  3. Creating new documents.
  4. Document types and access.
  5. Counting and iterating through open documents.
  6. Closing and activating documents.
  7. Saving documents.
  8. Creating images from documents.
  9. Exporting a document to other 3D formats.

 

The subsequent articles in this series will show:

 

  • Draft sheet, drawing views and dimensions handling.
  • Parametric part and feature techniques in detail.
  • Assembly Document migration in detail.
  • 2d entities creation and object selection.
  • File properties.
  • General Solid Edge techniques.

 

If you want to learn Solid Edge programming from grounds-up, several in-depth tutorials are available on this Solid Edge Programming blog.

 

When you run into any problem, you can always post a programming related query in the Development Forum.

 

 TwitterLogo32x32.pngTushar_Suradkar