Results 1 to 3 of 3

Thread: Some basic information

  1. #1
    Registered User
    Join Date
    May 2017
    Location
    Lampertheim, Germany
    Posts
    123

    Some basic information

    I think there are users which get in contact with python the first time (like me, I was always running away as I saw the strange and text-intensive code).
    That is the reason for me to write something about stumbling blocks I had reached. I hope this will aid somebody in the first steps.

    First the picky art of python with indentation:
    The mix of tab and space for indentation often leads to an "Indentation Error", so try to use only tabs or only spaces for indentation.
    Do not mix tab and space at least within a def-block.

    Next potential hurdle is the handling of global variables.
    It seems that you can read them in a def-block without usinge the "global" keyword, but if you have to change the varibles value, than you must use the "global" keyword.
    Example:
    Code:
    ...
    name=""
    ...
    def: example()
       usevar=name		# seems to work
       name="XYZ"		# seems to use a local variable named name
    Code:
    ...
    name=""
    ...
    def: example()
       global name
       usevar=name		# ok
       name="XYZ"		# this will write to the global variable named name
    Next hurdle:
    If you want to write your own lib, than you should use the "reload" mechanism because python remembers the imported libs. And if you do not reload, than changes you made during the developement are not recognized.
    During developement of a lib you should use:
    import libname; reload(libname)

    This all is really very basic, but if someone had told me, it had saved me hours on searching and "try and error" the things out.

    I will also write some hints on creating an UI with lwsdk (to find information on this is very hard)
    I will gather information on doing basic UI stuff with the lwsdk. This will coming soon.
    For example:
    How to implement mouse actions
    How to build some sort of custom buttons
    How to simplify the things with controls
    How to build some sort of "globalstore" and "globalrecall"
    How to reuse contols with tab controls (because you have to erase them during the switch to an other tab) without loosing the information in them
    As you will see, these are really basic things, but they can save you a lot of working time
    Yes, maybe there are more elegant ways to do this, but it works.

    Regards,
    KANUSO
    Last edited by KANUSO; 03-30-2018 at 04:03 AM.

  2. #2
    Kamehameha Chameleon BigHache's Avatar
    Join Date
    Sep 2006
    Location
    Future Past Life
    Posts
    1,899
    Thank you for sharing. I had run into some of the same issues but haven't looked at Python in LightWave for some time.

    Quote Originally Posted by KANUSO View Post
    First the picky art of python with indentation:
    The mix of tab and space for indentation often leads to an "Indentation Error", so try to use only tabs or only spaces for indentation.
    Do not mix tab and space at least within a def-block.
    In addition, I believe if you have written Python code in anything outside of the Python Console, and you edit that code in the Console and add tabs/spaces, they are not recognized as the same.


    Quote Originally Posted by KANUSO View Post
    Next hurdle:
    If you want to write your own lib, than you should use the "reload" mechanism because python remembers the imported libs. And if you do not reload, than changes you made during the developement are not recognized.
    During developement of a lib you should use:
    import libname; reload(libname)
    Thanks, I have run into this but was not aware of "reload".

  3. #3
    Registered User Diepgroen's Avatar
    Join Date
    Jul 2016
    Location
    Amsterdam
    Posts
    50
    Quote Originally Posted by KANUSO View Post
    During developement of a lib you should use:
    import libname; reload(libname)
    Great info, i had this issue before and didn't know what to do other than restart LW all the time. Thanks

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •