By declaring variables rather than leaving them in object type (fonction_echelle as SldWorks.Feature for example) I think it will go better.
After I guess we are missing some of the code so we would have to go through it step by step to see where it gets stuck (it can come from the entity selection which is empty for example).
After that, we should check the macro references if SW2020 is listed.
According to the documentation, the InsertScale function only works on Solid or Surface Bodies. But "REFSURFACE" points to the function that created the body, not the body itself. The fact that the surface body has the same name as the function, could explain why it still worked with 2016.
This works for me in 2020:
Option Explicit
Sub main()
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swFeat As SldWorks.Feature
Dim boolstatus As Boolean
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
boolstatus = swModel.Extension.SelectByID2("Surface-Importée1", "SURFACEBODY", 0, 0, 0, False, 0, Nothing, 0)
Set swFeat = swModel.FeatureManager.InsertScale(swScaleType_e.swScaleAboutCentroid, True, 1.5, 0, 0)
End Sub
Note: the last two terms of the InsertScale function are not taken into account when the second term is "True" (uniform scale)
Hello, here is my code and my part that I am opening is an imported surface.
XT format
Sub main()
Set swApp = Application.SldWorks
Set ModelDoc = swApp.ActiveDoc
Set Part = swApp.ActiveDoc
line100: '-------------------------------------------------------------------------------------------------------------------- Dim choix_matiere As String Dim coef_echelle Ace Double choix_matiere = InputBox("What is the material? 1-APET 2-PS 3-PP") If choix_matiere = "1" Then coef_echelle = 1.004 If choix_matiere = "2" Then coef_echelle = 1.006 If choix_matiere = "3" Then coef_echelle = 1.015 If choix_matiere <> "1" And choix_matiere <> "2" And choix_matiere <> "3" Then MsgBox ("Enter either 1, 2 or 3 only") GoTo line100 End If
Creating the scale Dim myModelView As Object
boolstatus = Part.Extension.SelectByID2("Surface-Imported1", "SURFACEBODY", 0, 0, 0, False, 0, Nothing, 0) Sun fonction_echelle As SldWorks.Feature Set fonction_echelle = Part.FeatureManager.InsertScale(swScaleType_e.swScaleAboutCentroid, True, coef_echelle, coef_echelle, coef_echelle)
So what I tested and found, if the imported surface is a complex surface (i.e.: almost closed) the macro doesn't work (Set fonction_echelle returns Nothing).
By recording the macro and doing the manipulation, it does save me an equivalent code but doesn't work anymore and returns Nothing as well.
Edit: it works on an offset surface from a volume model, it doesn't work on imported surfaces. Probably a regression if it worked before.