Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations waross on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Splitting a document or part name

Status
Not open for further replies.

Alan Lowbands

Aerospace
May 17, 2017
274
0
0
GB
Hi guys,

I have found this line of code that will remove the instance number from the part number.
strNewNumber = Split(CATIA.ActiveDocument.Name,".")(0)
Can anyone tell me if you can use this to edit the part number itself.
eg remove the first 2 numbers and the last 2 numbers? (123456789.1 to 34567.1)
I can't find anything that explains how to do this using this command

any help would be really appreciated.
thanks
Alan
 
Replies continue below

Recommended for you

this forum is more about CATIA question, your is a VBA question.

you can turn your number into a string with CStr(thenumber) then doing a mid(thestring,x,y) to keep what you need, then convert back to a number with Val(theString)

in your case :

Code:
newnumber = Val(Mid(CStr(yourNumber), 3, Len(CStr(thenumber)-4)))

Eric N.
indocti discant et ament meminisse periti
 
Hi itsmyjob,
The question was about a catia script.
I have tried to find examples but with virtually no luck.
I have used the line I mentioned before in a bit of code for removing the instance number (someone here gave me, may have been you)
Thanks for the pointer its appreciated.

regards
Alan
 
I'm not sure if this is me or the code doesn't work in cat script.
Keep getting a string mismatch error.
More than likely me but could someone tell me?

thanks
Alan

***********************************************************
Dim nSel
nSel = uSel.item(1).value.name

Dim nSel2
nSel2 = nSel

CStr(nSel2)

Dim nSel3
nSel3 = Val(Mid(CStr(nSel), 3, Len(CStr(nSel2)-4)))
*************************************************************
 
Assuming your string always has one and only one "." in it, try this piece:
Code:
myString = CATIA.ActiveDocument.Name
myNewString = Mid(myString , 3, InStr(myString , ".") - 5)
 
Thanks cilici
That seems to work removing the numbers from the front of the part number but removes the instance number when trying to remove the last 4 digits.
Is there away to keep the instance number ?

regards
Alan
 
hi guys,
did it by doing to cuts one for the part number and one for the instance number.

if thers a better way it would be nice to know.

cheers
Alan
 
Status
Not open for further replies.
Back
Top