Probleme macro sw 2018 et 2020

Hello

 

I created a simple macro in 2018 that works very well and with the new 2020 version it doesn't work anymore.

The function returns nothing  and rine does not happen

 

thank you for your help

 

Creating the scale
Dim myModelView As Object
Set myModelView = Part.ActiveView
myModelView.FrameState = swWindowState_e.swWindowMaximized
boolstatus = Part.Extension.SelectByID2("Imported-Surface1", "REFSURFACE", 0, 0, 0, True, 0, Nothing, 0)
Dim fonction_echelle As Object
Set fonction_echelle = Part.FeatureManager.InsertScale(0, True, 1.5, 1.5, 1.5)
 

Hello

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.

3 Likes

Same opinion and

Dim myModelView As SldWorks.View
1 Like

Hello

Following your answers it still doesn't work.

Do you have any other leads?

Thank you

 

 

 

Hello

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)

3 Likes

Hello

no it still doesn't work on 2020

 

Can you attach the file or a test file

Hello

I confirm that JeromeP's code works on SW2019 so should work on SW2020.

1 Like

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)

Using your code as is, it works very well for me.

Can be verified that the surface is correctly selected with:

MsgBox "Sélection: " & boolstatus

 

1 Like

Good evening

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.