AnsweredAssumed Answered

AddComponent5 Not Fixed to Origin

Question asked by Aaron Heathcote on Nov 1, 2016
Latest reply on Nov 4, 2016 by Aaron Heathcote

I am building a standalone application in vb.net and I am having some difficulties adding a component in the correct position.

InsertComponent.png

When adding a part to an assembly within SolidWorks, if you just hit the green tick then the component will be fixed in position (front plane of part to front plane of assembly, top plane of part to top plane of assembly and then right plane of part to right plane of assembly).

This is what I am trying to achieve but when I use AddComponent5 then the part I am putting into the assembly is fixed by the centre of the part to the origin of the assembly instead of the origin of part to origin of assembly.

PartInserted.png

As you can see above, the top origin is the origin of the assembly and the bottom is the origin of the part & the centre of the part is fixed to the assembly origin.

 

My Code:

        'Make Assemblies

        Dim Asm As IModelDoc2

        Dim AsmDoc As IAssemblyDoc

        Dim InsertComponent As Component2

        Dim asmTemplate As String

        asmTemplate = swApp.GetUserPreferenceStringValue(swUserPreferenceStringValue_e.swDefaultTemplateAssembly)

        Asm = CType(swApp.NewDocument(asmTemplate, 0, 0, 0), ModelDoc2)

        Asm = CType(swApp.ActiveDoc, ModelDoc2)

        AsmDoc = Asm

 

        Dim Post1Part As String

        Post1Part = A123456-1111-1@Assem1

 

 

        InsertComponent = AsmDoc.AddComponent5(Form2.FileLocation & Form2.JobNumber & "-" & Form2.LineNumber & "111.SLDPRT", swAddComponentConfigOptions_e.swAddComponentConfigOptions_CurrentSelectedConfig, "", False, "", 0, 0, 0)

        Asm.Extension.SelectByID2(Post1Part, "COMPONENT", 0, 0, 0, False, 0, Nothing, 0)

        AsmDoc.UnfixComponent()

        Asm.ClearSelection2(True)

 

The reason I have used AddComponent5 is because it allows the insert of components without having the components open, maybe there is another method?

Also I know that I have specified the position by defining the coordinates as 0,0,0 but what I'm wondering is is there a better way to insert the components and have them mated to the origin?


Currently my code inserts the part, then floats it, then my next move would be to mate front to front, top to top and right to right. Seems like unnecessary code but couldn't find a way to make this automatic on import.

 

Any help would be greatly appreciated.

Outcomes