TBC Macros and Extensions

 View Only
Expand all | Collapse all

Why System.Collections.Generic doesn't work on TBC while it runs on IronPython

  • 1.  Why System.Collections.Generic doesn't work on TBC while it runs on IronPython

    Posted 06-01-2023 09:07

    I would not be surprised to not get any response.....

    If you write this and run in on IronPython Console, it works but TBC throws this exception and asks to use Array[Type] which is not what I want use. I need to be able to use Collections.Generics not Array[Type].

    class point:
     def __init__(self,x,y,z):
    ...         self.X=x
    ...         self.Y=y
    ...         self.Z=z
    ...
    >>> PointList=List[point]()
    
    
    >>> point1=point(2,5,6)
    >>> point2=point(4,7,8)
    >>> point3=point(64,47,38)
    
    >>> PointList.Add(point1)
    >>> PointList.Add(point2)
    

    above script works on IronPython Console but when I run it with TBC it throws this nasty exception. 



    ------------------------------
    Morteza Kiani
    ------------------------------


  • 2.  RE: Why System.Collections.Generic doesn't work on TBC while it runs on IronPython

    Posted 06-01-2023 15:04

    Why are you defining your own point class rather than just using the one in Trimble.Vce.Geometry?



    ------------------------------
    Dylan Towler
    dylan_towler@buildingpoint.com.au
    https://tbcanz.com/anz-toolbox/
    ------------------------------



  • 3.  RE: Why System.Collections.Generic doesn't work on TBC while it runs on IronPython

    Posted 06-02-2023 10:57

    Yes, I'm aware of that. This was just an example to describe the issue. I want to to be able to have a choice when to use Python List or .NET list. 

    I see lots of merits on using System.Collections.Generics Lists in Iron Python instead of Python lists. The moment you want to work with Python List[Objects] nothing works or performance is awful!

    BTW, I switched to C# since TBC with IronPython is only a headache while writing object oriented codes. All of the example Macros I've seen so far were not object oriented so I believe I'm wasting my time by writing object oriented codes in TBC with Iron Python.



    ------------------------------
    Morteza Kiani
    ------------------------------



  • 4.  RE: Why System.Collections.Generic doesn't work on TBC while it runs on IronPython

    Posted 06-01-2023 16:10

    The code you posted worked for me by the way. I don't think that code is what is actually causing the problem.  It's more likely something that you're passing the the PointList to that is expecting an array. It's hard to tell without seeing the actual code causing the exception but if you wanted to post your full source I could take a look.



    ------------------------------
    Dylan Towler
    dylan_towler@buildingpoint.com.au
    https://tbcanz.com/anz-toolbox/
    ------------------------------



  • 5.  RE: Why System.Collections.Generic doesn't work on TBC while it runs on IronPython

    Posted 06-02-2023 10:32
    Edited by Morteza Kiani 06-02-2023 10:58

    It works for me either while creating that list within the StackPanel Class,  something like this. I tried exact code with IronPython Console and it works perfectly fine but not with TBC and IronPython

    class TempScript(StackPanel): # this inherits from the WPF StackPanel control
        def __init__(self, currentProject, macroFileFolder):
            with StreamReader (macroFileFolder + r"\TempScript.xaml") as s:
                wpf.LoadComponent (self, s)
                self.MyPointList=List[Point]()
    
                

    but the moment you instantiate this list within another class it throws error. something like this:

    class MyClass:
      def __init__MyClass():
          myPointsList=List[Point]()
    
    
    
    

    it will work on IronPython console but not with the Trimble

    Thank you,

    Morteza



    ------------------------------
    Morteza Kiani
    ------------------------------



  • 6.  RE: Why System.Collections.Generic doesn't work on TBC while it runs on IronPython

    Posted 06-04-2023 16:49

    All of the example code you've posted works fine for me within TBC.



    ------------------------------
    Dylan Towler
    dylan_towler@buildingpoint.com.au
    https://tbcanz.com/anz-toolbox/
    ------------------------------