Raph Posted September 7 Share Posted September 7 Hello everyone, I have a code with the possibility of creating a worksheet. It works great! but... Each time the code is executed, it generates a new table. Would it be possible to make a code that rewrites the existing table? I use the following code to create the worksheet: WSH = vs.CreateWS(vs.Concat(S1,' ',vs.Date(2,0)),N1+3,3) Thank you for your feedback Quote Link to comment
Pat Stanford Posted September 7 Share Posted September 7 You can certainly reuse a worksheet. Instead of the code you have above to get the handle to the worksheet with the CreateWS call, you will need to use code to get the handle to the existing worksheet. If you have the image of the worksheet selected in the drawing you can use GetWSFromImage. Or you can use other functions to find the WS you want by Name. GetObject('Your WS Name') is one way. 1 Quote Link to comment
Jesse Cogswell Posted September 7 Share Posted September 7 One way that I've done this is to use DelObject to delete the existing worksheet before creating the new one. Quote Link to comment
Sam Jones Posted September 7 Share Posted September 7 7 minutes ago, Jesse Cogswell said: One way that I've done this is to use DelObject to delete the existing worksheet before creating the new one. That's what I do. IF GetObject(GetName(worksheetName)) <> NIL THEN DelObject(GetObject(GetName(worksheetName))); WKSHandle := CreatWS(worksheetName, RowNum, ColNum); Quote Link to comment
Juliensv Posted September 12 Share Posted September 12 On 9/7/2023 at 4:58 PM, Jesse Cogswell said: One way that I've done this is to use DelObject to delete the existing worksheet before creating the new one. Does this delete or disassociate any worksheet images or does the association stay after you've deleted and recreated the worksheet? Quote Link to comment
Sam Jones Posted September 12 Share Posted September 12 Actually, I have no clue. None of the worksheets to which I do this have sheet images. I would imagine that the worksheet image would disappear for the deleted worksheet. However, if you placed the worksheet with a script you can just place it again. If you didn't originally place it, I would imagine you could collect the location of the worksheet before you delete it and place or move the new one to that location. WKS := GetObject(WKSName); WKSImage := GetWSImage(WKS); GetBBox(WKSImage, X1, Y1, X2, Y2); DelObject(WKS) Quote Link to comment
Jesse Cogswell Posted September 12 Share Posted September 12 Just did a test and deleting the source worksheet does indeed delete the worksheet image. @Sam Jones is correct in that you would need to pull the bounding box (GetBBox) and the original worksheet image scale (GetWSImageScaleF) then recreate the worksheet image using CreateWSImage and reapply the scale. You'll likely need to pull the original object's visual attributes as well. 1 Quote Link to comment
Raph Posted September 18 Author Share Posted September 18 Thank you for your feedback and answers, @Sam Jones I can't quite figure out how to convert the "<> NIL THEN" condition into Python. Can anyone help me? My code is in the attached image Quote Link to comment
Marionette Maven Marissa Farrell Posted September 18 Marionette Maven Share Posted September 18 I use != vs.Handle(0) in Marionette nodes, I think that should work. Quote Link to comment
Raph Posted September 19 Author Share Posted September 19 Thank You, Ok now it works fine!! 😝 😘 I found that the code with "GetName(worksheetName)" generates a problem. Simplifying the code without using this action works... No idea why, if anyone knows? see next image for code used Quote Link to comment
Marionette Maven Marissa Farrell Posted September 19 Marionette Maven Share Posted September 19 You don't need to get the name of the worksheet since you're already providing it. Also, GetName works on object handles, not strings. Here's a short example of how you could use GetName. vs.NameObject('NewRect') #set the name for the next created object vs.RectangleN(0,0,0,1,1,1) vs.AlrtDialog(str(vs.GetName(vs.LNewObj()))) Note that vs.RectangleN doesn't return a handle to the created rectangle, so vs.LNewObj() is used to call to the last created object. 1 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.