i want a unique code of 3 alphanumeric text from a artistic text lines for example
parag PAR
corel8 CR8
coreldraw-x6 CX6
etc
If you create the shapes in one run, it's pretty easy:
Option Explicit'Declaring a variable which is valid in this module during the runtimeDim MyCounter As Integer.....Sub Main()Dim Sh As Shape....
'Reset the counter:MyCounter = 0....
'Create the first shapeSet Sh = ActiveLayer.CreateArtisticText(1, 1, "Txt1")'name the shape with a functionSh.Name = MyShapeName()'repeat this as often as you wantSet Sh = ActiveLayer.CreateArtisticText(2, 1, "Txt2")Sh.Name = MyShapeName()....End Sub'This function will increase the counter and create a string conteinint the counterFunction MyShapeName() As StringMyCounter = MyCounter + 1MyShapeName = "Txt" + Right("000" + Trim(Str(MyCounter)), 3)End Function
If you have to do this in a document where you update from time to time a new page / layer, then you can do this with a function like this:
Function MyShapeName2() As StringDim p As Page, l As Layer, s As Shape, Ch As String, n As Integer, MaxN As IntegerConst TxtID = "Txt"MaxN = 0For Each p In ActiveDocument.Pages For Each l In p.Layers For Each s In l.Shapes If Left(s.Name, Len(TxtID)) = TxtID Then n = Val(Mid(s.Name, Len(TxtID) + 1)) If n > MaxN Then MaxN = n End If Next s Next lNext pMaxN = MaxN + 1MyShapeName2 = TxtID + Right("000" + Trim(Str(MaxN)), 3)End Function
Can you define what that 'proper unique name' must be? Do you expect to recognize the 'father' text in that unique names? Like Corel 8 to be CR8 and coreldraw-x6 to be CX6? If yes, I'm afraid there is not any automation able to help you on that issue... You must make this association manually and after that to find the 'brand name' on the page and according to that to insert the corespondent 'unique' name wherever you need. Is that a matter of thousands? Eventually the application will check if the three character name chosen by you is really unique for the necessary range and in case it is not, to worn you in order to choose another one. What about the case when more then one brand will be found? Isn't that be possible?
Hi, the good news first: this is totally possible. It's not even that complicated to code. The bad news is: You'll have to figure out your abbreviation algorithm by yourself. No one can help you with that, as the abbreviations you are using in your examples are following no logical pattern. It is up to you to find a logical pattern that fits your needs - since this is what you need to take care of before coding a single line. If you figured that out, the community here might be able to help you with some code examples of the HOW.
Edit: btw. those restrictions you are talking about (needs to be recognizable by ancestor text AND only have 3 characters), are pretty limiting . You need to get rid of them if you want to have a minor chance of success. For example: You are abbreviating software. Let's say the software starts with C and has a version number. This limits you to potentially 36 (characters and numbers) * 10 (numbers) = 360 different abbreviations. And this is not taking any further resemblance into account.
Lets say you want to abbreviate CorelDraw X6, CorelDesigner X6 and CorelDraw 6.0 - how are you gonna solve that? Good luck with that, as long as you keep your restrictions the way they are.