CADSharpTools: .NET Developer Toolkit

Blog 8.13.2018 No Comments

CADSharp is pleased to announce that our industry-leading SOLIDWORKS API and SOLIDWORKS PDM API libraries are now available to CADSharp.com Power User members. This is the ultimate toolkit for those who want to speed up their .NET addin and stand-alone development by utilizing our hand-made library of commonly used functions and classes. Best of all, it’s regularly updated by CADSharp team members with great new functionality.

Demonstration

Possibly the best way to demonstrate the power of this toolset is to compare two addins, one that uses CADSharpTools and one that does not. These addins both accomplish the same thing: creating dropdown menus in SolidWorks that appear in particular document types and display message boxes when clicked.

You will notice that the example using CADSharpTools requires fewer imports, fewer classes, fewer lines of code (about a third less), and is much more readable. More importantly, you can imagine how much faster developing an addin is using CADSharpTools. You can set up your own template with CADSharpTools already utilized or quickly update old addins. You might even discover a better way to accomplish certain tasks using our toolset.

Functionality

Note: While this is complete list of classes, the descriptions do not state all functionality in each class.

CTAddin

Contains classes that let you easily create drop-down menus and CommandManager tabs (saving you possibly hundreds of lines of code), register and unregister your addin with SolidWorks, and perform “cleanup” when unloading the addin.

CTAssembly

Contains functions that let you rename components, get a component’s instance, get a component’s name without the instance number, and create an array of unique components in the assembly.

CTConstants

Contains dozens of useful file extension and file filter constants.

CTDocManager

Lets you input your Document Manager license key via the constructor and then easily work with a document’s custom properties, get a document’s configuration names, and more.

CTDrawings

Provides flexible options for searching for and updating notes, getting a note’s position relative to the sheet margin, and locating views.

CTExcel

Lets you store a spreadsheet’s contents in a .NET DataTable, get worksheet and workbook pointers, create Excel visibly or invisibly, quit Excel, and determine if any Excel processes are active.

CTFileSystem

Lets you safely create, copy, delete, and rename files and folders in Windows. You can also determine if a file is read-only, verify its extension, verify whether a file name is legal, and read text files.

CTFormUtility

Lets you sort ListView controls in ascending or descending order, as well as create file and folder browsers that add the browsed location to a text box.

CTLogger

Lets you easily handle various aspects of logging, namely creating the log entries and accessing the log folder in the user’s AppData folder.

CTModel

Performs various tasks related to two or more SolidWorks model types, including toggling graphics updating, creating named views, working with display states, creating a pack and go, and saving the model (Save or Save As) in any format.

CTPart

Performs tasks related to parts, including getting IBody2 pointer given a body name, getting a body’s folder feature, and getting a body’s cut list feature.

CTSolidWorks

Lets you create an instance of a SolidWorks (for use with a stand-alone) with the ability to specify the desired year if multiple installations are present, exit SolidWorks (for use with a stand-alone), determine if any SolidWorks processes are active, open a SolidWorks model, get a model’s document type from its file path, and get a list of all SolidWorks models of a particular type in a folder.

CTTopology

Lets you search geometry and topology, such as getting the length of an edge and getting the largest planar face in a body.

CTUtility

Lets you easily get the data from a project’s Assembly Information, display a message with the product name as the title, save out an embedded icon to the local disk and get its file path, convert an enumerator to string, and compare two values given a tolerance.

CTXmlHandler

Lets you read read a specific XML node, update a specific XML node, and get a list of all material names in a SolidWorks material database.

How Can I Use It?

If you are a Power User member and wish to use CADSharpTools then you may visit our this page to learn how to obtain it. You can either download the DLL and add it as a reference to your project or you can copy and paste individual portions of the source code into your code. The documentation is available in the repository. You can also submit bug reports and enhancement requests using the repository’s built-in issue tracker. If you’re new to online repositories and have any questions, let us know.

