geosoft.gxpy.view.View.gxview.move_group_to_folder_2d always raises 'Could not find group'
I would like to use folders in a map, therefore I would like to use move_group_to_folder_2d. Either I am misusing the method move_group_to_folder_2d or it's bugged. Below minimal reproducable example.
from pathlib import Path
from geosoft import gxpy
from geosoft.gxpy import (group as gxgroup,
map as gxmap,
view as gxview,
)
with gxpy.gx.GXpy(suppress_progress=True):
map_name = str(Path('map_name').absolute())
with gxmap.Map.new(map_name, overwrite=True, ) as gmap:
with gxview.View.new(gmap, 'view_name') as view:
with gxgroup.Draw(view, name='group_name') as group:
p1 = (0,0)
p2 = (1,1)
group.line((p1, p2))
group_number = view.gxview.find_group('group_name')
view.gxview.add_folder_2d('folder_name', '')
# all of these methods raise:
# geosoft.gxapi.GXAPIError: MoveGroupToFolder2D_MVIEW : Invalid Could not find group.
# view.gxview.move_group_to_folder_2d('view_name', group_number)
# view.gxview.move_group_to_folder_2d('folder_name', group_number)
# view.gxview.move_group_to_folder_2d('', group_number)
Comments
-
@EmilNielsen @beckybodger1 are any of you able to jump in here?
0 -
Hi @VictorSavenije. This is arguably a bug but I can provide a workaround. The bug itself is that while "gxgroup.Draw" does indeed create the group, it does not update the backing tree representing the folder structure the Map Manager.
The only way to update this backing tree is to use the GXEMAP class from gxapi folder. FYI in case youre wondering, you can think of gxpy classes as being build top and abstracting gxapi classes).
Here is my workaround:
import geosoft.gxpy as gxpy from geosoft.gxpy import group from geosoft.gxpy import map from geosoft.gxpy import view from geosoft.gxapi import GXEMAP from geosoft.gxapi import GXMAP … with gxpy.gx.gx() as gxc: gx_emap = GXEMAP.load(r'D:\SomFolder\Map1.map') gx_map = gx_emap.lock() newmap = map.Map.from_gxapi(gx_map) with view.View.new(newmap, 'view_name') as newview: with group.Draw(newview, name='group_name') as newgroup: p1 = (0,0) p2 = (1,1) newgroup.line((p1, p2)) newview.gxview.add_folder_2d('folder_name', '') gx_emap.un_lock() gx_emap.un_load_all() with map.Map.open(r'D:\SomFolder\Map1.map') as newmap: with view.View.open(newmap, 'view_name') as newview: group_number = newview.gxview.find_group('group_name') newview.gxview.move_group_to_folder_2d('folder_name', group_number)FYI @PrachiChitkara
1 -
@SerbanMarin1 I replied to your answer on github, to me seems to be the best place to talk about bugs.
0


