Re: [QGIS-Developer] import 3d or _3d in python?

2022-10-04 Thread Raymond Nijssen via QGIS-Developer

Done:
https://github.com/qgis/pyqgis/issues/97

Raymond



On 03-10-2022 10:24, Martin Dobias wrote:

Hi Raymond

The general idea is that for every PyQGIS module (e.g. "core") there is 
a compiled python module (e.g. _core.so) and a directory acting as a 
module ("core") which imports the compiled module and adds some extra 
functionality (docstrings and more). So normally one wants to use import 
qgis.core instead of qgis._core.


Now with the 3d module things are not so great, because "3d" is not a 
valid module name because of the leading digit, so import qgis.3d simply 
won't work. There are some ways to work it around [1], but I wouldn't 
recommend using them. But as stated earlier, importing qgis._3d should 
generally do the job.


It is probably worth creating a ticket to address this, but I am not 
sure how to best fix it - probably the whole module should be renamed so 
avoid the leading digit - e.g. "threed"


[1] 
https://stackoverflow.com/questions/9090079/in-python-how-to-import-filename-starts-with-a-number 



Cheers
Martin


On Mon, Oct 3, 2022 at 8:58 AM Raymond Nijssen via QGIS-Developer 
mailto:qgis-developer@lists.osgeo.org>> 
wrote:



While trying to import a 3D class in a python script, I found out that
the code in the pyqgis docs is not working (for me):

from qgis.3d import QgsLayoutItem3DMap


Instead I need to add an underscore for the 3d module name:

from qgis._3d import QgsLayoutItem3DMap



Should this be fixed in the documentation? I'm not all sure, cause when
trying to fix it, I found this related commit:


https://github.com/qgis/pyqgis/commit/1ac564790aa0b7abbd003c04d07358d8e4f14493





This is the page in the docs:
https://qgis.org/pyqgis/master/3d/QgsLayoutItem3DMap.html



Should I make an issue? It took me a while to figure out that _3d
solution.

Cheers,
Raymond
___
QGIS-Developer mailing list
QGIS-Developer@lists.osgeo.org 
List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer

Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer



___
QGIS-Developer mailing list
QGIS-Developer@lists.osgeo.org
List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer


Re: [QGIS-Developer] import 3d or _3d in python?

2022-10-03 Thread Andrea Giudiceandrea via QGIS-Developer

Il 03/10/2022 09:19, Raymond Nijssen via QGIS-Developer ha scritto:
I know, but my script is not running in the console. It is part of a 
plugin, so I need to do the import. Would be handy if the 
documentation tells me how to do it.


Yes, I understood that. I just wanted to point out that QGIS itself 
imports the 3d library using qgis._3d, so it should be the correct 
module name to use.


Best regards.

Andrea
___
QGIS-Developer mailing list
QGIS-Developer@lists.osgeo.org
List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer


Re: [QGIS-Developer] import 3d or _3d in python?

2022-10-03 Thread Martin Dobias via QGIS-Developer
Hi Raymond

The general idea is that for every PyQGIS module (e.g. "core") there is a
compiled python module (e.g. _core.so) and a directory acting as a module
("core") which imports the compiled module and adds some extra
functionality (docstrings and more). So normally one wants to use import
qgis.core instead of qgis._core.

Now with the 3d module things are not so great, because "3d" is not a valid
module name because of the leading digit, so import qgis.3d simply won't
work. There are some ways to work it around [1], but I wouldn't recommend
using them. But as stated earlier, importing qgis._3d should generally do
the job.

It is probably worth creating a ticket to address this, but I am not sure
how to best fix it - probably the whole module should be renamed so avoid
the leading digit - e.g. "threed"

[1]
https://stackoverflow.com/questions/9090079/in-python-how-to-import-filename-starts-with-a-number

Cheers
Martin


On Mon, Oct 3, 2022 at 8:58 AM Raymond Nijssen via QGIS-Developer <
qgis-developer@lists.osgeo.org> wrote:

>
> While trying to import a 3D class in a python script, I found out that
> the code in the pyqgis docs is not working (for me):
>
> from qgis.3d import QgsLayoutItem3DMap
>
>
> Instead I need to add an underscore for the 3d module name:
>
> from qgis._3d import QgsLayoutItem3DMap
>
>
>
> Should this be fixed in the documentation? I'm not all sure, cause when
> trying to fix it, I found this related commit:
>
>
> https://github.com/qgis/pyqgis/commit/1ac564790aa0b7abbd003c04d07358d8e4f14493
>
>
>
> This is the page in the docs:
> https://qgis.org/pyqgis/master/3d/QgsLayoutItem3DMap.html
>
>
> Should I make an issue? It took me a while to figure out that _3d solution.
>
> Cheers,
> Raymond
> ___
> QGIS-Developer mailing list
> QGIS-Developer@lists.osgeo.org
> List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
> Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer
>
___
QGIS-Developer mailing list
QGIS-Developer@lists.osgeo.org
List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer


Re: [QGIS-Developer] import 3d or _3d in python?

2022-10-03 Thread Raymond Nijssen via QGIS-Developer

Hi Andrea,

I know, but my script is not running in the console. It is part of a 
plugin, so I need to do the import. Would be handy if the documentation 
tells me how to do it.


Kind regards,
Raymond


On 03-10-2022 09:02, Andrea Giudiceandrea via QGIS-Developer wrote:

Il 03/10/2022 08:57, Raymond Nijssen via QGIS-Developer ha scritto:


Instead I need to add an underscore for the 3d module name:

from qgis._3d import QgsLayoutItem3DMap


In the Python console, the 3d library is automatically imported (if QGIS 
is compiled with 3d support) with:


from qgis._3d import *

See: 
https://github.com/qgis/QGIS/blob/95e00c50d219b39b2571dd6bff59a1393deb9b6a/python/console/console_sci.py#L59 



Best regards.

Andrea Giudiceandrea
___
QGIS-Developer mailing list
QGIS-Developer@lists.osgeo.org
List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer

___
QGIS-Developer mailing list
QGIS-Developer@lists.osgeo.org
List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer


Re: [QGIS-Developer] import 3d or _3d in python?

2022-10-03 Thread Andrea Giudiceandrea via QGIS-Developer

Il 03/10/2022 08:57, Raymond Nijssen via QGIS-Developer ha scritto:


Instead I need to add an underscore for the 3d module name:

from qgis._3d import QgsLayoutItem3DMap


In the Python console, the 3d library is automatically imported (if QGIS 
is compiled with 3d support) with:


from qgis._3d import *

See: 
https://github.com/qgis/QGIS/blob/95e00c50d219b39b2571dd6bff59a1393deb9b6a/python/console/console_sci.py#L59


Best regards.

Andrea Giudiceandrea
___
QGIS-Developer mailing list
QGIS-Developer@lists.osgeo.org
List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer