Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware API
      • ZBrush GoZ API
      • Code Examples on Github
    • Forum
    • Downloads
    • Support
      • Support Procedures
      • Registered Developer Program
      • Plugin IDs
      • Contact Us
    • Categories
      • Overview
      • News & Information
      • Cinema 4D SDK Support
      • Cineware SDK Support
      • ZBrush 4D SDK Support
      • Bugs
      • General Talk
    • Unread
    • Recent
    • Tags
    • Users
    • Login

    SetPercent() not working...

    Cinema 4D SDK
    r19
    3
    7
    1.6k
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • G
      gogeta
      last edited by m_adam

      Hi,
      I am using ProgressDialog() class to show the progress bar in my plugin. I got the example from here.
      This example works fine and shows a good progress bar but when I customized it to use for my code it stopped showing the progress percentage which was set using SetPercent().
      Here is my code :

      void ProgressBarDialog::Timer(const BaseContainer &msg)
      {	
      	GePrint("ProgressBarDialog::Timer() is called.");
      	GePrint("value of percentIncrease = " + String::FloatToString((percentIncrease)));
      
      	percentIncrease += 2.0f;
      	SetPercent(percentIncrease/100);
      
      }
      

      Also if I am using the SetPercent() in *void ProgressBarDialog::Main(C4DThread bt) function of ProgressDialog(), it is still not working.

      Please help me with this as I am stuck with it for a long time.

      Thanks In Advance.

      1 Reply Last reply Reply Quote 0
      • M
        mp5gosu
        last edited by

        @gogeta said in SetPercent() not working...:

        percentIncrease/100

        This results in being an Int. Because you divide a float by 100 and that results in an Int rounded to 0.
        So simply cast it to float - right as the example you linked, does.

        1 Reply Last reply Reply Quote 1
        • G
          gogeta
          last edited by gogeta

          Hi,

          I tried the same as suggested by you but it still didn't work ☹ .
          I even tried with hardcoded float values but still no progress.
          I am not able to understand why is this happening 😅 .

          Update: In Main() function of ProgressDialog class I am doing some task and also updating the progress bar with SetPercent(0.1F), SetPercent(0.2F) and so on.
          Please guide me.

          Thanks.

          1 Reply Last reply Reply Quote 0
          • M
            mp5gosu
            last edited by

            Would you mind to share the relevant portion of your code?

            G 1 Reply Last reply Reply Quote 1
            • G
              gogeta @mp5gosu
              last edited by m_adam

              @mp5gosu Hi,

              I can't provide you the exact code but I am providing some portion of code for understanding. Please have a look into this.

              Bool ProgressBarDialog::CreateLayout()
              {
              	return ProgressDialog::CreateLayout();
              }
              
              Bool ProgressBarDialog::InitValues()
              {
              	GePrint("Initializing progress bar values.");
              	//percentIncrease = 0.0F;
              
              	//this->SetTimer(1000);
              	return ProgressDialog::InitValues();
              }
              
              void ProgressBarDialog::Main(C4DThread *bt)
              {
                      percentIncrease = 0.0F;
              	GePrint("In Main function.");
              	Bool status = false;
              	
              	
              	/*some variables*/
              	...
              	...
              	...
              	String str1;
              	String str2;
              
              	/*Set progress bar 10%*/
              	SetPercent(0.1f);
              	
              	DWORD flag = doSomework();
              
              	status = readStatus(arg1,arg2,arg3);
              	if (!status)
              	{
              		MessageDialog("Please Try Again. Facing Issue !");
              		isErrorOccurred = true;
              		return ;
              	}
              	
              	/*Set progress bar 20%*/
              	SetPercent(0.2f);
              	//StatusSetBar(10);
              
              
              	/*some relevant tasks*/
              
              	/*Set progress bar 30%*/
              	SetPercent(0.3f);
              	
              	status = doSomeCommunication(buff1, buff2);
              	
              	/*Set progress bar 60%*/
              	SetPercent(0.6f);
              	if (!status)
              	{
              		/*Set progress bar 70%*/
              		SetPercent(0.7f);
              		
              		/*Perform other tasks*/
              		
              		/*Set progress bar 80%*/
              		SetPercent(0.8f);
              
              	}
              	else
              	{
              		/*Set progress bar 70%*/
              		SetPercent(0.7f);
              		
              		status = doSomeParsing(Buff1, &var1);
              		if (!status)
              		{
              			MessageDialog(buff[0]); //display error msg
              			isErrorOccurred = true;
              			return ;
              		}
              
              		/*Set progress bar 90%*/
              		SetPercent(0.9f);
              		
              		/*do some other tasks*/
              
              	}
              
              	/*Set progress bar 100%*/
              	SetPercent(1.f);
              }
              
              void ProgressBarDialog::Timer(const BaseContainer &msg)
              {	
              	GePrint("ProgressBarDialog::Timer() is called.");
              	GePrint("value of percentIncrease = " + String::FloatToString((percentIncrease)));
              
              	percentIncrease += 2.0f;
              	SetPercent((Float)percentIncrease / 100);
              }
              

              Thanks!

              1 Reply Last reply Reply Quote 0
              • M
                m_adam
                last edited by

                Hi @gogeta sorry for the late reply.

                Since ProgressDialog makes use of a Timer in order to refresh the UI, you must call the Super::Timer operator like so at the end of your Timer function.

                return ProgressDialog::Timer(msg);
                

                If you have any questions please let me know!
                Cheers,
                Maxime.

                MAXON SDK Specialist

                Development Blog, MAXON Registered Developer

                G 1 Reply Last reply Reply Quote 2
                • G
                  gogeta @m_adam
                  last edited by

                  @m_adam Hi,

                  Thanks for your answer. I applied your changes and it worked like a charm ☺ .
                  Thanks again!!!

                  1 Reply Last reply Reply Quote 0
                  • First post
                    Last post