Community
PowerMill Forum
Welcome to Autodesk’s PowerMill Forums. Share your knowledge, ask questions, and explore popular PowerMill topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Supressed Zeros (0) at Left Side

10 REPLIES 10
SOLVED
Reply
Message 1 of 11
p.valente
439 Views, 10 Replies

Supressed Zeros (0) at Left Side

Hello everyone.

 

I have an MACRO to rename NCPROGRAMS at Active Folder. And works good.

But I have a little problem with number zero at start of ncprogram.

 

If I rename to 123456, Macro counts my $value + 1 and make: 123457, 123458, 123459. Perfect !

 

The problem is: if my ncprogram start: 000123 +1 it supress left zeros and make 123, 124, 125. Where is the zeros ??

 

I change STRING $nombre = "" and force it with STRING $nombre = "0" and I can have 1 zero at left side always, but I dont want this zero forever.

 

Can anyone can help me with this chalenge ? transform numbers in text or something. Any ideas ?

 

Thank you in advance,

Keep good work

Best Regards

 

 

 

Reset localvars


//Deseja alterar todos os nome dos NCPROGRAMS ?

 

string yesorno = "Clica SIM, para renomear os Ncprograms" + crlf + "Clica NAO, para cancelar a macro"
bool yes = 0
$yes = QUERY $yesorno

IF yes {

// Remover o 0 quando for iniciar por outro digito que não o 0
STRING $nombre = ""



INT $COUNT = INPUT "Introduz numero do primeiro programa"


// Nomear todos os Ncprograms ou só os selecionados


string allorno = "Click SIM, para renomear os Ncprograms" + crlf + "Clica NAO, outras opcoes"
bool yes = 0
$yes = QUERY $allorno


IF $yes == 1 {


// Numerar todos os Ncprograms

 
STRING NewName = ""

STRING Fold = ACTIVE_FOLDER()


FOREACH Ncp IN folder ($Fold) {
ACTIVATE NCPROGRAM $Ncp.name
$NewName = ($nombre + $COUNT)
$COUNT = $COUNT + 1

RENAME NCPROGRAM ; $NewName

}

 

 

Labels (1)
10 REPLIES 10
Message 2 of 11
ondrej.mikulec
in reply to: p.valente

INT $number = 10

//Create a string and join zeros
STRING $numberStr = "00000" + $number

//Create substring 5 digits from the end
$numberStr = substring($numberStr,length($numberStr)-5)

PRINT $numberStr
Message 3 of 11
p.valente
in reply to: ondrej.mikulec

I dont understand that code. Sorry.
You imput 5 zeros, my rename could be with random number of zeros. Could be only 1 zero at start. Could be 2 zeros.
The thing I need is "no supressed" zeros at left side of Ncprogram.

Message 4 of 11
LasseFred
in reply to: p.valente

Where do you get your Zeros from?

Is it your toolpath or?

______________________
Lasse F.
Message 5 of 11
p.valente
in reply to: LasseFred

I input it manualy in box from macro.

When Macro ask: "Write the name of frist NcProgram" I input 00547812 for example

Both zeros gone be supressed automatically by rename macro and gone write only 547812, 547813, 547814..........

Message 6 of 11
LasseFred
in reply to: p.valente

Use @ondrej.mikulec solution..

 

 

______________________
Lasse F.
Message 7 of 11
p.valente
in reply to: LasseFred

Please show mw how the solution get in macro. I cant understand it. Please help me. Thank you.

Message 8 of 11

Why would you need leading Zeroes? What is your purpose for needing them?

If it is because your machine uses 8 figure program numbers, then you don't need leading zeroes as a program numbered 1234 would automatically be named as 00001234 when loaded to the machine.

 

The code below will help you enter a number that will be of field width 8 characters.

 

int num = 0
Int num_length = 0
string snum = ""
string NC = ""
//Set required field width for number
int field_width = 8

String msg = "Enter a number"
//Enter a program number
Do {
$num = input $msg

//Returns length of number imput
$num_length = length($num)

If ($num_length > $field_width) {
$msg = "Number too long! - Re-enter"
}

} while ($num_length > $field_width)
$NC= $num

if ($num_length < $field_width) {
$snum = $num
Do {
//increment snum by adding leading zero
$snum = "0" + $snum
//get lenth of $snum string
$num_length = length($snum)
} while ($num_length < $field_width)
$NC = $snum
}

CREATE NCPROGRAM ; EDIT NCPROGRAM ; QUIT FORM NCTOOLPATH
RENAME NCPROGRAM "1" $NC

 

regards Kevin

Message 9 of 11

Grettings,
Can you please insert that code in my MACRO ? 

 

Thank you

Message 10 of 11

In my spare time i have created a macro for you to use that hopefully does what you need.

The macro is set to output numbers 8 characters long (adjustable in macro) with leading zeros if number is shorter than 8 characters.

Based on your original macro the language was recognised as Portuguese in google translator, my macro uses same.

 

Macro attached below change .txt to .mac, 

 

Hope this is what you need

Regards Kevin

Message 11 of 11

@kevin.hammond3WX4X, that was AWSOME !!!!

Many many thanks !!!!

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Technology Administrators


Autodesk Design & Make Report