Jump to content
Developer Wiki and Function Reference Links ×

Script for checking Numbers


KingChaos

Recommended Posts

Hi,

 

i am trying to convert a number from 1-4 digits into a predefined text.

 

Input is this "1 to 4" digit-number, which can be a and an single-digit (1,2,3 or 4) which has to be compared whether the single digit is contained in the 4 digit.

 

The script has to return a string "ABS" if the input is:

 

1234  & 1 -> ABS  1 is included

234 & 1 -> "" 1 is not included

312 & 1 -> ABS

 

i dont know which node i have to use. I searched for some who splits the 4 digit into 4 single digits, but i cant find it.

 

This Script i have to use in a bom-Chart for interiorcad. 

 

 

I would rather use the excel functions, but this function does not work in the vw chart i think or i am not able to find the syntax i have to use.

If someone can tell me, how the syntax of this function is, i dont need the marionette.

 

e4ea7067-86ce-4f86-9682-1b95bf772729.png

 

BR KC

 

Link to comment

does someone knows, what of the code the wrapped marionette i have to copy into my script editor?

 

image.png.02d731c605985dc99e66f777ab99c189.png

 

import Marionette 
import math 
import operator 
Marionette.execution_mode = Marionette.ExecutionType.Export 
###################### IfInStringABS_Wrap_79 ######################### 
class IfInStringABS_Wrap_79: 
    Handle = vs.Mrntte_GetNodeHandle(79)
    @Marionette.NodeDefinition 
    class Params(metaclass = Marionette.OrderedClass): 
        this = Marionette.Node("Wrapper") 
        this.SetDescription("""Wrapper""") 
        this.SetLinksObjects()
        InputKante_60_Lifted = Marionette.OIPControl( 'InputKante', Marionette.WidgetType.Int, 134)
        InputKante_60_Lifted.SetDescription("An OIP control that accepts integer values")
        KantenNr_61_Lifted = Marionette.OIPControl( 'KantenNr', Marionette.WidgetType.Int, 2)
        KantenNr_61_Lifted.SetDescription("An OIP control that accepts integer values")
        ABS_Output = Marionette.PortOut()
        ABS_Output.SetDescription("The result item")
    
    
    def RunNode(self): 
        ###################### String_62 ######################### 
        class String_62: 
            Handle = vs.Mrntte_GetNodeHandle(62)
            #COMMAND;READONLYREFFILE;[VWLibDef]/Input\String.py;
            #Modified April 2017
            @Marionette.NodeDefinition
            class Params(metaclass = Marionette.OrderedClass):
            #APPEARANCE
                #Name
                this = Marionette.Node( 'String' )
                this.SetDescription('A text string defined in the OIP')     
                
                #Input Ports
                
                #OIP Controls
                String = Marionette.OIPControl( 'string', Marionette.WidgetType.Text, '')
                String.SetDescription('A text string')
                
                #Output Ports
                s = Marionette.PortOut()
                s.SetDescription('The string')
            
            #BEHAVIOR
                
            def RunNode(self):
                #inputs
                s = self.Params.String.value
                
                #script
                
                #outputs
                self.Params.s.value = s
    
        ###################### String_89 ######################### 
        class String_89: 
            Handle = vs.Mrntte_GetNodeHandle(89)
            #COMMAND;READONLYREFFILE;[VWLibDef]/Input\String.py;
            #Modified April 2017
            @Marionette.NodeDefinition
            class Params(metaclass = Marionette.OrderedClass):
            #APPEARANCE
                #Name
                this = Marionette.Node( 'String' )
                this.SetDescription('A text string defined in the OIP')     
                
                #Input Ports
                
                #OIP Controls
                String = Marionette.OIPControl( 'string', Marionette.WidgetType.Text, '')
                String.SetDescription('A text string')
                
                #Output Ports
                s = Marionette.PortOut()
                s.SetDescription('The string')
            
            #BEHAVIOR
                
            def RunNode(self):
                #inputs
                s = self.Params.String.value
                
                #script
                
                #outputs
                self.Params.s.value = s
    
        ###################### InputKante_60 ######################### 
        class InputKante_60: 
            Handle = vs.Mrntte_GetNodeHandle(60)
            #COMMAND;READONLYREFFILE;[VWLibDef]/Input\Int.py;
            #Modified April 2017
            @Marionette.NodeDefinition
            class Params(metaclass = Marionette.OrderedClass):
            #APPEARANCE
                #Name
                this = Marionette.Node( 'Int' )    
                this.SetDescription('An integer value') 
                
                #Input Ports
                
                #OIP Controls
                Int = Marionette.OIPControl( 'Integer', Marionette.WidgetType.Int, 0)
                Int.SetDescription('An OIP control that accepts integer values') 
                
                #Output Ports
                i = Marionette.PortOut()
                i.SetDescription('The value')
                
            #BEHAVIOR
                
            def RunNode(self):
                #inputs
                i = self.Params.Int.value
                
                #script
                
                #outputs
                self.Params.i.value = i
    
        ###################### KantenNr_61 ######################### 
        class KantenNr_61: 
            Handle = vs.Mrntte_GetNodeHandle(61)
            #COMMAND;READONLYREFFILE;[VWLibDef]/Input\Int.py;
            #Modified April 2017
            @Marionette.NodeDefinition
            class Params(metaclass = Marionette.OrderedClass):
            #APPEARANCE
                #Name
                this = Marionette.Node( 'Int' )    
                this.SetDescription('An integer value') 
                
                #Input Ports
                
                #OIP Controls
                Int = Marionette.OIPControl( 'Integer', Marionette.WidgetType.Int, 0)
                Int.SetDescription('An OIP control that accepts integer values') 
                
                #Output Ports
                i = Marionette.PortOut()
                i.SetDescription('The value')
                
            #BEHAVIOR
                
            def RunNode(self):
                #inputs
                i = self.Params.Int.value
                
                #script
                
                #outputs
                self.Params.i.value = i
    
        ###################### If_In_String_70 ######################### 
        class If_In_String_70: 
            Handle = vs.Mrntte_GetNodeHandle(70)
            #COMMAND;READONLYREFFILE;[VWLibDef]/String\If In String.py;
            #added to library 02/28/2018 MFarrell
            @Marionette.NodeDefinition
            class Params(metaclass = Marionette.OrderedClass):
            #APPEARANCE
                #Name
                this = Marionette.Node( 'If In String' )
                this.SetDescription( 'If a sub string exists in the given full string, this node returns True, if not, it returns False.' )
                
                #Input Ports
                sFull = Marionette.PortIn( '' )
                sFull.SetDescription( 'The full string to search' )
                sSub = Marionette.PortIn( '' )
                sSub.SetDescription( 'The sub string' )
                
                #OIP Controls
                
                #Output Ports
                b = Marionette.PortOut()
                b.SetDescription( 'True or False, depending on whether the sub string is in the full string' )
        
            #BEHAVIOR
                
            def RunNode(self):
                #inputs
                full = self.Params.sFull.value
                sub = self.Params.sSub.value
                
                #script
                bool = []
                if str(sub) in str(full):
                    bool.append(True)
                else:
                    bool.append(False)
                    
                #outputs
                self.Params.b.value = bool
    
        ###################### ABS_Output_83 ######################### 
        class ABS_Output_83: 
            Handle = vs.Mrntte_GetNodeHandle(83)
            #COMMAND;READONLYREFFILE;[VWLibDef]/Data Flow\If.py;
            #Modified by MFarrell May 2017
            @Marionette.NodeDefinition
            class Params(metaclass = Marionette.OrderedClass):
            #APPEARANCE
                #Name
                this = Marionette.Node( 'If' )
                this.SetDescription( 'If test is true, pass the value from true otherwise pass the value from false' )    
        
                #Input Ports
                true = Marionette.PortIn( None, 'itemTrue' )
                true.SetDescription( "An item" )
                false = Marionette.PortIn( None, 'itemFalse' )
                false.SetDescription( "An item" )
                test = Marionette.PortIn( True, 'bTest' )
                test.SetDescription( "A boolean value" )
        
                #OIP Controls
        
                #Output Ports
                out = Marionette.PortOut('item')   
                out.SetDescription( "The result item" )
        
            #BEHAVIOR
                
            def RunNode(self):
                #inputs
                test = self.Params.test.value
                true = self.Params.true.value
                false = self.Params.false.value
        
                #script
                if test:
                    out = true
                else:
                    out = false
        
                #outputs
                self.Params.out.value = out
    
        if Marionette.execution_mode != Marionette.ExecutionType.PIOExecute: 
            vs.BeginGroup()
        String_62.Params.String.value = """ABS""" 
        String_62.Params.s.SetConnected( True )
        if String_62.Params.this.initFunc:
            String_62.Params.this.initFunc(String_62)
        String_62.RunNode(String_62) 
        ABS_Output_83.Params.true.value = Marionette.OutputMerge( ABS_Output_83.Params.true.value, String_62.Params.s )
        ABS_Output_83.Params.true.blocked = ABS_Output_83.Params.true.blocked or String_62.Params.s.blocked
        if String_62.Params.this.finalFunc:
            String_62.Params.this.finalFunc(String_62)
        Marionette.NotifyForOutValue( String_62, 0, String_62.Params.s ) 
    #########################################################################
        String_89.Params.String.value = """ """ 
        String_89.Params.s.SetConnected( True )
        if String_89.Params.this.initFunc:
            String_89.Params.this.initFunc(String_89)
        String_89.RunNode(String_89) 
        ABS_Output_83.Params.false.value = Marionette.OutputMerge( ABS_Output_83.Params.false.value, String_89.Params.s )
        ABS_Output_83.Params.false.blocked = ABS_Output_83.Params.false.blocked or String_89.Params.s.blocked
        if String_89.Params.this.finalFunc:
            String_89.Params.this.finalFunc(String_89)
        Marionette.NotifyForOutValue( String_89, 0, String_89.Params.s ) 
    #########################################################################
        InputKante_60.Params.i.SetConnected( True )
        if InputKante_60.Params.this.initFunc:
            InputKante_60.Params.this.initFunc(InputKante_60)
        InputKante_60.Params.Int.value = self.Params.InputKante_60_Lifted.value 
        InputKante_60.RunNode(InputKante_60) 
        If_In_String_70.Params.sFull.value = Marionette.OutputMerge( If_In_String_70.Params.sFull.value, InputKante_60.Params.i )
        If_In_String_70.Params.sFull.blocked = If_In_String_70.Params.sFull.blocked or InputKante_60.Params.i.blocked
        if InputKante_60.Params.this.finalFunc:
            InputKante_60.Params.this.finalFunc(InputKante_60)
        Marionette.NotifyForOutValue( InputKante_60, 0, InputKante_60.Params.i ) 
    #########################################################################
        KantenNr_61.Params.i.SetConnected( True )
        if KantenNr_61.Params.this.initFunc:
            KantenNr_61.Params.this.initFunc(KantenNr_61)
        KantenNr_61.Params.Int.value = self.Params.KantenNr_61_Lifted.value 
        KantenNr_61.RunNode(KantenNr_61) 
        If_In_String_70.Params.sSub.value = Marionette.OutputMerge( If_In_String_70.Params.sSub.value, KantenNr_61.Params.i )
        If_In_String_70.Params.sSub.blocked = If_In_String_70.Params.sSub.blocked or KantenNr_61.Params.i.blocked
        if KantenNr_61.Params.this.finalFunc:
            KantenNr_61.Params.this.finalFunc(KantenNr_61)
        Marionette.NotifyForOutValue( KantenNr_61, 0, KantenNr_61.Params.i ) 
    #########################################################################
        if not If_In_String_70.Params.sFull.blocked and not If_In_String_70.Params.sSub.blocked:
            If_In_String_70.Params.sFull.SetConnected( True )
            If_In_String_70.Params.sSub.SetConnected( True )
            If_In_String_70.Params.b.SetConnected( True )
            if If_In_String_70.Params.this.initFunc:
                If_In_String_70.Params.this.initFunc(If_In_String_70)
            maxPCnt = 0
            maxPCnt = If_In_String_70.Params.sFull.MaxLen( maxPCnt ) 
            maxPCnt = If_In_String_70.Params.sSub.MaxLen( maxPCnt ) 
            if If_In_String_70.Params.this.nodeListAbsorb or maxPCnt == 0: 
                try:
                    If_In_String_70.RunNode(If_In_String_70) 
                except:
                    Marionette.ReportException()
                ABS_Output_83.Params.test.value = Marionette.OutputMerge( ABS_Output_83.Params.test.value, If_In_String_70.Params.b )
                ABS_Output_83.Params.test.blocked = ABS_Output_83.Params.test.blocked or If_In_String_70.Params.b.blocked
            else: 
                p0List = If_In_String_70.Params.sFull.ExtendList( maxPCnt ) 
                p1List = If_In_String_70.Params.sSub.ExtendList( maxPCnt ) 
                out0 = None
                out0blocked = False
                for p0, p1 in zip(p0List, p1List): 
                    If_In_String_70.Params.sFull.value = p0 
                    If_In_String_70.Params.sSub.value = p1 
                    try:
                        If_In_String_70.RunNode(If_In_String_70) 
                    except:
                        Marionette.ReportException()
                    out0 = Marionette.OutputMerge( out0, If_In_String_70.Params.b ) 
                    out0blocked = out0blocked or If_In_String_70.Params.b.blocked
                If_In_String_70.Params.b.SetValue( out0 )
                If_In_String_70.Params.b.blocked = out0blocked
                ABS_Output_83.Params.test.value = Marionette.OutputMerge( ABS_Output_83.Params.test.value, If_In_String_70.Params.b )
                ABS_Output_83.Params.test.blocked = ABS_Output_83.Params.test.blocked or If_In_String_70.Params.b.blocked
            if If_In_String_70.Params.this.finalFunc:
                If_In_String_70.Params.this.finalFunc(If_In_String_70)
        else:
            If_In_String_70.Params.b.blocked = True
            ABS_Output_83.Params.test.value = Marionette.OutputMerge( ABS_Output_83.Params.test.value, If_In_String_70.Params.b )
            ABS_Output_83.Params.test.blocked = True
        Marionette.NotifyForOutValue( If_In_String_70, 0, If_In_String_70.Params.b ) 
    #########################################################################
        if not ABS_Output_83.Params.true.blocked and not ABS_Output_83.Params.false.blocked and not ABS_Output_83.Params.test.blocked:
            ABS_Output_83.Params.true.SetConnected( True )
            ABS_Output_83.Params.false.SetConnected( True )
            ABS_Output_83.Params.test.SetConnected( True )
            if ABS_Output_83.Params.this.initFunc:
                ABS_Output_83.Params.this.initFunc(ABS_Output_83)
            maxPCnt = 0
            maxPCnt = ABS_Output_83.Params.true.MaxLen( maxPCnt ) 
            maxPCnt = ABS_Output_83.Params.false.MaxLen( maxPCnt ) 
            maxPCnt = ABS_Output_83.Params.test.MaxLen( maxPCnt ) 
            if ABS_Output_83.Params.this.nodeListAbsorb or maxPCnt == 0: 
                try:
                    ABS_Output_83.RunNode(ABS_Output_83) 
                except:
                    Marionette.ReportException()
            else: 
                p0List = ABS_Output_83.Params.true.ExtendList( maxPCnt ) 
                p1List = ABS_Output_83.Params.false.ExtendList( maxPCnt ) 
                p2List = ABS_Output_83.Params.test.ExtendList( maxPCnt ) 
                out0 = None
                out0blocked = False
                for p0, p1, p2 in zip(p0List, p1List, p2List): 
                    ABS_Output_83.Params.true.value = p0 
                    ABS_Output_83.Params.false.value = p1 
                    ABS_Output_83.Params.test.value = p2 
                    try:
                        ABS_Output_83.RunNode(ABS_Output_83) 
                    except:
                        Marionette.ReportException()
                    out0 = Marionette.OutputMerge( out0, ABS_Output_83.Params.out ) 
                    out0blocked = out0blocked or ABS_Output_83.Params.out.blocked
                ABS_Output_83.Params.out.SetValue( out0 )
                ABS_Output_83.Params.out.blocked = out0blocked
            if ABS_Output_83.Params.this.finalFunc:
                ABS_Output_83.Params.this.finalFunc(ABS_Output_83)
        else:
            ABS_Output_83.Params.out.blocked = True
        Marionette.NotifyForOutValue( ABS_Output_83, 0, ABS_Output_83.Params.out ) 
    #########################################################################
        self.Params.ABS_Output.SetValue( ABS_Output_83.Params.out.value )
        self.Params.ABS_Output.blocked = ABS_Output_83.Params.out.blocked
        if Marionette.execution_mode != Marionette.ExecutionType.PIOExecute: 
            vs.EndGroup() 
    

