Results 1 to 11 of 11

Thread: CNC CAM software C# coding question

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2024
    Posts
    5

    CNC CAM software C# coding question

    I'm running a CAM software package that uses VB macro coding to activate tasks.

    I need to create a macro that will rename a tool loaded in my spindle. For example, if I had Tool #1 (T1) in the spindle when I shut the machine down, but the CAM software says I don't have a tool loaded on restart, I'd want to change the stated T0 on screen to T1. I'd like to press the button on my UCCNC screen and have it ask me what tool number I want to use for the renaming.

    I have the following code someone generously created for me that generates the input box. However this is for a tool change, and not a tool renaming.



    Code:
    string val = exec.TextQuestion("Enter loaded tool number.");
    string toolch = "M6 T" + val;
    
    exec.Code(toolch);
    which executes a tool change.

    ************************************************** ************************************************** **************

    Here is VB code where I can manually enter T61 T(#) in the manual input line in UCCNC and specify T1 to get the loaded tool renamed to T1. This works fine but I'd like to attach this to a macro so I only have to push a screen button and then enter the tool number.

    Code:
    int newTool = exec.Getnewtool();
    
    if (newTool < 0)
    {
        return;
    }
    else
    {
        exec.Setcurrenttool(newTool);
    }
    ************************************************** ************************************************
    I've tried combing the two command sequences in numerous ways similar to what I've pasted below. None have worked though. All have given me a code error message in UCCNC.


    Code:
    string val = exec.TextQuestion("Enter loaded tool number.");
    
    string Setcurrenttool(newTool); = "M61 T" + val;
    
    exec.Setcurrenttool(newTool);

    Could someone help me out here?

    Thanks,
    BH
    Last edited by dday9; Jul 29th, 2024 at 08:16 AM.

  2. #2
    PowerPoster
    Join Date
    Nov 2017
    Posts
    3,330

    Re: CNC CAM software VB coding question

    Quote Originally Posted by BH Davis View Post
    I'm running a CAM software package that uses VB macro coding to activate tasks.
    That code isn't any flavor of Basic or Visual Basic. VB doesn't use semicolon delimiters, and it doesn't use braces to surround code blocks. It could be JavaScript I suppose, no idea.

  3. #3

    Thread Starter
    New Member
    Join Date
    Jul 2024
    Posts
    5

    Re: CNC CAM software VB coding question

    Quote Originally Posted by OptionBase1 View Post
    That code isn't any flavor of Basic or Visual Basic. VB doesn't use semicolon delimiters, and it doesn't use braces to surround code blocks. It could be JavaScript I suppose, no idea.
    Okay.........thanks. My mistake. I appreciate your letting me know.

    BH

  4. #4

    Thread Starter
    New Member
    Join Date
    Jul 2024
    Posts
    5

    Re: CNC CAM software VB coding question

    And just did some more digging online and found out this is C# programming. I will continue along that vein.

    Again thanks,
    BH

  5. #5
    PowerPoster
    Join Date
    Nov 2017
    Posts
    3,330

    Re: CNC CAM software VB coding question

    Sounds good. I'll ask that the mods move this thread to the C# forum. Please don't create a new thread there or it will cause them extra work.

  6. #6

    Thread Starter
    New Member
    Join Date
    Jul 2024
    Posts
    5

    Re: CNC CAM software VB coding question

    Quote Originally Posted by OptionBase1 View Post
    Sounds good. I'll ask that the mods move this thread to the C# forum. Please don't create a new thread there or it will cause them extra work.

    Thanks again.
    BH

  7. #7
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    11,965

    Re: CNC CAM software C# coding question

    Moved from VB6 and earlier. Updated the title to include C#. Updated the post to include [CODE][/CODE] tags.
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | Code Tags | Sword of Fury - Jameram

  8. #8
    PowerPoster PlausiblyDamp's Avatar
    Join Date
    Dec 2016
    Location
    Pontypool, Wales
    Posts
    2,693

    Re: CNC CAM software C# coding question

    Never encountered this software before, so no idea about the specifics.

    The code you posted has an extra ; in it, try changing it to
    Code:
    string val = exec.TextQuestion("Enter loaded tool number.");
    
    string Setcurrenttool(newTool) = "M61 T" + val;
    
    exec.Setcurrenttool(newTool);
    and see if that helps.

    Also what error is it giving on your current attempts to make this change?

  9. #9

    Thread Starter
    New Member
    Join Date
    Jul 2024
    Posts
    5

    Re: CNC CAM software C# coding question

    Thank you. I hadn't noticed the extra semi-colon.

    I fixed that but still get the same error message: "Script error: macro has errors"

    However I have found some code that works:

    double val = exec.Question("Enter loaded tool number.");
    exec.Setcurrenttool(Convert.ToInt32(val));

    Thanks everyone for looking into this. I should be all set now.

    BH





    Quote Originally Posted by PlausiblyDamp View Post
    Never encountered this software before, so no idea about the specifics.

    The code you posted has an extra ; in it, try changing it to
    Code:
    string val = exec.TextQuestion("Enter loaded tool number.");
    
    string Setcurrenttool(newTool) = "M61 T" + val;
    
    exec.Setcurrenttool(newTool);
    and see if that helps.

    Also what error is it giving on your current attempts to make this change?

  10. #10
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,665

    Re: CNC CAM software C# coding question

    sigh...
    Code:
    string val = exec.TextQuestion("Enter loaded tool number.");
    
    string Setcurrenttool(newTool) = "M61 T" + val; <-- this here is the problem... it's not doing what you think it is doing.. don't do this.
    string newTool = "M61 T" + val;
    
    exec.Setcurrenttool(newTool); <-- NOW you can pass in newTool
    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  11. #11
    PowerPoster PlausiblyDamp's Avatar
    Join Date
    Dec 2016
    Location
    Pontypool, Wales
    Posts
    2,693

    Re: CNC CAM software C# coding question

    Quote Originally Posted by techgnome View Post
    sigh...
    Code:
    string val = exec.TextQuestion("Enter loaded tool number.");
    
    string Setcurrenttool(newTool) = "M61 T" + val; <-- this here is the problem... it's not doing what you think it is doing.. don't do this.
    string newTool = "M61 T" + val;
    
    exec.Setcurrenttool(newTool); <-- NOW you can pass in newTool
    -tg
    Oops, didn't even spot what the code was attempting to do!

Posting Permissions

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



Click Here to Expand Forum to Full Width