hexagon logo

VB Script, Using PutText to enter an expression

I want to write a script that can modify the THEO and TARG values of a feature to be an expression, such as "1+0" or "2*VX+4". So far I can change the values to other values but if I give it an expression it always seems to evaluate it first and insert the result rather than the expression itself.

Not sure if what I want to do is possible but after scouring the forum for any examples I am sure that if it is possible someone on here will know how to do it.
Parents
  • That's perfect! Thank you, for solving that for me. I am sure that you guys have run across the fact that if you try to loop a program using while loops PC-Dmis will decide that you obviously want your THEO and TARG values to update as you increment your alignments. A programmer once taught me that if you add "+0" or "*1" to the end of your values that PC-Dmis will see them as an expression and leave them alone. I am playing around with a script that will add "+0" to the end of all of the THEO and TARG values in my program since it is so tedious to do so myself, with the end goal of having a button in the wizards toolbar that I can access easily. I am simultaneously using this to try my hand out at automating PC-Dmis via Python since I am most comfortable with that language and want to build the next generation UI we use in it.

    Here is the base code I have for it now that it's working:

    from win32com.client import Dispatch
    from win32com.client import gencache
    from win32com.client import constants
    gencache.EnsureModule('{2A09476D-B502-4089-AA46-452D6754CB33}', 0, 9, 1)  
    
    DmisApp = Dispatch("pcdlrn.Application")
    DmisApp.Visible = 1  
    DmisAppEvents =
    DmisApp.ApplicationEvents  
    DmisApp.WaitUntilReady(40)
    DmisPart = DmisApp.ActivePartProgram  
    DmisCmds = DmisPart.Commands  
    
    FeatureTypes = [
         "Basic Hit",
        "CIRCLE (CONTACT)",
        "CONE (CONTACT)",
        "CYLINDER (CONTACT)",
        "Generic Feature",
        "LINE (CONTACT)",
        "Measured Circle",
        "Measured Cone",
        "Measured Cylinder",
        "Measured Line",
        "Measured Plane",
        "Measured Point",
        "Measured Round Slot",
        "Measured Sphere",
        "Measured Square Slot",
        "Measured Torus",
        "PLANE (CONTACT)",
        "SPHERE (CONTACT)",
        "VECTOR POINT (CONTACT)",
     ]
    
    DataTypes = [
         constants.THEO_X,
        constants.THEO_Y,
        constants.THEO_Z,
        constants.THEO_SX,
        constants.THEO_SY,
        constants.THEO_SZ,
        constants.THEO_EX,
        constants.THEO_EY,
        constants.THEO_EZ,
        constants.THEO_R,
        constants.THEO_A,
        constants.THEO_H,
        constants.THEO_SR,
        constants.THEO_SA,
        constants.THEO_SH,
        constants.THEO_ER,
        constants.THEO_EA,
        constants.THEO_EH,
        constants.THEO_I,
        constants.THEO_J,
        constants.THEO_K,
        constants.TARG_X,
        constants.TARG_Y,
        constants.TARG_Z,
        constants.TARG_SX,
        constants.TARG_SY,
        constants.TARG_SZ,
        constants.TARG_EX,
        constants.TARG_EY,
        constants.TARG_EZ,
        constants.TARG_R,
        constants.TARG_A,
        constants.TARG_H,
        constants.TARG_SR,
        constants.TARG_SA,
        constants.TARG_SH,
        constants.TARG_ER,
        constants.TARG_EA,
        constants.TARG_EH,
        constants.TARG_I,
        constants.TARG_J,
        constants.TARG_K,
        constants.MEAS_X,
        constants.MEAS_Y,
        constants.MEAS_Z,
        constants.MEAS_SX,
        constants.MEAS_SY,
        constants.MEAS_SZ,
        constants.MEAS_EX,
        constants.MEAS_EY,
        constants.MEAS_EZ,
        constants.MEAS_R,
        constants.MEAS_A,
        constants.MEAS_H,
        constants.MEAS_SR,
        constants.MEAS_SA,
        constants.MEAS_SH,
        constants.MEAS_ER,
        constants.MEAS_EA,
        constants.MEAS_EH,
        constants.MEAS_I,
        constants.MEAS_J,
        constants.MEAS_K,
    ]
    
    for cmd in DmisCmds:
        if cmd.TypeDescription in FeatureTypes:
            for dtype in DataTypes:
                old = cmd.GetText(dtype, 0)
                cmd.SetExpression(old + "+0", dtype, 0)
    
    


    I made another script that will remove all the "+0"s just to be prepared for the inevitability of it being useful now that I can so easily add the "+0"s

     from win32com.client import Dispatch
    from win32com.client import gencache
    from win32com.client import constants
    gencache.EnsureModule('{2A09476D-B502-4089-AA46-452D6754CB33}', 0, 9, 1)  
    
    DmisApp = Dispatch("pcdlrn.Application")
    DmisApp.Visible = 1  
    DmisAppEvents =
    DmisApp.ApplicationEvents  
    DmisApp.WaitUntilReady(40)
    DmisPart = DmisApp.ActivePartProgram  
    DmisCmds = DmisPart.Commands  
    
    FeatureTypes = [
         "Basic Hit",
        "CIRCLE (CONTACT)",
        "CONE (CONTACT)",
        "CYLINDER (CONTACT)",
        "Generic Feature",
        "LINE (CONTACT)",
        "Measured Circle",
        "Measured Cone",
        "Measured Cylinder",
        "Measured Line",
        "Measured Plane",
        "Measured Point",
        "Measured Round Slot",
        "Measured Sphere",
        "Measured Square Slot",
        "Measured Torus",
        "PLANE (CONTACT)",
        "SPHERE (CONTACT)",
        "VECTOR POINT (CONTACT)",
     ]
    
    DataTypes = [
         constants.THEO_X,
        constants.THEO_Y,
        constants.THEO_Z,
        constants.THEO_SX,
        constants.THEO_SY,
        constants.THEO_SZ,
        constants.THEO_EX,
        constants.THEO_EY,
        constants.THEO_EZ,
        constants.THEO_R,
        constants.THEO_A,
        constants.THEO_H,
        constants.THEO_SR,
        constants.THEO_SA,
        constants.THEO_SH,
        constants.THEO_ER,
        constants.THEO_EA,
        constants.THEO_EH,
        constants.THEO_I,
        constants.THEO_J,
        constants.THEO_K,
        constants.TARG_X,
        constants.TARG_Y,
        constants.TARG_Z,
        constants.TARG_SX,
        constants.TARG_SY,
        constants.TARG_SZ,
        constants.TARG_EX,
        constants.TARG_EY,
        constants.TARG_EZ,
        constants.TARG_R,
        constants.TARG_A,
        constants.TARG_H,
        constants.TARG_SR,
        constants.TARG_SA,
        constants.TARG_SH,
        constants.TARG_ER,
        constants.TARG_EA,
        constants.TARG_EH,
        constants.TARG_I,
        constants.TARG_J,
        constants.TARG_K,
        constants.MEAS_X,
        constants.MEAS_Y,
        constants.MEAS_Z,
        constants.MEAS_SX,
        constants.MEAS_SY,
        constants.MEAS_SZ,
        constants.MEAS_EX,
        constants.MEAS_EY,
        constants.MEAS_EZ,
        constants.MEAS_R,
        constants.MEAS_A,
        constants.MEAS_H,
        constants.MEAS_SR,
        constants.MEAS_SA,
        constants.MEAS_SH,
        constants.MEAS_ER,
        constants.MEAS_EA,
        constants.MEAS_EH,
        constants.MEAS_I,
        constants.MEAS_J,
        constants.MEAS_K,
    ]
    
    for cmd in DmisCmds:
        if cmd.TypeDescription in FeatureTypes:
            for dtype in DataTypes:
                old = cmd.GetText(dtype, 0)
                new = old[[emoticon:33306C418930400BAC28808410F8AC8B]ld.find("+0")]
                cmd.SetExpression(new, dtype, 0)
    
    


    The code could still be optimized a little bit but it works for now.

    Thanks again for the help!
