Importing Custom Classes

Ask your PowerShell-related questions, including questions on cmdlet development!
Forum rules
Do not post any licensing information in this forum.

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 7 years and 6 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.
Locked
User avatar
ISAssets
Posts: 10
Last visit: Wed Mar 27, 2024 6:25 pm

Importing Custom Classes

Post by ISAssets »

Product, version and build: PowerShell Studio 2015 4.2.89
32 or 64 bit version of product: 64 bit
Operating system: Windows 10
32 or 64 bit OS: 64 bit
PowerShell Version: 5

I've created a class which contains the properties and methods that I want to use in form.

Can you please advise how I import my class so that I call the methods and get/set the properties from the form?

Thanks
DevinL
Posts: 1098
Last visit: Tue Jun 06, 2017 9:15 am

Re: Importing Custom Classes

Post by DevinL »

Before I help I have a follow-up question to clarify what exactly you're asking.

Are you wanting to know how to import the class object just for the form or were you wanting to see it in PrimalSense?
DevinL
SAPIEN Technologies, Inc.
User avatar
ISAssets
Posts: 10
Last visit: Wed Mar 27, 2024 6:25 pm

Re: Importing Custom Classes

Post by ISAssets »

I'm using PowerShell Studio.

I want to be able to access it from code file behind the form so I can write some front end specific logic into the form code file.

With Visual Studio I'd add the class to the project and put in a using statement in form's code file.

Not sure how to do here.
DevinL
Posts: 1098
Last visit: Tue Jun 06, 2017 9:15 am

Re: Importing Custom Classes

Post by DevinL »

[TOPIC MOVED TO WINDOWS POWERSHELL FORUM BY MODERATOR]
DevinL
SAPIEN Technologies, Inc.
DevinL
Posts: 1098
Last visit: Tue Jun 06, 2017 9:15 am

Re: Importing Custom Classes

Post by DevinL »

In that case, this is a general PowerShell question as opposed to a product specific question and so I've moved the topic to the Windows PowerShell forum.
DevinL
SAPIEN Technologies, Inc.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Importing Custom Classes

Post by jvierra »

We do not add classes to projects. You can place your class in a PS1 file and dot source it. It will be available. JUst use it as you would in PowerShell.

PowerShell Forms do not use "Code Behind" that requires a compiler. The code in a PS form i just a bunch of snippets assigned to events or stored within the form function.


You can also just paste your class into the editor as if it was a function.

If a project paste the class in the globals file.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Importing Custom Classes

Post by jvierra »

Her is an example of using a class in a form:
Attachments
Test-Class.psf
(22.77 KiB) Downloaded 149 times
This topic is 7 years and 6 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.
Locked