Module Aliases and Primalsense

This forum can be browsed by the general public. Posting is limited to current SAPIEN license holders with active maintenance and does not offer a response time guarantee.
Forum rules
DO NOT POST LICENSE NUMBERS, ACTIVATION KEYS OR ANY OTHER LICENSING INFORMATION IN THIS FORUM.
Only the original author and our tech personnel can reply to a topic that is created in this forum. If you find a topic that relates to an issue you are having, please create a new topic and reference the other in your post.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 4 years and 5 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
User avatar
jasonv
Posts: 49
Last visit: Thu Sep 01, 2022 5:40 am

Module Aliases and Primalsense

Post 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
  2. 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 3687 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.

Thanks.

- Jason



DO NOT POST SUBSCRIPTIONS, KEYS OR ANY OTHER LICENSING INFORMATION IN THIS FORUM
User avatar
brittneyr
Site Admin
Posts: 1655
Last visit: Thu Mar 28, 2024 11:13 am
Answers: 39
Been upvoted: 30 times

Re: Module Aliases and Primalsense

Post by brittneyr »

Are the alias you added appearing in the Object Browser panel?
SPS_ObjectBrowserAlias.png
SPS_ObjectBrowserAlias.png (35.3 KiB) Viewed 3682 times
Brittney
SAPIEN Technologies, Inc.
User avatar
jasonv
Posts: 49
Last visit: Thu Sep 01, 2022 5:40 am

Re: Module Aliases and Primalsense

Post 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                                        2.0.0.1    TMCModule
It does not show up in the object browser within in the module.

It does work within the script.

Thanks. -Jason
User avatar
jasonv
Posts: 49
Last visit: Thu Sep 01, 2022 5:40 am

Re: Module Aliases and Primalsense

Post 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.

Thanks.
User avatar
jasonv
Posts: 49
Last visit: Thu Sep 01, 2022 5:40 am

Re: Module Aliases and Primalsense

Post 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.

Thanks.

- Jason
User avatar
brittneyr
Site Admin
Posts: 1655
Last visit: Thu Mar 28, 2024 11:13 am
Answers: 39
Been upvoted: 30 times

Re: Module Aliases and Primalsense

Post 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
SPS_Reload-Cache.png (29.3 KiB) Viewed 3569 times
Brittney
SAPIEN Technologies, Inc.
User avatar
jasonv
Posts: 49
Last visit: Thu Sep 01, 2022 5:40 am

Re: Module Aliases and Primalsense

Post 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.

Thanks.
User avatar
brittneyr
Site Admin
Posts: 1655
Last visit: Thu Mar 28, 2024 11:13 am
Answers: 39
Been upvoted: 30 times

Re: Module Aliases and Primalsense

Post 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.
Brittney
SAPIEN Technologies, Inc.
User avatar
jasonv
Posts: 49
Last visit: Thu Sep 01, 2022 5:40 am

Re: Module Aliases and Primalsense

Post 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...

http://info.sapien.com/index.php/how-to ... 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.

Thanks.
This topic is 4 years and 5 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.