AnsweredAssumed Answered

Inserting a library feature part into a part

Question asked by Nick Hayman on Mar 23, 2014
Latest reply on May 19, 2016 by Joe C.

Hello,

 

I have a question about the macro i recorded a moment ago.

 

The macro should take a library feature part and insert it onto a plane within a part. The reference point is the origin. So why does this not work?

 

Im new to this so please go easy on me! Any help welcome. See code below:

 

Sub main()

 

Set swApp = _
Application.SldWorks

 

Set Part = swApp.ActiveDoc
boolstatus = Part.Extension.SelectByID2("Front Plane", "PLANE", 1.45181545719948E-02, 0.01084930684622, 0, False, 0, Nothing, 0)
boolstatus = Part.Extension.SelectByID2("Point1@Origin", "EXTSKETCHPOINT", 0, 0, 0, True, 0, Nothing, 0)
Set Part = swApp.OpenDoc6("C:\ProgramData\SolidWorks\SolidWorks 2013\Design Library\LIBS\NH4.SLDLFP", 1, 4, "", longstatus, longwarnings)
Set Part = swApp.ActiveDoc
Dim myModelView As Object
Set myModelView = Part.ActiveView
myModelView.FrameLeft = 0
myModelView.FrameTop = 205
Set myModelView = Part.ActiveView
myModelView.FrameState = swWindowState_e.swWindowNormal
swApp.ActivateDoc2 "NH4.SLDLFP", False, longstatus
Set Part = swApp.ActiveDoc
Set Part = swApp.ActiveDoc
Set myModelView = Part.ActiveView
myModelView.FrameLeft = 0
myModelView.FrameTop = 21
Set myModelView = Part.ActiveView
myModelView.FrameState = swWindowState_e.swWindowMaximized
swApp.ActivateDoc2 "PART1111", False, longstatus
Set Part = swApp.ActiveDoc
Set Part = swApp.ActiveDoc
Set myModelView = Part.ActiveView
myModelView.FrameLeft = 0
myModelView.FrameTop = 205
Set myModelView = Part.ActiveView
myModelView.FrameState = swWindowState_e.swWindowMaximized
Part.ClearSelection2 True
boolstatus = Part.Extension.SelectByID2("Point1@Origin", "EXTSKETCHPOINT", 0, 0, 0, True, 0, Nothing, 0)
boolstatus = Part.Extension.SelectByID2("Point1@Origin", "EXTSKETCHPOINT", 0, 0, 0, True, 0, Nothing, 0)
Part.ClearSelection2 True
Part.ClearSelection2 True
boolstatus = Part.Extension.SelectByID2("Front Plane", "PLANE", 1.45181545719948E-02, 0.01084930684622, 0, False, 0, Nothing, 0)
boolstatus = Part.Extension.SelectByID2("Point1@Origin", "EXTSKETCHPOINT", 0, 0, 0, True, 1, Nothing, 0)
boolstatus = Part.InsertLibraryFeature("C:\ProgramData\SolidWorks\SolidWorks 2013\Design Library\LIBS\NH4.SLDLFP")
Part.ClearSelection2 True
Part.ClearSelection2 True
boolstatus = Part.EditRebuild3()
End Sub


Outcomes