Fonction InsertMoveCopyBody2

Hello

I am looking to move my piece represented by the name scale1 of a created point (point1) on the original coordinate system

I select the 3 entities but when my function executes nothing happens

can you help me

Thank you very much

Part.ClearSelection2 True
boolstatus = Part.Extension.SelectByID2("Scale1", "BODYFEATURE", 0, 0, 0, False, 1, Nothing, 0)
boolstatus = Part.Extension.SelectByID2("Point1", "DATUMPOINT", 0, 0, 0, True, 2, Nothing, 0)
boolstatus = Part.Extension.SelectByID2("Point1@Origine", "EXTSKETCHPOINT", 0, 0, 0, True, 3, Nothing, 0)


Dim myFeature As Object

Set myFeature = Part.FeatureManager.InsertMoveCopyBody2(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, False, 1)

Hello, Try this:

Option Explicit
Sub main()
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swFeatData As SldWorks.MoveCopyBodyFeatureData
Dim vFeat As Variant
Dim boolstatus As Boolean

Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
boolstatus = swModel.Extension.SelectByID2("Echelle1", "BODYFEATURE", 0, 0, 0, False, 1, Nothing, 0)
Set vFeat = swModel.FeatureManager.InsertMoveCopyBody2(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, False, 1)
Set swFeatData = vFeat.GetDefinition()

boolstatus = swModel.Extension.SelectByID2("Point1", "DATUMPOINT", 0, 0, 0, False, 1, Nothing, 0)
boolstatus = swModel.Extension.SelectByID2("Point1@Origine", "EXTSKETCHPOINT", 0, 0, 0, True, 1, Nothing, 0)
swFeatData.AddMate Nothing, swMateType_e.swMateCOINCIDENT, swMateAlign_e.swMateAlignCLOSEST, 0, 0, Empty
vFeat.ModifyDefinition swFeatData, swModel, Nothing
End Sub

 

Hello

The body is well selected at the front line

macro crashes on next line

Set vFeat = swModel.FeatureManager.InsertMoveCopyBody2(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, False, 1)

 

 

Hello

Can you help me with this problem?

Thank you

 

 

Hello

Attach your file so I can test

1 Like

Hello

here is attached my macro 

 


macro4.swp

Cool. But I already have my code, so it doesn't really help me:D It's your SLDPRT file that I need.

Although the lines you added could cause problems because the variables are already defined below.

Dim swApp As Object
Dim Part As Object
Dim boolstatus As Boolean
Dim longstatus As Long, longwarnings As Long

 

Attached is my file


Part1.SLDPRT

Indeed it doesn't work.
But it's not surprising because it doesn't work by creating the function manually either.
We would have to put constraints on the entities (face/vertex) of the solid.
The other solution is to move the solid from the coordinates of the point:

Option Explicit
Sub main()
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim vFeat As Variant
Dim boolstatus As Boolean
Dim swFeat As SldWorks.Feature
Dim swRefPt As SldWorks.RefPoint
Dim swMathPt As SldWorks.MathPoint

Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
boolstatus = swModel.Extension.SelectByID2("Point1", "DATUMPOINT", 0, 0, 0, False, 1, Nothing, 0)
Set swFeat = swModel.SelectionManager.GetSelectedObject6(1, -1)
Set swRefPt = swFeat.GetSpecificFeature2
Set swMathPt = swRefPt.GetRefPoint
boolstatus = swModel.Extension.SelectByID2("Boss.-Extru.1", "SOLIDBODY", 0, 0, 0, False, 1, Nothing, 0)
Set vFeat = swModel.FeatureManager.InsertMoveCopyBody2(swMathPt.ArrayData(0), swMathPt.ArrayData(1), swMathPt.ArrayData(2), 0, 0, 0, 0, 0, 0, 0, False, 1)
End Sub