VRED-python code Disappear

VRED-python code Disappear

tg_kim
Contributor Contributor
1,698 Views
5 Replies
Message 1 of 6

VRED-python code Disappear

tg_kim
Contributor
Contributor

hi

im using the external python file, Qt designer UI and VRED-python API.

 

When i used to vrNotePtr Module in external python file, they didn't have Attribute.

 

Terminal Error messages were "AttributeError: module 'vrNodePtr' has no attribute 'getNChildren", 

AttributeError: module 'vrNodePtr' has no attribute 'getChild' etc......

 

most of all, When i use to vrNodeService Module, vrdNode Module, pop-up UI was disappear.

 

could you show me a way to appear and the Attribute error reason? 

 

0 Likes
Accepted solutions (1)
1,699 Views
5 Replies
Replies (5)
Message 2 of 6

Christian_Garimberti
Advisor
Advisor

Hi @tg_kim, i think you are mixing API v1 and v2 together.

vrNodePtr is from v1 and should have getChild and getNChildren. But maybe it is an invalid node, so better is if you try with .isValid() to check it.

vrNodeService is from APIv2 and you don't need to import in external scripts, so you have to remove it from the import line you wrote.

 

Note that you have to correctly manage API v1 and v2 while working with nodes:

if you want to use v1 to access a node, for example, you have to use vrScenegraph.getSelecteNode(), and it return a vrNodePtr

instead with API v2 you can use vrScenegraphService.getSelectedNode(), returning a vrdNode

you can also convert, if necessary nodes from v1 to v2 or viceversa, like written in the python help.

 

To explicitly convert a vrdNode to a vrNodePtr object:

oldNodePtr = toNode(newVRDObject.getObjectId())

You can also convert a vrNodePtr to vrdNode:

newVRDObject = vrNodeService.getNodeFromId(oldNodePtr.getID())

 

But if you need more precise help, could you share a sample of your python?

 

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 3 of 6

tg_kim
Contributor
Contributor

thanks your reply!
When i checked the VRED-python API v1 document,
getChild, getNChildren methods were there.
why don't use the getChild, getNChildren Methods? there is on paper.
so you means that i have to know the Convert rules VRED pyhton API v1 between v2? alright. i would need a much time...
how about python v1, v2 document interation plan in Autodesk? ...never?

0 Likes
Message 4 of 6

Christian_Garimberti
Advisor
Advisor
Accepted solution

I don't know Autodesk future plan... 

to manage v1 against v2 the only advice i have is to start trying to use v2, and if not possible (not all the modules are present in v2) convert and use the v1.

For some reference you can watch some python tutorial on the Vredpro youtube channel.

https://youtube.com/playlist?list=PLWdaxAx39RiIoGxHGkXlZE8Pj6IGPTWxX&si=I3FzQdcTN9_9sebb

 

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 5 of 6

tg_kim
Contributor
Contributor

could you see my pictures?

 

left was VRED's terminal and pop-up window. right was external python script file.

im going to click to button of VRED's pop-up window, and come to error.

 

tgkimVDAQE_0-1697768208444.png

 

line 205 was come to error.

how i get the graph's child name?

0 Likes
Message 6 of 6

chr33z
Advocate
Advocate

Hi!

 

There are a few problems with this code:

1. The method "getChild()" does not work with a name as parameter. You have to put in an index (0 .... n) as parameter. 2. The method "getChild()" has to be called on the object "a", which is of type "vrdNode" So this would work:

 

def update_button():
    a = vrNodeService.findNode("Root")
    print(a.getName())
    eee = a.getChild(0)
    print(eee.getName())

 

When you want to find a child of vrdNode "a" by name you will have to do something like this:

 

def update_button():
    a = vrNodeService.findNode("Root")
    print(a)
    
    for index in range(a.getChildCount()):
        child = a.getChild(index)
        
        if child.getName() == "Perspective":
            print("Yeah")
    
update_button()

 

Hope I could help! Best, Christopher