tca Posted June 23, 2016 Share Posted June 23, 2016 Hi, I'm looking for a way to create classes from a worksheet. We have an extensive program for a large hospital project. We've created a list of classes we would like to use to structure that program in VW. The list is currently in excel but could easily be pasted in a VW worksheet were a script could pick it up and generate classes with the names from the worksheet. Unfortunately I'm not able to script this myself. I've attached the VW worksheet. any ideas? Quote Link to comment
michaelk Posted June 23, 2016 Share Posted June 23, 2016 This should do it. Open the worksheet. Select the range of cells you want to use to create classes. Run the script. I'll also attach the file in 2015 and 2016. hth mk Procedure CreateClasssesFromWorksheet; {Badly scripted by Michael Klaers} {Open a worksheet. Select a cell or range of cells. Run this script.} {This script will create a class using the contents of the cells as names.} VAR WSHand : Handle; {Handle to Worksheet} topRow,leftColumn,bottomRow,rightColumn :INTEGER; currentCellRow,currentCellColumn,topRangeRow,leftRangeColumn,topRangeSubrow,bottomRangeRow,rightRangeColumn,bottomRangeSubrow :INTEGER; LoopColumn,LoopRow :INTEGER; ClassNameinWorksheet :STRING; BEGIN WSHand:=GetTopVisibleWS; GetWSSelection(WSHand,currentCellRow,currentCellColumn,topRangeRow,leftRangeColumn,topRangeSubrow,bottomRangeRow,rightRangeColumn,bottomRangeSubrow); For LoopColumn := leftRangeColumn TO rightRangeColumn DO BEGIN FOR LoopRow := topRangeRow TO bottomRangeRow DO BEGIN GetWSCellString(WSHand,LoopRow,LoopColumn,ClassNameinWorksheet); If ClassNameinWorksheet <> '' THEN NameClass(ClassNameinWorksheet); END; END; END; RUN(CreateClasssesFromWorksheet); classes_v2015.vwx classes_v2016.vwx 2 Quote Link to comment
tca Posted June 23, 2016 Author Share Posted June 23, 2016 wow great! Thanks for the effort! Quote Link to comment
michaelk Posted June 23, 2016 Share Posted June 23, 2016 It was mostly luck :-) I'm a pretty bad scripter, but I already had a script that queried every selected cell in a worksheet. From there it only takes 2 lines of script to get the text from the cell and create a class. Wish they were all that easy. I'm glad it works for what you need. mk Quote Link to comment
Matteo New Posted May 30, 2017 Share Posted May 30, 2017 is there any possibility to add the description that way, too? Quote Link to comment
michaelk Posted June 4, 2017 Share Posted June 4, 2017 This script should do it. Put the class names you want in column A. Put the descriptions in column B. Leave the worksheet open. Run the script. PROCEDURE CreateClasssesFromWorksheet; {Badly scripted by Michael Klaers} {Open a worksheet. Run this script.} {This script will create a class using the contents of the cells in Column A as names.} {The contents of Column B will be the desciption for the class in Column A of the same row.} VAR WSHand,ClassHandle :HANDLE; LoopRow :INTEGER; ClassNameinWorksheet,ClassDescriptioninWorksheet :STRING; BResult, IsThisACell :BOOLEAN; BEGIN WSHand:=GetTopVisibleWS; IsThisACell := TRUE; LoopRow := 1; WHILE (IsThisACell) DO BEGIN GetWSCellString(WSHand,LoopRow,1,ClassNameinWorksheet); GetWSCellString(WSHand,LoopRow,2,ClassDescriptioninWorksheet); If ClassNameinWorksheet <> '' THEN NameClass(ClassNameinWorksheet); ClassHandle := GetObject(ClassNameinWorksheet); BResult := SetDescriptionText(ClassHandle, ClassDescriptioninWorksheet); IsThisACell:=IsValidWSCell(WSHand,LoopRow + 1,1); LoopRow := LoopRow + 1; END; END; RUN(CreateClasssesFromWorksheet); Quote Link to comment
Matteo New Posted June 9, 2017 Share Posted June 9, 2017 wow, great. that definitely does help!!! thank you! Quote Link to comment
RubenH Posted July 3, 2019 Share Posted July 3, 2019 Hello, Fantastic thread! Is there a way to assign the attributes at creation in the methods described above. All from a table? Any clue is welcomed. Quote Link to comment
michaelk Posted July 4, 2019 Share Posted July 4, 2019 I haven't tried it, but I wonder if it would be possible to make the worksheet entries for the class attributes human readable. Perhaps. Check out this thread: At the end of the thread is a script that uses the graphic attributes of a selected object to create a class with the objects attributes and one to edit the graphic attributes of a class. 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.