How to Retrieve Item Descriptions Using the Client API with Python?
A
Anton Ahl
started a topic
16 days ago
Running the code snippet below prints the names of all the parts in the item, but how do I get the item descriptions of all the parts?
import SystemWeaver as sw
import SystemWeaverAPI as swa
...
handle = sw.Common.SWHandleUtility.ToHandle(handle_str)
item = swa.SWConnection.Instance.Broker.GetItem(handle)
parts = item.GetAllParts()
for part in parts:
print(part.Name) # How to get the item plain text descriptions for all parts?
To clarify, the text that would appear in this box in the GUI:
Best Answer
S
SystemWeaver Support
said
8 days ago
Hi Anton,
Try this out and see if it can work for you:
For part in parts:
print(SWDescription.DescriptionToPlainText(IswItem(IswPart(part).DefObj).Description, swa.SWConnection.Instance.Broker))
This should print the item Descriptions of all the parts' items.
Yes, thanks. There seems to be a problem with part.DefObj though. Printing at each step in the code yields this:
import SystemWeaver as sw
import SystemWeaverAPI as swa
...
handle = sw.Common.SWHandleUtility.ToHandle(handle_str)
item = swa.SWConnection.Instance.Broker.GetItem(handle)
print(item)
parts = item.GetAllParts()
print(parts)
for part in parts:
print(part)
print(part.DefObj)
print(item)
=> SystemWeaver.ClientAPI.API.TswLibraryItem
print(parts)
=> SystemWeaver.Common.TswParts
print(part)
=> SystemWeaver.ClientAPI.API.TswPart
print(part.DefObj)
=> AttributeError: 'IswObject' object has no attribute 'DefObj'
SystemWeaver Support
said
11 days ago
Hi Anton,
part.DefObj returns a generic IswObj, because we don't know which DefObj the part has. But if you are just going through items, you can cast the part.DefObj to IswItem and then get the description.
Hopefully this can be helpful.
SystemWeaver Support
A
Anton Ahl
said
10 days ago
Sure but the problem I have is that running part.DefObj does not return a generic IswObject; instead, it raises the error: AttributeError: 'IswObject' object has no attribute 'DefObj'.
Anton Ahl
Running the code snippet below prints the names of all the parts in the item, but how do I get the item descriptions of all the parts?
To clarify, the text that would appear in this box in the GUI:
Hi Anton,
Try this out and see if it can work for you:
This should print the item Descriptions of all the parts' items.
SystemWeaver Support
- Oldest First
- Popular
- Newest First
Sorted by Oldest FirstSystemWeaver Support
Hi Anton,
To be able to get the item Descriptions of all the parts to print, you can test out the below code:
You can also read more about how to work with Descriptions in one of our articles: Introduction to the SystemWeaver API in C# : SystemWeaver
If you are interested in learning more, we offer SystemWeaver API training classes which you can read more about here: Interested in SystemWeaver API Training? : SystemWeaver
I hope this information could be helpful.
SystemWeaver Support
Anton Ahl
Yes, thanks. There seems to be a problem with part.DefObj though. Printing at each step in the code yields this:
SystemWeaver Support
Hi Anton,
part.DefObj returns a generic IswObj, because we don't know which DefObj the part has. But if you are just going through items, you can cast the part.DefObj to IswItem and then get the description.
Hopefully this can be helpful.
SystemWeaver Support
Anton Ahl
Sure but the problem I have is that running part.DefObj does not return a generic IswObject; instead, it raises the error: AttributeError: 'IswObject' object has no attribute 'DefObj'.
Here is what printing part outputs:
This seems strange. I would expect print(type(part)) to output <class 'SystemWeaver.Common.IswPart'>, not <class 'SystemWeaver.Common.IswObject'>.
For parts, it prints as expected:
SystemWeaver Support
Hi Anton,
Try this out and see if it can work for you:
This should print the item Descriptions of all the parts' items.
SystemWeaver Support
-
Support for Autotest of API applications
-
Major version exception in API
-
Part multiplicity exception in API
-
Get enum attribute value description
-
Detecting connection status?
-
Item type name from SID
-
Adding an existing item as part to an item using C# API
-
Last Changed date isn't updating
-
Script filer och API
-
How do I return a DataTable instead of IswItems?
See all 19 topics