AnsweredAssumed Answered

Reference a Solidworks Part file in MacroFeature?

Question asked by Rob Edwards on Jul 29, 2019
Latest reply on Mar 30, 2020 by Rob Edwards

Hi Guys


I'm having some fun with macrofeatures that output bodies

Here's what I'd like to do - look at another Solidworks part document -a library part that contains some preexisting geometry.  And then use that geometry to form an extrude in the active part.


I have managed to get this working by asking the user to choose a file and saving the file path as a string parameter in the macrofeature.  The rebuild method opens the file and gets the model doc.


This works fine when the macrofeature is created and until the file is reopened.  At which time the rebuild method will cause an unresponsive crash as the library part is not open in Solidworks.


I'm sure I shouldn't be loading a file during the rebuild function...

Dim sProfileFilepath As String
Call swMFD.GetStringByName("ProfileFilepath", sProfileFilepath)

Dim swFLError As swFileLoadError_e
Dim swFLWarning As swFileLoadWarning_e

Set swProfileModel = swApp.OpenDoc6(sProfileFilepath, swDocPART, swOpenDocOptions_Silent, "", swFLError, swFLWarning)

..but how should I go about getting the ModelDoc. and ensuring the file is open.


If the file is already open then the OpenDoc6 gives a swFileLoadWarning_AlreadyOpen warning but we get a ModelDoc and have no crashes.


Is it possible to create my own External reference so that Solidworks will open the file for me?



I jerry rigged this by inserting the same part into my file and it works.



What would be the proper way to do this?


Essentially I am trying to make a library of some common extrudes that I can choose from at will.


Thanks for looking


All the best