try: 
################################################# 
    IfInStringABS_Wrap_79.Params.InputKante_60_Lifted.value = 134 
    IfInStringABS_Wrap_79.Params.KantenNr_61_Lifted.value = 2 
    if Marionette.execution_mode != Marionette.ExecutionType.PIOExecute and IfInStringABS_Wrap_79.Params.this.nodeLinksObjects: 
        vs.BeginGroup()
    if IfInStringABS_Wrap_79.Params.this.initFunc:
        IfInStringABS_Wrap_79.Params.this.initFunc(IfInStringABS_Wrap_79)
    IfInStringABS_Wrap_79.RunNode(IfInStringABS_Wrap_79) 
    if IfInStringABS_Wrap_79.Params.this.finalFunc:
        IfInStringABS_Wrap_79.Params.this.finalFunc(IfInStringABS_Wrap_79)
    if Marionette.execution_mode != Marionette.ExecutionType.PIOExecute and IfInStringABS_Wrap_79.Params.this.nodeLinksObjects: 
        vs.EndGroup()
        if Marionette.execution_mode != Marionette.ExecutionType.Export:
            vs.Marionette_LinkObject(IfInStringABS_Wrap_79.Handle, vs.LNewObj())
    Marionette.NotifyForOutValue( IfInStringABS_Wrap_79, 0, IfInStringABS_Wrap_79.Params.ABS_Output ) 
#########################################################################
except Marionette.MarionetteError: 
    pass 
 

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...