Page 1 of 1

Variable boolstatus for InsertMateReference

Posted: Thu Oct 26, 2023 1:41 am
by senuba
Hello
I've recorded a macro. It creates a Mate Reference based on selected surfaces using boolstatus. What I want is to select the surfaces by clicking and then create the Mate Reference. Since I'll be applying this to multiple parts, the constants within boolstatus need to be changed. Thank you in advance for your help

Code: Select all

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

Sub main()
Set swApp = Application.SldWorks
Set Part = swApp.ActiveDoc
boolstatus = Part.Extension.SelectByRay(3.90459275934063E-03, 1.74419775687511E-02, -4.00804859780806E-02, 0.719981793085169, -0.488420146094646, 0.493023304230895, 3.8791577729578E-04, 1, True, 1, 0)
boolstatus = Part.Extension.SelectByRay(6.37084061600035E-03, 1.36439426446486E-02, -3.99999999999636E-02, 0.719981793085169, -0.488420146094646, 0.493023304230895, 3.8791577729578E-04, 2, True, 2, 0)
boolstatus = Part.Extension.SelectByRay(-8.83375323485325E-03, 8.12187193855607E-03, -7.99928660113096E-02, 0.719981793085169, -0.488420146094646, 0.493023304230895, 3.8791577729578E-04, 2, True, 4, 0)
Dim myFeature As Object
Set myFeature = Part.FeatureManager.InsertMateReference2("Varsayılan", Nothing, 0, 0, False, Nothing, 2, 0, False, Nothing, 3, 0)
Part.ClearSelection2 True
End Sub

Re: Variable boolstatus for InsertMateReference

Posted: Thu Oct 26, 2023 12:54 pm
by JSculley
If you want to preselect geometry and then run you macro, those lines aren't needed. Instead, you need to set the mark for each of your selections so that they have the correct values for your primary, secondary and tertiary selections. Delete those three lines and replace them with this:

Code: Select all

Dim selMgr As SelectionMgr
Set selMgr = Part.SelectionManager
boolstatus = selMgr.SetSelectedObjectMark(1, 1, swSelectionMarkAction_e.swSelectionMarkSet)
boolstatus = selMgr.SetSelectedObjectMark(2, 2, swSelectionMarkAction_e.swSelectionMarkSet)
boolstatus = selMgr.SetSelectedObjectMark(3, 4, swSelectionMarkAction_e.swSelectionMarkSet)
This assumes that you are selecting the entities in order (primary, secondary, tertiary).

Re: Variable boolstatus for InsertMateReference

Posted: Fri Oct 27, 2023 1:13 am
by senuba
JSculley wrote: Thu Oct 26, 2023 12:54 pm If you want to preselect geometry and then run you macro, those lines aren't needed. Instead, you need to set the mark for each of your selections so that they have the correct values for your primary, secondary and tertiary selections. Delete those three lines and replace them with this:

Code: Select all

Dim selMgr As SelectionMgr
Set selMgr = Part.SelectionManager
boolstatus = selMgr.SetSelectedObjectMark(1, 1, swSelectionMarkAction_e.swSelectionMarkSet)
boolstatus = selMgr.SetSelectedObjectMark(2, 2, swSelectionMarkAction_e.swSelectionMarkSet)
boolstatus = selMgr.SetSelectedObjectMark(3, 4, swSelectionMarkAction_e.swSelectionMarkSet)
This assumes that you are selecting the entities in order (primary, secondary, tertiary).
You are amazing. Its wonderful for me. Thanks a lot.