def getUIContent(): my_toolProperty = apex_sdk.ToolPropertyContainer() my_toolProperty.TitleText = "AuFast 1.6" file_path = os.path.dirname(os.path.realpath(__file__)) #my_toolProperty.TitleImageUriString = os.path.join(os.path.dirname(file_path), r'..\\icons\\auFast.png') my_toolProperty.TitleImageUriString = file_path + "./auFast.png" my_toolProperty.WorkFlowInstructions = """<HTML><BODY><P STYLE=\"font-size:10;\"><SPAN>AuFast 1.4</SPAN></P> <P><SPAN> </SPAN></P> <P><SPAN>This script creates hole-to-hole fastener connections for surface-to-surface, surface-to-solid, and solid-to-solid connections.</SPAN></P> <P STYLE=\"font-size:10;\"><SPAN>Send questions, comments and Elvis sightings to [email protected]</SPAN></P></BODY></HTML>""" #handle apply button (green) click event my_toolProperty.AppliedCommand = apex_sdk.ActionCommand( System.Action(HandleApplyButton)) # handle exit button (red) click event my_toolProperty.ExitCommand = apex_sdk.ActionCommand( System.Action(HandleExitButton)) my_toolProperty.ToolPropertyContent = getCustomToolPropertyContent() #define pickFiterTools my_toolProperty.ShowPickChoice = True my_toolProperty.IsCustomTool = True #setPickFilterTools() my_toolProperty.PickFilterList = setPickFilterTools() return my_toolProperty
def PingUpdater(self, *args): avg_ping = 0 while True: result_ping = ping(SERVERS.get(self.server, "eu"), timeout=1, unit="ms", size=1) if avg_ping == 0: avg_ping = result_ping if result_ping is None: result_ping = -1 else: result_ping = math.trunc(result_ping) if result_ping >= 0: avg_ping = (result_ping + avg_ping) / 2 console_text = f"Ping: {result_ping}ms \t|\tAvg ping: {math.trunc(avg_ping)}ms" else: console_text = "Lost package" self.window.Dispatcher.Invoke( System.Action(lambda: self.console.AddLine(console_text))) self.window.Dispatcher.Invoke( System.Action(lambda: self.SetText(f"{result_ping}ms"))) time.sleep(1)
def do_long_process(self): for i in range(10): sleep(1) print(i) if self.output and not self.output.closed: self.progress_state = (i + 1) * 10 self.output.Dispatcher.Invoke( System.Action(self.update_progress)) self.output.Dispatcher.Invoke( System.Action(self.append_message))
def getUIContent(): my_toolProperty = apex_sdk.ToolPropertyContainer() # Provide an icon and a name for the tool property panel # my_toolProperty.TitleImageUriString = os.path.join(os.path.dirname(current_file_path), r"Icons\script.png") my_toolProperty.TitleText = "Find bodies within distance" my_toolProperty.WorkFlowInstructions = ''' <p><strong><span style="color: #999999;">Find fixture<br /></span></strong></p> <p><span style="color: #999999;">Description: This tools uses the distance search algorithm to find bodies in contact with the selected assembly.<br /></span></p> <ul> <li><span style="color: #999999;"><span style="color: #00ccff;">Distance (mm)</span>: Search distance.<br /></span></li> <li><span style="color: #999999;"><span style="color: #00ccff;">Separate in new assembly</span>: Check this option if you want to separate the bodies found within the specified distance. This is usually the expected behavior.</span><span style="color: #999999;"><br /></span></li> </ul> <p><span style="color: #999999;">Workflow:</span></p> <ol> <li><span style="color: #999999;">Define the search distance<br /></span></li> <li><span style="color: #999999;">Select/skip separate in new assembly<br /></span></li> <li><span style="color: #999999;">Select an assembly containing the reference geometries</span></li> <li><span style="color: #999999;">Click find close parts<br /></span></li> </ol> <p><span style="color: #999999;">For support: <span style="color: #ff0000;"><a href="mailto:[email protected]">[email protected]</a></span></span></p> <p><span style="color: #999999;"><span style="color: #ff0000;"></span></span></p> ''' # Define UI my_toolProperty.ToolPropertyContent = getCustomToolPropertyContent() # Handle apply button (green) click event my_toolProperty.AppliedCommand = apex_sdk.ActionCommand(System.Action(HandleApplyButton)) # Define PickFilterList my_toolProperty.ShowPickChoice = True my_toolProperty.PickFilterList = setPickFilterList() return my_toolProperty
def test_callable(): """Test that only delegate subtypes are callable""" def foo(): pass assert callable(System.String("foo")) == False assert callable(System.Action(foo)) == True
def getUIContent(): my_toolProperty = apex_sdk.ToolPropertyContainer() # Provide an icon and a name for the tool property panel # my_toolProperty.TitleImageUriString = os.path.join(os.path.dirname(current_file_path), r"Icons\script.png") my_toolProperty.TitleText = "Slice body" my_toolProperty.WorkFlowInstructions = '''<p><strong><span style="color: #999999;">DED - Vertical slicing<br /></span></strong></p> <p><span style="color: #999999;">Description: This tool was designed to help with slicing geometries vertically.</span></p> <ul> <li><span style="color: #999999;"><span style="color: #00ccff;">Layer height (mm)</span>: expected/desired layer height<br /></span></li> <li><span style="color: #999999;"><span style="color: #00ccff;">Do not create multiple solids</span>: this option will create body partitions instead of splitting the body into multiple solids</span><span style="color: #999999;"><span style="color: #00ccff;"></span></span><span style="color: #999999;"><span style="color: #00ccff;"></span></span></li> </ul> <p><span style="color: #999999;">Workflow:</span></p> <ol> <li><span style="color: #999999;">Define the layer height</span></li> <li><span style="color: #999999;">Choose whether to create multiple solids or not</span></li> <li><span style="color: #999999;">Select the starting face of the splitting</span></li> <li><span style="color: #999999;">Click Slice geometry</span></li> </ol> <p><span style="color: #999999;">Selected starting face defines the body to be sliced (the body to which the surface belongs).</span></p> <p><span style="color: #999999;">For support: <span style="color: #ff0000;"><a href="mailto:[email protected]">[email protected]</a></span></span></p> <p><span style="color: #999999;"><span style="color: #ff0000;"></span></span></p>''' # Define UI my_toolProperty.ToolPropertyContent = getCustomToolPropertyContent() # Handle apply button (green) click event my_toolProperty.AppliedCommand = apex_sdk.ActionCommand( System.Action(HandleApplyButton)) # Define PickFilterList my_toolProperty.ShowPickChoice = True my_toolProperty.PickFilterList = setPickFilterList() return my_toolProperty
def getUIContent(): my_toolProperty = apex_sdk.ToolPropertyContainer() # Provide an icon and a name for the tool property panel # my_toolProperty.TitleImageUriString = os.path.join(os.path.dirname(current_file_path), r"Icons\script.png") my_toolProperty.TitleText = "Round corners" my_toolProperty.WorkFlowInstructions = ''' <p><strong><span style="color: #999999;">Round corners<br /></span></strong></p> <p><span style="color: #999999;">Description: This tool creates fillets at the corners of selected faces. This helps with improving contact when running simulations.<br /></span></p> <ul> <li><span style="color: #999999;"><span style="color: #00ccff;">Corner radius</span>: Fillet size definition<br /></span></li> <li><span style="color: #999999;"><span style="color: #00ccff;">Round selected faces</span>: Click to perform the filleting <br /></span></li> </ul> <p><span style="color: #999999;">Workflow:</span></p> <ol> <li><span style="color: #999999;">Select the faces to be filleted<br /></span></li> <li><span style="color: #999999;">Define fillet radius size</span><span style="color: #999999;"><br /></span></li> <li><span style="color: #999999;">Click round selected faces button<br /></span></li> </ol> <p><span style="color: #999999;">For support: <span style="color: #ff0000;"><a href="mailto:[email protected]">[email protected]</a></span></span></p> <p><span style="color: #999999;"><span style="color: #ff0000;"></span></span></p> ''' # Define UI my_toolProperty.ToolPropertyContent = getCustomToolPropertyContent() # Handle apply button (green) click event my_toolProperty.AppliedCommand = apex_sdk.ActionCommand( System.Action(HandleApplyButton)) # Define PickFilterList my_toolProperty.ShowPickChoice = True my_toolProperty.PickFilterList = setPickFilterList() return my_toolProperty
def getUIContent(): my_toolProperty = apex_sdk.ToolPropertyContainer() # Provide an icon and a name for the tool property panel # my_toolProperty.TitleImageUriString = os.path.join(os.path.dirname(current_file_path), r"Icons\script.png") my_toolProperty.TitleText = "Get trajectory from edge" my_toolProperty.WorkFlowInstructions = ''' <p><strong><span style="color: #999999;">Get trajectory tool<br /></span></strong></p> <p><span style="color: #999999;">Description: This tool was designed to help extracting trajectory information to be used in Simufact Welding.<br /></span></p> <ul> <li><span style="color: #999999;"><span style="color: #00ccff;">Calculate normal direction</span>: Using this option the user also gets the normal direction at the points of the trajectory.</span><span style="color: #999999;"></span><span style="color: #999999;"></span></li> <li><span style="color: #999999;"><span style="color: #00ccff;">Get trajectory from edge</span>: Extract trajectories from selected edges.<br /></span></li> </ul> <p><span style="color: #999999;">Workflow:</span></p> <ol> <li><span style="color: #999999;">Select the edges you want to create trajectories from (one or multiple)<br /></span></li> <li><span style="color: #999999;">Define whether you need the normal direction by marking the checkbox<br /></span></li> <li><span style="color: #999999;">Click get trajectory from edge<br /></span></li> </ol> <p><span style="color: #999999;">For support: <span style="color: #ff0000;"><a href="mailto:[email protected]">[email protected]</a></span></span></p> <p><span style="color: #999999;"><span style="color: #ff0000;"></span></span></p> ''' # Define UI my_toolProperty.ToolPropertyContent = getCustomToolPropertyContent() # Handle apply button (green) click event my_toolProperty.AppliedCommand = apex_sdk.ActionCommand( System.Action(HandleApplyButton)) # Define PickFilterList my_toolProperty.ShowPickChoice = True my_toolProperty.PickFilterList = setPickFilterList() return my_toolProperty
def SetFontSize(self, size): self.label.FontSize = size self.check_label.FontSize = self.label.FontSize self.window.Dispatcher.Invoke( System.Windows.Threading.DispatcherPriority.Render, System.Action(self.SizeUpdater)) CONFIG.font_size = str(size)
def SetFont(self, font): self.label.FontFamily = System.Windows.Media.FontFamily(font) self.check_label.FontFamily = self.label.FontFamily self.window.Dispatcher.Invoke( System.Windows.Threading.DispatcherPriority.Render, System.Action(self.SizeUpdater)) CONFIG.font_name = font
def SetFontWeight(self, font_weight): CONFIG.font_weight = font_weight font_weight = FontWeight.get(font_weight, System.Windows.FontWeights.Bold) self.label.FontWeight = font_weight self.check_label.FontWeight = self.label.FontWeight self.window.Dispatcher.Invoke( System.Windows.Threading.DispatcherPriority.Render, System.Action(self.SizeUpdater))
def getUIContent(): my_toolProperty = apex_sdk.ToolPropertyContainer() # Provide an icon and a name for the tool property panel my_toolProperty.TitleImageUriString = os.path.join( os.path.dirname(current_file_path), r"Icons\script.png") my_toolProperty.TitleText = "Create simple joints" # Define UI my_toolProperty.ToolPropertyContent = getCustomToolPropertyContent() # Handle apply button (green) click event my_toolProperty.AppliedCommand = apex_sdk.ActionCommand( System.Action(HandleApplyButton)) return my_toolProperty
def getUIContent(): my_toolProperty = apex_sdk.ToolPropertyContainer() # Provide an icon and a name for the tool property panel # my_toolProperty.TitleImageUriString = os.path.join(os.path.dirname(current_file_path), r"Icons\script.png") my_toolProperty.TitleText = "Hatching layers" my_toolProperty.WorkFlowInstructions = '''<p><strong><span style="color: #999999;">DED - Hatching tool<br /></span></strong></p> <p><span style="color: #999999;">Description: This tool was designed to help with hatching layers of sliced geometry.<br /></span></p> <ul> <li><span style="color: #999999;"><span style="color: #00ccff;">Trajec. spacing (mm)</span>: Distance between two trajectories calculated from the centerline.<br /></span></li> <li><span style="color: #999999;"><span style="color: #00ccff;">Point spacing (mm)</span>: Distance between two points of a trajectory (sampling resolution)</span></li> <li><span style="color: #999999;"><span style="color: #00ccff;">Angular cut</span>: Algorithm to vary the angular cut</span><span style="color: #999999;"></span> <ul> <li><span style="color: #999999;"><span style="color: #ff6600;">Single angle</span>: one single angle will be used for all layers</span></li> <li><span style="color: #999999;"><span style="color: #ff6600;">Incremental</span>: the angle will be multiplied by the layer number (1*angle, 2*angle, 3*angle, ...)</span></li> <li><span style="color: #999999;"><span style="color: #ff6600;">Cycle through</span>: inform the specific angles to be used separating them by comma (ex: 0, 30, 45)</span></li> </ul> </li> <li><span style="color: #999999;"><span style="color: #00ccff;">Angle (deg)</span>: specify the cut angle for the hatching algorithm</span><span style="color: #999999;"></span></li> <li><span style="color: #999999;"><span style="color: #00ccff;">Mesh the layers</span>: mesh the resulting hatched geometry with the 2.5D mesher (hexahedral elements)</span><span style="color: #999999;"></span></li> </ul> <p><span style="color: #999999;">Workflow:</span></p> <ol> <li><span style="color: #999999;">Define trajectory spacing (this depends on your process)</span></li> <li><span style="color: #999999;">Define point spacing</span></li> <li><span style="color: #999999;">Select hatching algorithm</span></li> <li><span style="color: #999999;">Define initial angle or angles</span></li> <li><span style="color: #999999;">Choose whether to perform meshing aftewards</span></li> <li><span style="color: #999999;">Select where to save the trajectories</span></li> <li><span style="color: #999999;">Click create hatching to start the process</span></li> </ol> <p><span style="color: #999999;">For support: <span style="color: #ff0000;"><a href="mailto:[email protected]">[email protected]</a></span></span></p> <p><span style="color: #999999;"><span style="color: #ff0000;"></span></span></p>''' # Define UI my_toolProperty.ToolPropertyContent = getCustomToolPropertyContent() # Handle apply button (green) click event my_toolProperty.AppliedCommand = apex_sdk.ActionCommand( System.Action(HandleApplyButton)) # Define PickFilterList my_toolProperty.ShowPickChoice = True my_toolProperty.PickFilterList = setPickFilterList() return my_toolProperty
def getUIContent(): my_toolProperty = apex_sdk.ToolPropertyContainer() # Provide an icon and a name for the tool property panel # my_toolProperty.TitleImageUriString = os.path.join(os.path.dirname(current_file_path), r"Icons\script.png") my_toolProperty.TitleText = "Design fixture by stiffness" # Define UI my_toolProperty.ToolPropertyContent = getCustomToolPropertyContent() # Handle apply button (green) click event my_toolProperty.AppliedCommand = apex_sdk.ActionCommand( System.Action(HandleApplyButton)) # Define PickFilterList my_toolProperty.ShowPickChoice = True my_toolProperty.PickFilterList = setPickFilterList() return my_toolProperty
def getUIContent(): my_toolProperty = apex_sdk.ToolPropertyContainer() # Provide an icon and a name for the tool property panel # my_toolProperty.TitleImageUriString = os.path.join(os.path.dirname(current_file_path), r"Icons\script.png") my_toolProperty.TitleText = "Create refinement regions" my_toolProperty.WorkFlowInstructions = ''' This tool will infer the weld beads from the CAD. ''' # Define UI my_toolProperty.ToolPropertyContent = getCustomToolPropertyContent() # Handle apply button (green) click event my_toolProperty.AppliedCommand = apex_sdk.ActionCommand(System.Action(HandleApplyButton)) # Define PickFilterList my_toolProperty.ShowPickChoice = True my_toolProperty.PickFilterList = setPickFilterList() return my_toolProperty
def getUIContent(): my_toolProperty = apex_sdk.ToolPropertyContainer() # Provide an icon and a name for the tool property panel # my_toolProperty.TitleImageUriString = os.path.join(os.path.dirname(current_file_path), r"Icons\script.png") my_toolProperty.TitleText = "Stiffness studies" my_toolProperty.WorkFlowInstructions = ''' <p><span style="background-color: #ff0000;">Experimental tool for running multiple stiffness analysis.</span></p> ''' # Define UI my_toolProperty.ToolPropertyContent = getCustomToolPropertyContent() # Handle apply button (green) click event my_toolProperty.AppliedCommand = apex_sdk.ActionCommand(System.Action(HandleApplyButton)) # Define PickFilterList my_toolProperty.ShowPickChoice = True my_toolProperty.PickFilterList = setPickFilterList() return my_toolProperty
def getUIContent(): my_toolProperty = apex_sdk.ToolPropertyContainer() # Provide an icon and a name for the tool property panel # my_toolProperty.TitleImageUriString = os.path.join(os.path.dirname(current_file_path), r"Icons\script.png") my_toolProperty.TitleText = "Expand & Split" my_toolProperty.WorkFlowInstructions = ''' <p><strong><span style="color: #999999;">Expand & Split<br /></span></strong></p> <p><span style="color: #999999;">Description: This tools takes existing geometries and creates expanded (offset) versions of the outer surfaces. No extra geometry will be created. It takes advantage of the existing built-in partitioning tool.<br /></span></p> <ul> <li><span style="color: #999999;"><span style="color: #00ccff;">Distance (mm)</span>: Offset distance from the existing faces.<br /></span></li> <li><span style="color: #999999;"><span style="color: #00ccff;">Split solids</span>: Check this option if you want to split solids within reach of the expanded faces.<br /></span></li> <li><span style="color: #999999;"><span style="color: #00ccff;">Split surfaces</span>: Check this option if you want to split surfaces within reach of the expanded faces.</span><span style="color: #999999;"></span></li> <li><span style="color: #999999;"><span style="color: #00ccff;">Suppress extra vertices</span>: Performs an extra step to cleanup vertices after performing the split (partitioning).<br /></span></li> </ul> <p><span style="color: #999999;">Workflow:</span></p> <ol> <li><span style="color: #999999;">Define offset distance<br /></span></li> <li><span style="color: #999999;">Select/skip split solids<br /></span></li> <li><span style="color: #999999;">Select/skip split surfaces<br /></span></li> <li><span style="color: #999999;">Select/skip suppression of extra vertices<br /></span></li> <li><span style="color: #999999;">Select an assembly containing all geometries used for splitting</span></li> <li><span style="color: #999999;">Click expand beads and split</span><span style="color: #999999;"></span></li> </ol> <p><span style="color: #999999;">For support: <span style="color: #ff0000;"><a href="mailto:[email protected]">[email protected]</a></span></span></p> <p><span style="color: #999999;"><span style="color: #ff0000;"></span></span></p> ''' # Define UI my_toolProperty.ToolPropertyContent = getCustomToolPropertyContent() # Handle apply button (green) click event my_toolProperty.AppliedCommand = apex_sdk.ActionCommand( System.Action(HandleApplyButton)) # Define PickFilterList my_toolProperty.ShowPickChoice = True my_toolProperty.PickFilterList = setPickFilterList() return my_toolProperty
def getUIContent(): my_toolProperty = apex_sdk.ToolPropertyContainer() # Provide an icon and a name for the tool property panel # my_toolProperty.TitleImageUriString = os.path.join(os.path.dirname(current_file_path), r"Icons\script.png") my_toolProperty.TitleText = "Create group from selection" my_toolProperty.WorkFlowInstructions = ''' <p><strong><span style="color: #999999;">Create group<br /></span></strong></p> <p><span style="color: #999999;">Description: This tools creates an assembly with selected solid bodies and/or surfaces.<br /></span></p> <ul> <li><span style="color: #999999;"><span style="color: #00ccff;">Group name</span>: Assign an assembly name to the new group manually.<br /></span></li> <li><span style="color: #999999;"><span style="color: #00ccff;">Create under the same parent</span>: Takes the common uppermost parent of all selected bodies/surfaces as reference for creating the new assembly group.</span></li> </ul> <p><span style="color: #999999;">Workflow:</span></p> <ol> <li><span style="color: #999999;">Select the solid bodies and/or surfaces<br /></span></li> <li><span style="color: #999999;">Give the new group a name (optional)<br /></span></li> <li><span style="color: #999999;">Select whether it should be created under a common parent assembly<br /></span></li> <li><span style="color: #999999;">Click create assembly</span><span style="color: #999999;"></span></li> </ol> <p><span style="color: #999999;">For support: <span style="color: #ff0000;"><a href="mailto:[email protected]">[email protected]</a></span></span></p> <p><span style="color: #999999;"><span style="color: #ff0000;"></span></span></p> ''' # Define UI my_toolProperty.ToolPropertyContent = getCustomToolPropertyContent() # Handle apply button (green) click event my_toolProperty.AppliedCommand = apex_sdk.ActionCommand( System.Action(HandleApplyButton)) # Define PickFilterList my_toolProperty.ShowPickChoice = True my_toolProperty.PickFilterList = setPickFilterList() return my_toolProperty
def getUIContent(): my_toolProperty = apex_sdk.ToolPropertyContainer() # Provide an icon and a name for the tool property panel # my_toolProperty.TitleImageUriString = os.path.join(os.path.dirname(current_file_path), r"Icons\script.png") my_toolProperty.TitleText = "Create refinement regions" my_toolProperty.WorkFlowInstructions = ''' <p><strong><span style="color: #999999;">Refinement region<br /></span></strong></p> <p><span style="color: #999999;">Description: This tool creates a solid body to envelope the selected edge. The idea is to define a refinement region to be used as split location.<br /></span></p> <ul> <li><span style="color: #999999;"><span style="color: #00ccff;">Diameter</span>: Define the region diameter<br /></span></li> <li><span style="color: #999999;"><span style="color: #00ccff;">Extend region</span>: Do an extra push-pull to extend the region beyond the start and end points (capture HAZ better)<br /></span></li> </ul> <p><span style="color: #999999;">Workflow:</span></p> <ol> <li><span style="color: #999999;">Select the edges you want to create trajectories from (one or multiple)<br /></span></li> <li><span style="color: #999999;">Define the region diameter<br /></span></li> <li><span style="color: #999999;">Define whether extension is needed<br /></span></li> <li><span style="color: #999999;">Click create regions</span></li> </ol> <p><span style="color: #999999;">For support: <span style="color: #ff0000;"><a href="mailto:[email protected]">[email protected]</a></span></span></p> <p><span style="color: #999999;"><span style="color: #ff0000;"></span></span></p> ''' # Define UI my_toolProperty.ToolPropertyContent = getCustomToolPropertyContent() # Handle apply button (green) click event my_toolProperty.AppliedCommand = apex_sdk.ActionCommand( System.Action(HandleApplyButton)) # Define PickFilterList my_toolProperty.ShowPickChoice = True my_toolProperty.PickFilterList = setPickFilterList() return my_toolProperty
def RunLater(ctrl,handler): ctrl.Dispatcher.BeginInvoke(System.Action(handler))
def SetText(self, text): self.label.Content = text self.window.Dispatcher.Invoke( System.Windows.Threading.DispatcherPriority.Render, System.Action(self.SizeUpdater))
def Show(self): self.window.Dispatcher.Invoke( System.Windows.Threading.DispatcherPriority.Render, System.Action(self.window.Show))
def SetServer(self, server): self.window.Dispatcher.Invoke( System.Action(lambda: self.console.AddLine(f"Server: {server}"))) self.server = server CONFIG.server = server
def exec(self): # -------------------------------------------------------------- # List<T> の生成 # 大抵の.NET クラスは、普通に呼び出せる。 # List<T> は、ジェネリックなので List[T]() という形で呼べる。 # Dictionary<K,V> の場合は、 Dictionary[K,V]() となる。 # -------------------------------------------------------------- net_list01 = List[int]() for x in range(10): net_list01.Add(x) pr('net_list01', net_list01) pr('net_list01.Count', net_list01.Count) pr('items', ','.join(str(x) for x in net_list01)) # -------------------------------------------------------------- # 引数に IEnumerable<T> を要求するメソッドの場合 # AddRangeを Python の list で呼ぶとエラーになる # e.g. TypeError: No method matches given arguments # net_list01.AddRange([10, 11, 12]) # つまり、Python の list のままでは駄目だということ。 # -------------------------------------------------------------- # -------------------------------------------------------------- # 以下のように別のList<T>を作って, それをAddRangeはOK # -------------------------------------------------------------- net_list02 = List[int]() net_list02.Add(11) net_list02.Add(12) net_list02.Add(13) net_list01.AddRange(net_list02) pr('items', ','.join(str(x) for x in net_list01)) # -------------------------------------------------------------- # 以下のやり方でもOK # # Pythonの list から .NET 側の シーケンスを 構築する場合は # 以下のように System.Array からつくる。 # # http://stackoverflow.com/questions/16484167/python-net-framework-reference-argument-double # # -------------------------------------------------------------- py_list01 = [21, 22, 23] ary01 = System.Array[int](py_list01) net_list01.AddRange(ary01) pr('items', ','.join(str(x) for x in net_list01)) # ------------------------------------------------------- # System.Threading.Tasks.Task は、delegate を要求する。 # そのまま Python の function オブジェクトを渡しても # エラーになる。Task.Run のシグネチャに合わせて # System.Action を生成して渡す。 # # http://stackoverflow.com/questions/30659933/python3-pythonnet-generic-delegates # ------------------------------------------------------- def print_hello(): for _ in range(3): Thread.Sleep(500) print('task---sleep') print('hello world') net_task01 = Task.Run(System.Action(print_hello)) pr('task', net_task01) net_task01.Wait() # ------------------------------------------------------- # null は Python には存在しないので None を設定するみたい。 # https://github.com/pythonnet/pythonnet/blob/master/src/tests/test_array.py # ------------------------------------------------------- try: tmp_list = List[str]() tmp_list.Add('hello') tmp_list.Add('world') tmp_list.Clear() assert tmp_list is not None tmp_list = None assert tmp_list is None tmp_list.Add('hello world') except AttributeError as attr_ex: pr('attr-ex', attr_ex) # ------------------------------------------------------- # .NET 側の例外も普通にハンドルできる # スローしたい場合は raise でOK # ------------------------------------------------------- try: raise_nullex() except System.NullReferenceException as null_ex: pr('csharp-ex', null_ex)