Lesson 3.1 – Opening, Saving, and Exporting Documents

You need to be logged in to view this content. Please login or become a member.

<<  Prev   |   Index   |   Next  >>

Description

This lesson covers opening, saving, and exporting native and non-native documents with the SolidWorks API. Many tips for using API calls are covered.

Notes

In 2012 you can use ISldWorks::ActivateDoc3 to control whether the document is rebuilt after activation. See our example “Traverse all open documents” for how to use ActivateDoc3 in combination with ISldWorks::GetDocuments to cycle through all open documents.

In lesson 3.5 you will learn how to get the current template path from the system options, removing the need to specify your template path in the macro.

Lesson Files

Lesson 3.1 code

Homework

Lesson 3.1 homework part A solution
Lesson 3.1 homework part B solution
Lesson 3.1 homework part C solution

4 Comments

  1. andystone40

    Is there a similar function to GetTitle that returns either just the title without the extension or the title and the extension every time so that you don’t need to worry about peoples settings? I realize the GetPathName works but for a command like “swApp.CloseDoc swModel.GetTitle” it will only work under some settings.

    • Your only options are:

      1. Parse the full title (name and extension) out of the string returned by IModelDoc2::GetPathName using string manipulation functions.

      2. Use the FileSystemObject::GetFileName to get the name and extension from IModelDoc2::GetPathName. This will require a reference to the Microsoft Scripting Runtime.

  2. holadepo

    Thanks for this tutorial. I tried to load an stl mesh file for the scanTo3D add-in but the macro seems to be loading the file as an stl graphic instead of a mesh. Does this mean there is no API access to the scanTo3D add-in?

Questions and Comments

You must be logged in to post a comment.