Page 1 of 1

Module Aliases and Primalsense

Posted: Thu Sep 26, 2019 7:58 am
by jasonv
To help you better we need some information from you.

*** Please fill in the fields below. If you leave fields empty or specify 'latest' rather than the actual version your answer will be delayed as we will be forced to ask you for this information. ***

Product, version and build: 5.6.167
32 or 64 bit version of product: 64
Operating system: Windows 10 Professional (1809)
32 or 64 bit OS: 64

*** Please add details and screenshots as needed below. ***

I created aliases to module functions and Primalsense does not seem to pick them up.

Within the module ...
  1. Set-Alias -Name 'List-Object' -Value 'Show-Object' -Option AllScope -Force
  3. Export-ModuleMember -Function * -Alias * -Variable *
It's picking up the new and renamed functions but not the exported aliases.
2019-09-26 10_51_57-SAPIEN PowerShell Studio 2019.png
2019-09-26 10_51_57-SAPIEN PowerShell Studio 2019.png (13.91 KiB) Viewed 1609 times
The function Show-Object exists within the module.

Both of these lines should be valid. The list-object should be red to indicate an alias.

This is after a cache rebuild, module selection and cache reload.

Note: There are several aliases defined the same way that display as expected.


- Jason


Re: Module Aliases and Primalsense

Posted: Thu Sep 26, 2019 9:43 am
by brittneyr
Are the alias you added appearing in the Object Browser panel?
SPS_ObjectBrowserAlias.png (35.3 KiB) Viewed 1604 times

Re: Module Aliases and Primalsense

Posted: Thu Sep 26, 2019 11:07 am
by jasonv
I changed the Set-Alias (didn't work) to New-Alias and loaded the module in PS console.
  1. New-Alias -Name 'List-Object'       -Value 'Show-Object' -Force
As you can see from the "get-command -module" output the alias list-object exists.
CommandType     Name                                               Version    Source
-----------     ----                                               -------    ------
Alias           List-Object                                  TMCModule
It does not show up in the object browser within in the module.

It does work within the script.

Thanks. -Jason

Re: Module Aliases and Primalsense

Posted: Thu Sep 26, 2019 12:17 pm
by jasonv
I got it to work. I needed to totally remove the modules from the cache and rebuild the cache. Just reloading the modules did not work. Additionally I tried to switch back to the older module, but that didn't work either. The new functions should have turned grey when I performed a cache reload.


Re: Module Aliases and Primalsense

Posted: Mon Sep 30, 2019 9:33 am
by jasonv
Additional information ...

I have my module in the PSModulePath. I'm using folder versioning within the path like the OS. By default the latest version of the module is selected. If I want to use the previous version within Sapien PS, I cannot by just selecting it and using "Build Cache" within the Cash Editor. I would think that the functions that do not exist within the old module would be unrecognized by PrimalSense. I can use the different module versions within script by using the argument RequiredVersion with the import-module command. What I'm looking for are repeatable instructions on how to switch between different versions of a module and have PrimalSense recognize the changes. It's appears I can go forward with versions, but not in reverse using older module versions.


- Jason

Re: Module Aliases and Primalsense

Posted: Mon Sep 30, 2019 9:41 am
by brittneyr
If you build the cache from the cache editor, you will need to reload the cache from the ribbon.

The steps should be:
1. Change the version of the module in the Cache Editor.
2. Build Cache, then close the Cache Editor.
3. Reload the cache from the ribbon.
SPS_Reload-Cache.png (29.3 KiB) Viewed 1491 times

Re: Module Aliases and Primalsense

Posted: Tue Oct 01, 2019 11:01 am
by jasonv
That didn't work for reverting back to a previous module version. I think the issue has something to do with PS auto loading modules. If I'm in the console the steps are ...

1. Turn auto loading off

$ENV:PSModuleAutoloadingPreference = "none"

2. Remove the loaded module.

Remove-Module -Name <modulename> -Force

3. Load the module you need to work with.

Import-Module -Name <modulename> -RequiredVersion <version> -Force

I think Sapien PS somehow needs to emulate this.


Re: Module Aliases and Primalsense

Posted: Fri Oct 04, 2019 8:31 am
by brittneyr
Are you still unable to get the correct PrimalSense for your previous module version?
The answer I provided has to do with updating the cache to properly color your module.

As for what modules will load into scripts, the module version that is loaded when importing a module is determined by PowerShell and the environment variable PSModulePath if you don't specify a version. This is not determined by PowerShell Studio.

Re: Module Aliases and Primalsense

Posted: Tue Oct 08, 2019 7:20 am
by jasonv
To be clear, the issue I'm having is mainly adding a function to a module and having that function recognized by PrimalScript. So far I found that removing the module from the cache and then rebuilding the cache gets this working consistently.

After reviewing this article... ... yaW5nIl0=

At the very bottom it states. "Just remember, when having multiple versions of the same module, make sure to use the latest one."

Maybe you're enforcing that. The video depicts using an updated module.

My scripts are working as expected using the PSModulePath and have versioned folders under that path. I just use the -RequiredVersion argument if I want to used a former version of the module, otherwise PS always defaults to the latest version as expected.