CQ-editor icon indicating copy to clipboard operation
CQ-editor copied to clipboard

FR: expose context detection

Open Andrei-Pozolotin opened this issue 4 years ago • 8 comments

similar to

if __name__ == "__main__":
   "this is main context"

cq-editor should set a global variable or an environment variable to indicate to the client script that is is being ran inside the cq-editor

that would help client libraries such as cq-parts alter rendering behavior

sure this can be done via stack traversal, but "official" integration would be better

Andrei-Pozolotin avatar Mar 23 '20 15:03 Andrei-Pozolotin

Sounds reasonable. What do you propose to put in globals? Now the __name__ is set to "temp"

adam-urbanczyk avatar Mar 23 '20 16:03 adam-urbanczyk

  1. currently cq-parts expects environment variable

https://github.com/cqparts/cqparts/blob/master/src/cqparts/display/cqparts_server.py#L22

ENVVAR_SERVER = 'CQPARTS_SERVER'
@map_environment(
    name='cqparts_server',
    order=50,
    condition=lambda: ENVVAR_SERVER in os.environ,
)
class CQPartsServerDisplayEnv(DisplayEnvironment):

https://github.com/cqparts/cqparts/blob/master/src/cqparts/display/freecad.py#L10

@map_environment(
    name="freecad",
    order=10,
    condition=lambda: 'MYSCRIPT_DIR' in os.environ,
)
class FreeCADDisplayEnv(DisplayEnvironment):
  1. so perhaps both a global variable and an environment variable are needed

  2. as for key/value, it is better be long, explicit, and specific, i.e.

CADQUERY_EDITOR_ENGINE

Andrei-Pozolotin avatar Mar 23 '20 16:03 Andrei-Pozolotin

I see that you are referring to some display functionality of CQparts. How do you want to integrate it with CQ-editor?

adam-urbanczyk avatar Mar 23 '20 17:03 adam-urbanczyk

I do not know. I was expecting to find some analogue to show_object in cq-editor but do not see any. What would you suggest?

Andrei-Pozolotin avatar Mar 23 '20 23:03 Andrei-Pozolotin

cqparts has a display method that takes the place of show_object.

https://github.com/cqparts/cqparts/blob/3302f2ccd56b92df2c368d924e6c843330712d70/tests/t_cqparts/test_display.py#L17

jmwright avatar Mar 23 '20 23:03 jmwright

ok, either way :-)

  1. how do you see total integration of cq + cq-editor +cq-parts ?

  2. plus: does cq-editor plan to allow back propagation of user ui assembly edits back to the assembly code or json (via import/export)? https://cqparts.github.io/cqparts/doc/cqparts/import-export.html

Andrei-Pozolotin avatar Mar 23 '20 23:03 Andrei-Pozolotin

I personally would like to see the CQ ecosystem standardize on show_object.

jmwright avatar Mar 24 '20 00:03 jmwright

@Andrei-Pozolotin I think the way to go regarding CQParts support is to extend show_object (or actually the underlying method cq_utils.make_AIS ) to support CQParts objects. Relevant issue to track this is #17 .

Regarding your second point, no specific plans at the moment.

adam-urbanczyk avatar Mar 26 '20 07:03 adam-urbanczyk

Solved by #399: __name__ is set to __cq_main__

adam-urbanczyk avatar Apr 29 '23 07:04 adam-urbanczyk