please look at this macro: 2013 SOLIDWORKS API Help - Add Component and Mate Example (VBA)
the component is inserted using : Set swcomponent = swAssy.AddComponent5(strCompModelname, swAddComponentConfigOptions_CurrentSelectedConfig, "", False, "", -1, -1, -1)
note that part should be in SW memory before calling AddComponent5
Thanks guys for your help on this issue. I wanted to make mention that I'm just trying to insert a new part into an already existing Solidworks part. That's kind of the goal of creating this VB.NET add-in so that this process becomes automated. I'm still having issues with getting Solidworks to insert a new part. I'm a newbie at programming so any help would be greatly appreciated.
This is what I have so far in terms of my code. I created a dialog box for SW part insertion.
I have the code below linked to my "Okay" button in my VB.NET project. Can anyone tell me what exactly I'm missing to make this work?
Private Sub Button1_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles Button1.Click
'process the data from the User From with solidworks
Dim swcomponent As SolidWorks.Interop.sldworks.Component2
swcomponent = SwApp.AddComponent5(swAddComponentConfigOptions_e.swAddComponentConfigOptions_CurrentSelectedConfig, "", False, "", -1, -1, -1)
Me.DialogResult = System.Windows.Forms.DialogResult.OK
Isn't that method for adding parts to assemblies?
have you looked into InsertPart2?
what error are you getting?
Also, have you considered using the MenuStrip control in place of those buttons?
It'll free up real estate on the form and it'll allow you to add more methods of your own if you decide to expand your applications.
(i think it looks more professional and predictable to the user)
Do you need that cancel button?
Sorry, not trying to nitpick.
It's been my experience that you do not give users the ability to cancel something that must run.
If all the button does is close the application, then delete it because you already have that little "X" up to the right.
(i usually disable that little "x" because i like to e in control of how my code exits)
Thanks for replying to my thread. You're right, there are a lot of things in terms of the overall layout and look of the dialog box that could use updating. I'd like to get around to fixing those issues but at the moment I'm more concerned with the overall functionality of this add-in. In other words, I would just like this thing to finally run, lol. Does anyone know the VB.NET code in order to Insert a New Part into an open Model template - not an Assembly - in SolidWorks? And where exactly would this code be placed in a VB.NET project? I am currently using Visual Studio Community 2015 Edition - with an installed VB.NET Solidworks Standard template. I've tried searching webpage after webpage, online looking for more detailed information on how to Insert a new part into an existing Model, using VB.NET. Unfortunately, I have found little to nothing to help me figure this out. I'd be eternally grateful for anyone's expertise and knowledge on this subject.
I've never done what you are asking.
What do you mean by "Model template"?
I think you mean a Part file that another Part file will be inserted into.
That would mean you are trying to replicate the Insert>Part command.
Kinda like this:
Dim swApp As Object
Dim Part As Object
Dim myFeature As Object
Set swApp = Application.SldWorks
Set Part = swApp.ActiveDoc
Set myFeature = Part.InsertPart2("C:\AwesomeWorkGoesHere\FM8432.SLDPRT", 383)
Are you after something like that?
I haven't forgotten about you and thanks for your reply to this thread. I really appreciate your help with my VB.NET project. Unfortunately, at the moment, this particular project has been put on the back-burner. Will be returning to this issue soon.
Okay All, I'm back on trying to Insert a Part into an Open Part Model in Solidworks. I've been able to click on the "Insert New Part Into Existing Configuration" and an Open Dialog Box will appear but when I go to Select a .Sldprt file to open. Nothing appears in my SolidWorks template no new part...
Does anyone know if I'm missing something in my code? Confused as to what the problem could be? Would be very appreciative for any help I can get on this issue. Thanks again.
Any ideas as to what needs to be fixed with this VB.NET Addin? I could really use some expert advice at the moment..