Macro for inserting and mating a new part in an assembly

I know there must be one out there but I can't find it!

Does anyone know where I can get a macro that when run inside anassembly creates a new part, asks for file name and save locationthen inserts that part into the active assembly setting it to fixedor mated?

I've tried recording a macro but of course I don't know how to getit to ask for user input a the save stage.

Thanks for your help. Very much appreciated.SolidworksApi macros
Answers 11
JB
JB 2009-03-13 Best Answer
Hi Scott,

The functionality you describe was more or less how SolidWorksworked prior to SW2008 when using the 'Insert New Part' function.

I don't like the virtual component functionality introduced inSW2008 - or to be more precise I don't like that I am forced to useit. It gives me an extra step in the process because I ALWAYS saveout the parts. Is that the same reason you have for such a macro?

I don't know if a ready-made macro can be found somewhere. I willbe happy to assist you with specific questions/problems if you havesomething to start with.
IK
IK 2009-03-13
using common dialog from vb
SF
SF 2009-03-16
Thanks for your comments Jorn. I do like the virtual featurefunctionality and use it quite a bit for things like fasteners andgaskets that aren't actually modeled in the assembly but need toappear in the BOM. However when I do this it's from within adrawing by right clicking on the BOM and selecting "Insert NewPart". When in an assembly I never use it and as you say, resentbeing forced to which adds the extra work. I would appreciate theoption of being asked for a file name and have lodged a enhancementrequest. I as you say, always save out the parts and so want torevert to the old behavior.

Anyway, back to the topic of a macro...
I know nothing of VB but have decided to learn since many if notall my enhancement requests can be solved with macros. All I havedone is to use the record macro function which has produced thedesired result only it doesn't give the option to nominate the newpart name or save location. I just need to find the VB functionthat brings up the dialogue box for user input. I have tried toupload it up get an error.

Ivan,

As mentioned I know zip about VB... so I just ran the macro withinan open assembly you attached and it starts a new part file butdoes not insert it nor give me the option to name it. What is theintended usage of the macro?

I am off to buy a VB book today! Thanks
SF
SF 2009-03-16
Here is the macro...
IK
IK 2009-03-16
Scott,

in my macro, if you choose tools -> references, are you missing"microsoft common dialog control" ?
JB
JB 2009-03-16

Scott Manning wrote:

 

Here is the macro...

Scott,

Stay tuned. The next couple of days I am busy with meetings andthings to do so I am not able to assist you right now. I will getback to you later this week (if you still need help).
SF
SF 2009-03-17

ivana kolin wrote:

 

in my macro, if you choose tools -> references, are youmissing "microsoft common dialog control" ?

Arrr yes. I see in there where there is no file reference -which causes the error. I got that far. So your macro then callsthe dialogue control which allows the data to be entered?

I don't have that control available in the "references" as youmention. I'll go and have a google and track it down.

IK
IK 2009-03-17
SF
SF 2009-03-17
Cool got it. Saved it with the other ocx files. Went totools/references and selected it. Saved and closed the macro.Re-opened the macro and confirmed it was still checked - yup.

Open assembly, save assembly. Run macro.

The macro still created a new part but did not save it (no dialoguebox or anything) nor insert it into the assembly.... Still doingsomething wrong?

FWIW, I am using SW2009 SP2.1 on WinXP SP2

Thanks, I appreciate your help
IK
IK 2009-03-17
did you register it with C:\WINDOWS\system32\regsvr32.exepath\comdlg32.ocx ?
SF
SF 2009-03-19
Yeah, but still no joy :-(