michaelk Posted May 18, 2017 Share Posted May 18, 2017 Can someone tell my why I'm getting an error on line 41, the SetName function. The script still does what it is supposed to do after dismissing the error message. This is an example of the error I get when one VP on a sheet layer is selected: Procedure ViewportRename; {Badly Scripted by Michael Klaers. Updated Aug 2, 2015} {This script will take all selected viewports and change the name of those viewports to be (Sheet Layer) (Drawing Number) (Drawing Name) This version tries to force the name to appear immeidately in the name field, data tab, OIP when only one VP is selected. Prior to this version the new name appeared immediately in the Nav Palette, but not in the name field.} Var VPDwgTitle,VPName,BText,VPNum : String; h,hh: Handle; ViewportLayer: Handle; ViewportLayerString: String; Procedure RenameVP(h : HANDLE); Begin {*********** BEGIN Procedure ***********} ViewportLayer:= GetLayer(h); ViewportLayerString:= GetLName(ViewportLayer); VPDwgTitle := GetObjectVariableString(h, 1032); VPNum := GetObjectVariableString(h, 1033); ResetObject(h); { Message('Viewport Handle: ',h,chr(13), 'Layer Handle: ',ViewportLayer,chr(13), 'Layer Name: ',ViewportLayerString,chr(13), 'VP Num: ',VPNum,chr(13), 'VP Name: ',VPDwgTitle); } SetName(h, CONCAT(ViewportLayerString,' ',VPNum,' ',VPDwgTitle)); SetDSelect(h); {These two commands are just here to force the new name to appear in the } SetSelect(h); {name field immediately. They can be deleted w/o consequence} End; {*********** END Procedure ***********} Begin {*********** Main Program ***********} ForEachObject(RenameVP,(((T=VIEWPORT) & (SEL=TRUE)))); End; Run(ViewportRename); Any ideas? Thanks! mk Quote Link to comment
Pat Stanford Posted May 18, 2017 Share Posted May 18, 2017 Can you post a file with the right set of viewports in it to try the script? Quote Link to comment
michaelk Posted May 18, 2017 Author Share Posted May 18, 2017 Every file. After the script is run a couple times it starts kicking out error messages. Quote Link to comment
JBenghiat Posted May 18, 2017 Share Posted May 18, 2017 That makes sense. Names have to be unique and unused, even if re-naming an object with its own name. If you run the script once, you have already assigned the name to the objects, and you will get errors in the second run. You can check to see if an object already has the name before assigning. You should also check that the proposed name is unique -- Name2Index = 0 -- and decide what to do if the name isn't unique. -Josh Quote Link to comment
Pat Stanford Posted May 18, 2017 Share Posted May 18, 2017 Or, you can just set the name to something unique and then to what you want it to be. You could use SetName(h, Date(2,2)); or SetName(h, CreateUUID); to generate a name that should always be unique. Put this line right above your existing SetName. 1 Quote Link to comment
michaelk Posted May 18, 2017 Author Share Posted May 18, 2017 Yahoo!!! Thanks, that worked great. 1 Quote Link to comment
michaelk Posted May 18, 2017 Author Share Posted May 18, 2017 (edited) Thanks Josh and Patrick. Just for my own understanding: Why was the script kicking back errors on random viewports on other sheet layers? Are they selected but not in the active sheet layer and therefore the script is trying to include it? Should I add a criterion to make sure I only include the active sheet layer? mk Edited May 18, 2017 by michaelk Grammar pedantry is a terrible thing. Quote Link to comment
Pat Stanford Posted May 18, 2017 Share Posted May 18, 2017 2 hours ago, michaelk said: Just for my own understanding: Why was the script kicking back errors on random viewports on other sheet layers? Are they selected but not in the active sheet layer and therefore the script is trying to include it? Should I add a criterion to make sure I only include the active sheet layer? Yes and Yes. If you only want to work on viewports you can see you should definitely add a criteria for the active layer. Which is kind of a pain since the criteria only work by Layer Name so you have to get the name and then use that in the criteria. Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.