Think of it as similar to our Macro Library, except 1) the entire codebase can be downloaded and referenced in a project, 2) the codebase is in .NET. As long as you kindly do not share the DLL or the code outside of your organization with individuals who aren’t CADSharp, the sky is the limit. (Note: it is fine to use the code in a project that you will sell to a customer. Please the entire Usage Agreement here.)

Want to keep up with future content and training events? Sign up for our newsletter.


Leave Comment

Fix These 4 Common PDM Vault Addin Errors

Blog 8.1.2018 No Comments


Have you ever attempted to develop a SOLIDWORKS PDM addin and run into errors when adding it to the vault? This short posts discusses four different types of errors one might actually see when adding a new PDM addin to a vault.

1. The DLL is not com module 

This error simply means that your DLL is com-compliant. Your types were not registered for com interops and probably are not com-visible. You can fix this by:

  • Decorating the class with the ComVisible(“true”) attribute and guid:

  • Going to Project > Build (Compile for VB.NET) and then checking register for com interop.

2. Please Select at least one DLL implementing the IEdmAddIn5 Interface


 

Your add-in class must  implement the IEDMAddIn5 interface.  To implement this interface, you must reference a dll that contains this interface.

  • Add a reference to <SOLIDWORKS PDM INSTALLATION FOLDER>/EPDM.interop.epdm.dll. This assumes you are writing a add-in for CLR4 (SOLIDWORKS 2013 and newer). Here’s a table that summarises the different versions of the PDM interops:
     PDM Professional versions… Support .NET Framework…
    2013 and later 4.0 and later
    2009 – 2012 3.5, 3.0, and 2.0
    2008 and earlier 2.0

    To target earlier version of the CLR, follow this link for instructions.

  • Implement the interface like follow:

    Normally, after writing MyPDMAddInClass : IEdmAddIn5, Visual Studio will show a squiggly line under IEdmAddIn5, press Ctrl + ; and then implement explicity:

3. The add-in ‘<Path>’ cannot be installed since it returned an invalid required version SOLIDWORKS PDM version from its GetAddInInfo Method

This is because of an incomplete implementation of the GetAddInInfo method. A sample implementation of the GetAddInInfo would look like this:

4. The archive server could not open  the Windows registry



This error is because of windows permissions. If you are running Windows 7/10, make sure the run the administration tool with administrator privileges.
If you have downloaded the add-in dll, make sure it’s not blocked by windows. To unblock, simply right on it and go to properties:

Questions or comments? Please share in the comments below!

Amen Jlili

Want to keep up with future CADSharp.com content and training events? Join our newsletter!


Leave Comment

What’s New in the 2018 SolidWorks API

Blog 3.1.2018 No Comments

SolidWorks 2018 was released over half a year ago, but it’s never too late to talk about the new enhancements in the SolidWorks API. Aside from covering new API calls, we will look at what is undoubtedly this version’s most notable upgrade: VSTA 2015. This lets programmers create .NET macros in Visual Studio instead of the lackluster VSTA editor.

New API Calls and Interfaces

Below is a list of the most notable API calls and interfaces added in SolidWorks 2018. You can see all additions and their related API calls in the Release Notes article in the API Help. You can find it in the local API Help by searching for “Release Notes” in the category tab. Note that the local API Help Release Notes will only be as up-to-date as the service pack you have downloaded.

