API 2 check node type in external Python module

API 2 check node type in external Python module

j.kaestle
Enthusiast Enthusiast
1,047 Views
6 Replies
Message 1 of 7

API 2 check node type in external Python module

j.kaestle
Enthusiast
Enthusiast

Hi,

I am writing an external Python module in which I want to check the type of the selected node.

'if node.isType(vrdTransformNode)' works fine in the VRED Script Editor.  When using the external module, I get the error that "vrdTransformNode" is not defined. What must I add to the script, to make object types known.
 
Thanks a lot
 
Jochen
0 Likes
1,048 Views
6 Replies
Replies (6)
Message 2 of 7

Christian_Garimberti
Advisor
Advisor

Hi, try to use node.isType(vrKernelServices.vrdTransformNode)

or maybe just importing vrKernelServices before, but i never tried

 

Best

Chris

Christian Garimberti
Technical Manager and Visualization Enthusiast
Qs Informatica S.r.l. | Qs Infor S.r.l. | My Website
Facebook | Instagram | Youtube | LinkedIn

EESignature

Message 3 of 7

j.kaestle
Enthusiast
Enthusiast

Hi,
thank you fro the hint. 'node.isType(vrKernelServices.vrdTransformNode)' also doesn't work. I still get  the error message "NameError: name 'vrKernelServices' is not defined. Did you mean: 'vrMaterialService'?"


Regarding this discussion, it is not recommended to import the services:

Solved: Python Plugin: import vrKernelServices.vrUVService - Autodesk Community - VRED

 

My workaround now is to use

if (str(type(node)) == '<class \'vrKernelServices.vrdTransformNode\'>')

 

Best

Jochen

0 Likes
Message 4 of 7

Christian_Garimberti
Advisor
Advisor

Hi, i made some easy test and it worked for me... in both the Script Editor and as a Script Plugin, without importing the vrKernelService.

i'm working in VRED PRo 2024.2.1. Which version are you using? Maybe older version it doesn't works.

Christian_Garimberti_0-1707746191489.png

I tried with this in the script editor

def testvrKernelServices2():
    node = vrScenegraphService.getSelectedNode()
    print(node.isType(vrKernelServices.vrdTransformNode))
    
testvrKernelServices2()

And this in a script plugin

from PySide6 import QtCore, QtGui, QtWidgets
    
class testDialog(QtWidgets.QDialog):
    def __init__(self, parent=None):
        super(testDialog, self).__init__(parent)
        self.setWindowTitle('Test')
        boxlayout = QtWidgets.QGridLayout(self)
        self.setLayout(boxlayout)
        
        self.TestButton = QtWidgets.QPushButton("Test")
        self.TestButton.clicked.connect(self.testvrKernelServices)
        boxlayout.addWidget(self.TestButton, 0, 1)
        
    def testvrKernelServices(self):
        node = vrScenegraphService.getSelectedNode()
        print(node.isType(vrKernelServices.vrdTransformNode))
        
myTestDialog = testDialog(VREDPluginWidget)
myTestDialog.show()

 Best

Chris

Christian Garimberti
Technical Manager and Visualization Enthusiast
Qs Informatica S.r.l. | Qs Infor S.r.l. | My Website
Facebook | Instagram | Youtube | LinkedIn

EESignature

0 Likes
Message 5 of 7

j.kaestle
Enthusiast
Enthusiast

Hi,

I work with VRED 2024.2

The whole thing is strange. If I start VRED and test it in an empty scene it is working.
If I load my scene, which loads the external modules, it fails:

jkaestle_0-1707749970132.png

I will analyze my modules and try to find the cause. If I find it, I will tell you.

 

Best

Jochen

0 Likes
Message 6 of 7

Christian_Garimberti
Advisor
Advisor

Hi, maybe you found a bug...

If you put this code in the script editor of new scene just after the Vred Startup, it works.

If you load something new, or create a news cene, it does not work anymore.

def testvrKernelServices2():
    node = vrScenegraphService.getSelectedNode()
    print(node.isType(vrKernelServices.vrdTransformNode))
testvrKernelServices2()

Working with script plugins works everytime.

Maybe someone from Autodesk could give a check.

@__daniel.lincoln__ 

 

best

Chris

 

Christian Garimberti
Technical Manager and Visualization Enthusiast
Qs Informatica S.r.l. | Qs Infor S.r.l. | My Website
Facebook | Instagram | Youtube | LinkedIn

EESignature

Message 7 of 7

Eduardt_AlbergEZ998
Participant
Participant

Hi,

i also tested it and it is weird that its working after vred startup. You have to import the vrKernelServices or you just import the classes you need from the vrKernelServices, just like this:

from vrKernelServices import vrdTransformNode
    
def testvrKernelServices2():
    node = vrScenegraphService.getSelectedNode()
    print(node.isType(vrdTransformNode))
testvrKernelServices2()

But be careful. Most classes can be imported normally, classes with a service at the end, such as vrNodeService or vrMaterialService should not be imported in this way, as these are already instantiated in VRED and you replace this instance with the class if you import them in this way.

0 Likes