Bug? Units VBA macro turns on Scene Reflections and Shadows

Programming and macros
User avatar
loeb
Posts: 47
Joined: Sun Jan 16, 2022 5:55 pm
Answers: 1
x 35
x 8

Bug? Units VBA macro turns on Scene Reflections and Shadows

Unread post by loeb »

I have a macro that sets the document Units the way I like them, but it has the strange side effect of turning on the Scene Shadows and Reflections in all the inactive configurations. Does anyone have any idea why this might be or is it a bug?

Code: Select all

Option Explicit
Sub main()
    Dim swApp                       As SldWorks.SldWorks
    Dim swModel                     As SldWorks.ModelDoc2
    Dim BoolStatus                  As Boolean
    
    Dim SystemOfUnits               As Integer
    Dim DualSystemOfUnits           As Integer
    Dim PrimaryLengthDecPlaces      As Integer
    Dim AngularUnits                As Integer
    Dim MassDecPlaces               As Integer
    Dim DualLengthDecPlaces         As Integer
    Dim AngularDecPlaces            As Integer
    Dim DecimalRoundingMethod       As Integer
    Dim TimeDecPlaces               As Integer
    
    SystemOfUnits = swUnitSystem_e.swUnitSystem_IPS
    DualSystemOfUnits = swMM
    PrimaryLengthDecPlaces = 3
    DualLengthDecPlaces = 1
    AngularUnits = swDEGREES
    AngularDecPlaces = 0
    MassDecPlaces = 3
    DecimalRoundingMethod = swUnitsDecimalRounding_e.swUnitsDecimalRounding_HalfAway
    TimeDecPlaces = 2
    
    Set swApp = Application.SldWorks
    Set swModel = swApp.ActiveDoc
    If swModel Is Nothing Then
        swApp.SendMsgToUser2 "No drawing document open.", swMessageBoxIcon_e.swMbStop, swMessageBoxBtn_e.swMbOkCancel
        Exit Sub
    End If

    BoolStatus = swModel.Extension.SetUserPreferenceInteger(swUserPreferenceIntegerValue_e.swUnitSystem, 0, SystemOfUnits)
    BoolStatus = swModel.Extension.SetUserPreferenceInteger(swUserPreferenceIntegerValue_e.swUnitsDualLinear, 0, DualSystemOfUnits)
    BoolStatus = swModel.Extension.SetUserPreferenceInteger(swUserPreferenceIntegerValue_e.swUnitsLinearDecimalPlaces, 0, PrimaryLengthDecPlaces)
    BoolStatus = swModel.Extension.SetUserPreferenceInteger(swUserPreferenceIntegerValue_e.swUnitsDualLinearDecimalPlaces, 0, DualLengthDecPlaces)
    BoolStatus = swModel.Extension.SetUserPreferenceInteger(swUserPreferenceIntegerValue_e.swUnitsAngular, 0, AngularUnits)
    BoolStatus = swModel.Extension.SetUserPreferenceInteger(swUserPreferenceIntegerValue_e.swUnitsAngularDecimalPlaces, 0, AngularDecPlaces)
    BoolStatus = swModel.Extension.SetUserPreferenceInteger(swUserPreferenceIntegerValue_e.swUnitsMassPropDecimalPlaces, 0, MassDecPlaces)
    BoolStatus = swModel.Extension.SetUserPreferenceInteger(swUserPreferenceIntegerValue_e.swUnitsDecimalRounding, 0, DecimalRoundingMethod)
End Sub


User avatar
JSculley
Posts: 602
Joined: Tue May 04, 2021 7:28 am
Answers: 55
x 8
x 827

Re: Bug? Units VBA macro turns on Scene Reflections and Shadows

Unread post by JSculley »

What version of SW are you using? I tried your code with SW2017 SP5 and SW2021 SP5.1 and neither exhibited the behavior you describe.
User avatar
Stefan Sterk
Posts: 31
Joined: Tue Aug 10, 2021 2:40 am
Answers: 2
x 49
x 62

Re: Bug? Units VBA macro turns on Scene Reflections and Shadows

Unread post by Stefan Sterk »

I'm running SW2021 SP5.1 and i do get the same behavior, and not just with the API calls, it also happens when just going to ⚙️Options and click ing on the OK button does enable the floor shadow and reflection on none active configurations.
Options changes enables floor shodows and reflection for all none active configurations
Options changes enables floor shodows and reflection for all none active configurations
ryan-feeley
Posts: 81
Joined: Thu Jan 20, 2022 3:35 pm
Answers: 0
x 31
x 89

Re: Bug? Units VBA macro turns on Scene Reflections and Shadows

Unread post by ryan-feeley »

What are the settings for scene shadows and scene reflection in your *.p2s scene file?

So if you open your *.p2s scene in a text editor, say `C:\Program Files\Solidworks2020\SOLIDWORKS\data\graphics\Scenes\01 basic scenes\00 3 point faded.p2s`, what do you see? I bet the Scene Reflections and Shadows are enabled.

I've had various annoyances with SWX in the past if the scene file says one thing, or leaves something out, but my part or assembly templates say something else.

I try to just keep everything consistent, and use custom scenes as needed. I haven't run into any downstream issues with custom scenes and sharing files, etc. SWX appears to cache everything it needs inside the model file, so if the link to the custom environment goes stale, nothing bad happens. [As long as the paths to the .hdr lighting and floor appearance are still valid -- I don't customize these]. There is a document properties option to save everything scene/appearance wise inside the model file, but I haven't enabled it.

I'm curious if anyone else has similar, or different experiences.
User avatar
loeb
Posts: 47
Joined: Sun Jan 16, 2022 5:55 pm
Answers: 1
x 35
x 8

Re: Bug? Units VBA macro turns on Scene Reflections and Shadows

Unread post by loeb »

ryan-feeley wrote: Sun Feb 27, 2022 3:33 pm What are the settings for scene shadows and scene reflection in your *.p2s scene file?
...
I'm curious if anyone else has similar, or different experiences.
Ryan, I didn't think about looking there because I really don't mess with scenes unless I'm trying to render and that very infrequent for me. If I get around to exploring that, I'll share with you what I learn.
Post Reply