I have bolded those API calls that I find particularly interesting. Those with an asterisk I could not find when I looked at the release notes.

  • Access general tolerance table annotations and features.
  • Work with hidden cells, rows, and columns in tables.
  • Add a distance mate between cylindrical components of an assembly.
  • Add rebuild and save marks to multiple configurations and remove them from all configurations.
  • Add specific display dimensions by type.
  • Create a spline constrained to a surface.
  • Create a trimmed sheet body with a specified tolerance.*
  • Create advanced assembly mates and sweeps.
  • Create advanced holes in parts.
  • Create bidirectional twist and thin-walled sweep features.
  • Create internal and external threads.
  • Handle pre- and post-notify events when converting bodies.
  • Import and export Hole Wizard and Toolbox data.
  • Modify control points and interior knots in sketch splines.
  • Offload PhotoView 360 rendering to other networked machines.
  • Optionally rebuild a model after adding configurations.
  • Quickly check whether an interference exists between components.
  • Save and restore the current SolidWorks settings. (Appears to mimic Copy Settings Wizard)
  • Advanced exploded view editing.
  • Set table anchors at selected sketch points on drawing sheets.
  • Show the preview of a configuration selected in the ConfigurationManager.
  • Edit third-party native CAD components in assemblies.*
  • Get corresponding objects between drawing views and parts or assemblies.
  • Get layer items by type.
  • Get or set a custom property builder template for parts or weldments.
  • Get or set whether to automatically rebuild equations.
  • Get or set whether to automatically repair files on opening.
Accessor Diagrams

New interfaces added this year not only have the typical accessor list you have come to expect but also a PDF that visually shows an interface’s accessors and the interfaces that it gives access to. At this point I don’t see myself using these very much, but perhaps others will find them helpful.

Important Updates to VSTA

VSTA (Visual Studio Tools for Applications) is the technology that allows you to create .NET macros. Previously you had to use the VSTA editor, which looked like a rudimentary version of Visual Studio but launched from SolidWorks like the VB Editor. I really despises the VSTA editor so I am pleased that creating .NET macros can now be done in Visual Studio. This change is possible because SolidWorks 2018 upgraded from VSTA 1.0 to VSTA 3.0 (also known as VSTA 2015). In the General tab of the System Settings, you can toggle between using VSTA 1.0 and 3.0 in 2018 and eventually only VSTA 3.0 will be available, therefore it is important to upgrade one’s .NET macros sooner rather than later.

Personally, I am still going to avoid .NET macros because its unclear whether the DLL stability issue that existed with VSTA 1.0 still exists in VSTA 3.0. I also have encountered numerous people who can’t get VSTA installed properly even though it is checked in the SolidWorks Installation Manager. Altogether, the hassle involved with VSTA isn’t worth it and I’d rather simply use VBA macros for testing and .NET stand-alones and addins for production. Nevertheless, if you end up using VSTA 3.0 with Visual Studio then please share your experience with us in the comments below.

To learn more about how to use VSTA 3.0, watch Daniel Seaman (SolidWorks API Tech Support Manager) deliver a presentation on the topic from SolidWorks World 2018. Steps to do this:

1. Visit the SolidWorks World 2018 agenda
2. Search the Sessions tab for the name “Seaman”
3. The result for “Upgrading SOLIDWORKS Macros to Visual Studio Tools for Applications 2015” should appear and you can click Watch Video on the right (requires a free account)

Context-Sensitive Help Viewer

According to the release notes: When you install SOLIDWORKS 2018, SOLIDWORKS and SOLIDWORKS enumerator context-sensitive helps are registered and integrated with the Help Viewer of the Visual Studio installed on your machine. After installing SOLIDWORKS 2018, configure Visual Studio to launch Help Viewer F1 help by selecting Help –> Help Preference –> Launch in Help Viewer.

To be honest, I haven’t figured out how to use this with Visual Studio Community 2017. If anyone has gotten it to work, let me know in the comments below. At this point its unclear to me if this saves that much time beyond simply creating a shortcut to apihelp.chm.

Workgroup PDM API No Longer Supported

As the title says, SolidWorks Corp is no longer offering technical support for the Workgroup PDM API since Workgroup PDM is no longer shipped with SolidWorks as of this version. Obviously the intent is to push all PDM users, even the small and mid-sized companies that Workgroup PDM was created for, toward SolidWorks PDM Standard or Professional (formerly Enterprise PDM).

Does anything we’ve covered stand out to you as particularly useful or exciting? If so then let us know in the comments!

Want to keep up with future CADSharp.com content and training events? Join our newsletter!


Leave Comment