picia
Mechanical
- Mar 24, 2006
- 26
hello.
I try make it but I dont know how... Below is the code macro from internet.I dont give my code because is very long... I want make that when i run it I have information for example:Select Surface. Then macro "wait" for me and I can select surface and click ok or something like that.I want make that I dont need before I run macro select the surface only when macro is runing... If You have any ideas please help me.I willby greatful for Your help...
Example code:
Sub GetXYZofSurfaceCentroid()
'***********************************
'Get XYZ coordinates of centroid and load
'them into array "XYZ"
'***********************************
Dim swApp As SldWorks.SldWorks
Dim Part As SldWorks.ModelDoc2
Dim SelMgr As SldWorks.SelectionMgr
Dim boolstatus As Boolean
Dim longstatus As Long, longwarnings As Long
Dim Feature As SldWorks.Feature
Dim MathPoint As SldWorks.MathPoint
Dim RefPoint As SldWorks.RefPoint
Dim vRefPointFeatureArray As Variant
Dim XYZ As Variant
Set swApp = Application.SldWorks
Set Part = swApp.ActiveDoc
Set SelMgr = Part.SelectionManager
'If SelMgr.GetSelectedObjectCount2(-1) <> 1 Then
' MsgBox "You must select a single face/surface for this macro."
' Exit Sub
'ElseIf SelMgr.GetSelectedObjectType3(1, -1) <> swSelFACES Then
' MsgBox SelMgr.GetSelectedObjectType3(1, -1)
' MsgBox "You must select a single face/surface for this macro."
' Exit Sub
'End If
vRefPointFeatureArray = Part.FeatureManager.InsertReferencePoint(4, 0, 0.01, 1)
Set Feature = vRefPointFeatureArray(0)
Set RefPoint = Feature.GetSpecificFeature2
Set MathPoint = RefPoint.GetRefPoint
XYZ = MathPoint.ArrayData
Set MathPoint = Nothing
Set RefPoint = Nothing
Set Feature = Nothing
'Part.Extension.DeleteSelection2 (2)
MsgBox "X: " & XYZ(0) * 1000 & vbCrLf & "Y: " & XYZ(1) * 1000 & vbCrLf & "Z: " & XYZ(2) * 1000
End Sub
I try make it but I dont know how... Below is the code macro from internet.I dont give my code because is very long... I want make that when i run it I have information for example:Select Surface. Then macro "wait" for me and I can select surface and click ok or something like that.I want make that I dont need before I run macro select the surface only when macro is runing... If You have any ideas please help me.I willby greatful for Your help...
Example code:
Sub GetXYZofSurfaceCentroid()
'***********************************
'Get XYZ coordinates of centroid and load
'them into array "XYZ"
'***********************************
Dim swApp As SldWorks.SldWorks
Dim Part As SldWorks.ModelDoc2
Dim SelMgr As SldWorks.SelectionMgr
Dim boolstatus As Boolean
Dim longstatus As Long, longwarnings As Long
Dim Feature As SldWorks.Feature
Dim MathPoint As SldWorks.MathPoint
Dim RefPoint As SldWorks.RefPoint
Dim vRefPointFeatureArray As Variant
Dim XYZ As Variant
Set swApp = Application.SldWorks
Set Part = swApp.ActiveDoc
Set SelMgr = Part.SelectionManager
'If SelMgr.GetSelectedObjectCount2(-1) <> 1 Then
' MsgBox "You must select a single face/surface for this macro."
' Exit Sub
'ElseIf SelMgr.GetSelectedObjectType3(1, -1) <> swSelFACES Then
' MsgBox SelMgr.GetSelectedObjectType3(1, -1)
' MsgBox "You must select a single face/surface for this macro."
' Exit Sub
'End If
vRefPointFeatureArray = Part.FeatureManager.InsertReferencePoint(4, 0, 0.01, 1)
Set Feature = vRefPointFeatureArray(0)
Set RefPoint = Feature.GetSpecificFeature2
Set MathPoint = RefPoint.GetRefPoint
XYZ = MathPoint.ArrayData
Set MathPoint = Nothing
Set RefPoint = Nothing
Set Feature = Nothing
'Part.Extension.DeleteSelection2 (2)
MsgBox "X: " & XYZ(0) * 1000 & vbCrLf & "Y: " & XYZ(1) * 1000 & vbCrLf & "Z: " & XYZ(2) * 1000
End Sub