Reply
  • That's perfect! Thank you, for solving that for me. I am sure that you guys have run across the fact that if you try to loop a program using while loops PC-Dmis will decide that you obviously want your THEO and TARG values to update as you increment your alignments. A programmer once taught me that if you add "+0" or "*1" to the end of your values that PC-Dmis will see them as an expression and leave them alone. I am playing around with a script that will add "+0" to the end of all of the THEO and TARG values in my program since it is so tedious to do so myself, with the end goal of having a button in the wizards toolbar that I can access easily. I am simultaneously using this to try my hand out at automating PC-Dmis via Python since I am most comfortable with that language and want to build the next generation UI we use in it.

    Here is the base code I have for it now that it's working:

    from win32com.client import Dispatch
    from win32com.client import gencache
    from win32com.client import constants
    gencache.EnsureModule('{2A09476D-B502-4089-AA46-452D6754CB33}', 0, 9, 1)  
    
    DmisApp = Dispatch("pcdlrn.Application")
    DmisApp.Visible = 1  
    DmisAppEvents =
    DmisApp.ApplicationEvents  
    DmisApp.WaitUntilReady(40)
    DmisPart = DmisApp.ActivePartProgram  
    DmisCmds = DmisPart.Commands  
    
    FeatureTypes = [
         "Basic Hit",
        "CIRCLE (CONTACT)",
        "CONE (CONTACT)",
        "CYLINDER (CONTACT)",
        "Generic Feature",
        "LINE (CONTACT)",
        "Measured Circle",
        "Measured Cone",
        "Measured Cylinder",
        "Measured Line",
        "Measured Plane",
        "Measured Point",
        "Measured Round Slot",
        "Measured Sphere",
        "Measured Square Slot",
        "Measured Torus",
        "PLANE (CONTACT)",
        "SPHERE (CONTACT)",
        "VECTOR POINT (CONTACT)",
     ]
    
    DataTypes = [
         constants.THEO_X,
        constants.THEO_Y,
        constants.THEO_Z,
        constants.THEO_SX,
        constants.THEO_SY,
        constants.THEO_SZ,
        constants.THEO_EX,
        constants.THEO_EY,
        constants.THEO_EZ,
        constants.THEO_R,
        constants.THEO_A,
        constants.THEO_H,
        constants.THEO_SR,
        constants.THEO_SA,
        constants.THEO_SH,
        constants.THEO_ER,
        constants.THEO_EA,
        constants.THEO_EH,
        constants.THEO_I,
        constants.THEO_J,
        constants.THEO_K,
        constants.TARG_X,
        constants.TARG_Y,
        constants.TARG_Z,
        constants.TARG_SX,
        constants.TARG_SY,
        constants.TARG_SZ,
        constants.TARG_EX,
        constants.TARG_EY,
        constants.TARG_EZ,
        constants.TARG_R,
        constants.TARG_A,
        constants.TARG_H,
        constants.TARG_SR,
        constants.TARG_SA,
        constants.TARG_SH,
        constants.TARG_ER,
        constants.TARG_EA,
        constants.TARG_EH,
        constants.TARG_I,
        constants.TARG_J,
        constants.TARG_K,
        constants.MEAS_X,
        constants.MEAS_Y,
        constants.MEAS_Z,
        constants.MEAS_SX,
        constants.MEAS_SY,
        constants.MEAS_SZ,
        constants.MEAS_EX,
        constants.MEAS_EY,
        constants.MEAS_EZ,
        constants.MEAS_R,
        constants.MEAS_A,
        constants.MEAS_H,
        constants.MEAS_SR,
        constants.MEAS_SA,
        constants.MEAS_SH,
        constants.MEAS_ER,
        constants.MEAS_EA,
        constants.MEAS_EH,
        constants.MEAS_I,
        constants.MEAS_J,
        constants.MEAS_K,
    ]
    
    for cmd in DmisCmds:
        if cmd.TypeDescription in FeatureTypes:
            for dtype in DataTypes:
                old = cmd.GetText(dtype, 0)
                cmd.SetExpression(old + "+0", dtype, 0)
    
    


    I made another script that will remove all the "+0"s just to be prepared for the inevitability of it being useful now that I can so easily add the "+0"s

     from win32com.client import Dispatch
    from win32com.client import gencache
    from win32com.client import constants
    gencache.EnsureModule('{2A09476D-B502-4089-AA46-452D6754CB33}', 0, 9, 1)  
    
    DmisApp = Dispatch("pcdlrn.Application")
    DmisApp.Visible = 1  
    DmisAppEvents =
    DmisApp.ApplicationEvents  
    DmisApp.WaitUntilReady(40)
    DmisPart = DmisApp.ActivePartProgram  
    DmisCmds = DmisPart.Commands  
    
    FeatureTypes = [
         "Basic Hit",
        "CIRCLE (CONTACT)",
        "CONE (CONTACT)",
        "CYLINDER (CONTACT)",
        "Generic Feature",
        "LINE (CONTACT)",
        "Measured Circle",
        "Measured Cone",
        "Measured Cylinder",
        "Measured Line",
        "Measured Plane",
        "Measured Point",
        "Measured Round Slot",
        "Measured Sphere",
        "Measured Square Slot",
        "Measured Torus",
        "PLANE (CONTACT)",
        "SPHERE (CONTACT)",
        "VECTOR POINT (CONTACT)",
     ]
    
    DataTypes = [
         constants.THEO_X,
        constants.THEO_Y,
        constants.THEO_Z,
        constants.THEO_SX,
        constants.THEO_SY,
        constants.THEO_SZ,
        constants.THEO_EX,
        constants.THEO_EY,
        constants.THEO_EZ,
        constants.THEO_R,
        constants.THEO_A,
        constants.THEO_H,
        constants.THEO_SR,
        constants.THEO_SA,
        constants.THEO_SH,
        constants.THEO_ER,
        constants.THEO_EA,
        constants.THEO_EH,
        constants.THEO_I,
        constants.THEO_J,
        constants.THEO_K,
        constants.TARG_X,
        constants.TARG_Y,
        constants.TARG_Z,
        constants.TARG_SX,
        constants.TARG_SY,
        constants.TARG_SZ,
        constants.TARG_EX,
        constants.TARG_EY,
        constants.TARG_EZ,
        constants.TARG_R,
        constants.TARG_A,
        constants.TARG_H,
        constants.TARG_SR,
        constants.TARG_SA,
        constants.TARG_SH,
        constants.TARG_ER,
        constants.TARG_EA,
        constants.TARG_EH,
        constants.TARG_I,
        constants.TARG_J,
        constants.TARG_K,
        constants.MEAS_X,
        constants.MEAS_Y,
        constants.MEAS_Z,
        constants.MEAS_SX,
        constants.MEAS_SY,
        constants.MEAS_SZ,
        constants.MEAS_EX,
        constants.MEAS_EY,
        constants.MEAS_EZ,
        constants.MEAS_R,
        constants.MEAS_A,
        constants.MEAS_H,
        constants.MEAS_SR,
        constants.MEAS_SA,
        constants.MEAS_SH,
        constants.MEAS_ER,
        constants.MEAS_EA,
        constants.MEAS_EH,
        constants.MEAS_I,
        constants.MEAS_J,
        constants.MEAS_K,
    ]
    
    for cmd in DmisCmds:
        if cmd.TypeDescription in FeatureTypes:
            for dtype in DataTypes:
                old = cmd.GetText(dtype, 0)
                new = old[[emoticon:33306C418930400BAC28808410F8AC8B]ld.find("+0")]
                cmd.SetExpression(new, dtype, 0)
    
    


    The code could still be optimized a little bit but it works for now.

    Thanks again for the help!
Children