Skip to main content
Known Participant
Oct 16, 2023 1:28 PM UTC
Open for Voting

obtain child comment graph pos

could you add a method so we can obtain a child comment's graph position?

 

i have this plugin that when placing entities(nodes/objects) in scene, it first checks if an entity is selected, if so, it offsets the new entity from that. however when it comes to offsetting something from a selected comment thats a child of a node, then the newly placed entity is badly offset due to the child comment's pos being based off the nodes coordinate system rather than the graphs.

 

regards,

phil

2 replies

phil81334Author
Known Participant
Oct 17, 2023 2:37 PM UTC

ty, hopefully a more robust method would be implemented in future.

 

regards,

phil

Translate
Cyril Dellenbach
Community Manager
Community Manager
Oct 17, 2023 12:44 PM UTC

Hi Phil,

 

The idea is to use the position of the node + the comment's offset.

 

import sd
from sd.api.sdbasetypes import float2
​
app = sd.getContext().getSDApplication()
ui_mgr = app.getQtForPythonUIMgr()
graph = ui_mgr.getCurrentGraph()
​
node = graph.getNodes()[0]
node_pos = node.getPosition()
​
obj = graph.getGraphObjects()[0]
obj_pos_relative = obj.getPosition()
​
obj_pos = float2(
	node_pos.x + obj_pos_relative.x,
	node_pos.y + obj_pos_relative.y
	)
​
print("Node position - " + str(node_pos))
print("Comment position (relative) - " + str(obj_pos_relative))
print("Comment position (absolute) - " + str(obj_pos))


Note that this will work only with a single node graph, and this node must have a comment.

Best regards,

Translate
Cyril Dellenbach (Micro) | Product Manager | Substance Painter