Pat Stanford Posted November 6, 2015 Share Posted November 6, 2015 This script was written based on a query in another forum: https://techboard.vectorworks.net/ubbthreads.php?ubb=showflat&Number=218975#Post218975 Procedure SymbolContentsToByClass; {If the selected object in a drawing is a symbol, it locates the} {symbol definition and converts all objects inside the definition} {to use the ByClass option for all attributes} {November 6, 2015} {© 2015, Pat Stanford pat@coviana.com} {Licensed under the GNU Lesser General Public License} {This has only been lightly tested. I recommend that you use this on a } {copy of your primary file. No warranty expressed or implied. Use at} {your own risk. Do not operate heavy machinery while using this script.} Var H1, H2, H3: Handle; SymDefName: String; Begin H1:=FSActLayer; If GetType(H1)=15 then Begin SymDefName:=GetSymName(H1); H2:=GetObject(SymDefName); H3:=FinSymDef(H2); While H3 <> Nil do Begin SetLSByClass(H3); SetLWByClass(H3); SetMarkerByClass(H3); SetOpacityByClass(H3); SetPenColorByClass(H3); SetFPatByClass(H3); SetFillColorByClass(H3); H3:=NextObj(H3); End; End; ResetObject(H1); RedrawAll; End; Run(SymbolContentsToByClass); Quote Link to comment
Boh Posted December 14, 2017 Share Posted December 14, 2017 (edited) Just tried this and it works! Is it easy to change this script it's inverse? (i.e.Remove all "by-class" settings of objects in a symbol). Edited December 14, 2017 by Boh Quote Link to comment
MullinRJ Posted December 21, 2017 Share Posted December 21, 2017 Boh, There may be a more elegant way to remove the Attributes-By-Class setting for selected objects, but I can't find it. I can only do it by removing each attribute individually. Here's a script to that effect. This will work on multiple selected symbols, but not on nested symbols. If a symbol definition contains other symbol instancess, they will not be affected. You will have to run this script on instances of each symbol you want to convert. You can place them in the drawing, select them all, then run the script once. After this script is run, you will not see any differences in the symbol's appearance. The objects inside will have the same attributes as the classes they are in. However, if you then change the appearance of a controlling class, these symbols will not follow the new class appearance since their contents no longer are set By-Class. I hope this is what you were looking for. Raymond Procedure SymbolContentsNotByClass; { If the selected objects in a drawing are symbols, this script locates } { each symbol definition and converts all objects inside the definition } { to REMOVE the SetByClass option for all attributes. } { 21 December 2017 - Raymond Mullin } { This has been less than lightly tested. Pat Stanford recommends you use } { this on a copy of your primary file. No warranty expressed or implied. } { Use at your own risk. Do not operate heavy machinery while using this script. } { I concur. } VAR SymH, H: Handle; B, visibility :Boolean; thickBasis, angul, Opacity, PenOp, FillOp :Integer; style, Red, Grn, Blu :Longint; size, wydth, thickness :Real; BEGIN SymH := FSActLayer; while (SymH <> Nil) do begin if (GetTypeN(SymH) = 15) then begin { if it is a Symbol } H := FinSymDef(GetObject(GetSymName(SymH))); while (H <> Nil) do begin SetLW(H, GetLW(H)); SetLSN(H, GetLSN(H)); GetPenFore(H, Red, Grn, Blu); SetPenFore(H, Red, Grn, Blu); GetPenBack(H, Red, Grn, Blu); SetPenBack(H, Red, Grn, Blu); SetFPat(H, GetFPat(H)); GetFillFore(H, Red, Grn, Blu); SetFillFore(H, Red, Grn, Blu); GetFillBack(H, Red, Grn, Blu); SetFillBack(H, Red, Grn, Blu); if GetObjBeginningMarker(H, style, angul, size, wydth, thickBasis, thickness, visibility) then B := SetObjBeginningMarker(H, style, angul, size, wydth, thickBasis, thickness, visibility); if GetObjEndMarker(H, style, angul, size, wydth, thickBasis, thickness, visibility) then B := SetObjEndMarker(H, style, angul, size, wydth, thickBasis, thickness, visibility); { For VW 2016 and earlier, use the following for Opacity: } GetOpacity(H, Opacity); SetOpacity(H, Opacity); { For VW 2017 and later, use the following for Opacity: } { if GetOpacityN(H, PenOp, FillOp) then B := SetOpacityN(H, PenOp, FillOp); } H := NextObj(H); end; { while (H <> Nil) } ResetObject(SymH); end; { if } SymH := NextSObj(SymH); end; { while (SymH <> Nil) } RedrawAll; END; Run(SymbolContentsNotByClass); Quote Link to comment
Boh Posted December 21, 2017 Share Posted December 21, 2017 That is brilliant Raymond! Thank you. Perfect for me as I am sorting out my library of symbols so very useful. Quote Link to comment
MullinRJ Posted December 21, 2017 Share Posted December 21, 2017 You're welcome. Quote Link to comment
Andy Broomell Posted March 24, 2021 Share Posted March 24, 2021 (edited) @MullinRJ - This is fantastic, and in fact is really close to what I was recently looking for in this thread. Any way to adjust the script so that it works on all symbol definitions in the current file's RM, rather than on selected objects? If not, this will make due in the meantime. Alternatively, I wonder if there's a script that inserts one instance of every symbol definition into the document, which could be ran first? [EDIT - This script does the job] Edited March 24, 2021 by Andy Broomell Quote Link to comment
MullinRJ Posted March 25, 2021 Share Posted March 25, 2021 Hi @Andy Broomell , Yes, with some minor changes to the preceding script, the following script "should" convert the entire Symbol Library, but there are no guarantees. I will leave it to you to tell me if it works. It's 2 AM and I only whimsically ran this script through its paces, meaning I tried it once, it ran, and I posted it below. I did test it on Symbols stored in Folders and it appears to work. Try it on COPIES of your working files several times before committing to your real work. Procedure AllSymbolContentsNotByClass; { This script converts every object inside all symbol definitions } { to REMOVE the SetByClass option for all object attributes. } { 24 March 2021 - Raymond Mullin } { This has been less than lightly tested. Pat Stanford recommends you: } { "Use this on a copy of your primary file. No warranty expressed or implied. } { Use at your own risk. Do not operate heavy machinery while using this script." } { I concur. } function RemoveSetByClass(SymH :Handle) :Boolean; Var H: Handle; B, visibility :Boolean; thickBasis, angul, Opasity, PenOp, FillOp :Integer; style, Red, Grn, Blu :Longint; size, wydth, thickness :Real; Begin if (GetTypeN(SymH) = 16) then begin { if it is a Symbol Definition } H := FInSymDef(SymH); while (H <> Nil) do begin SetLW(H, GetLW(H)); SetLSN(H, GetLSN(H)); GetPenFore(H, Red, Grn, Blu); SetPenFore(H, Red, Grn, Blu); GetPenBack(H, Red, Grn, Blu); SetPenBack(H, Red, Grn, Blu); SetFPat(H, GetFPat(H)); GetFillFore(H, Red, Grn, Blu); SetFillFore(H, Red, Grn, Blu); GetFillBack(H, Red, Grn, Blu); SetFillBack(H, Red, Grn, Blu); if GetObjBeginningMarker(H, style, angul, size, wydth, thickBasis, thickness, visibility) then B := SetObjBeginningMarker(H, style, angul, size, wydth, thickBasis, thickness, visibility); if GetObjEndMarker(H, style, angul, size, wydth, thickBasis, thickness, visibility) then B := SetObjEndMarker(H, style, angul, size, wydth, thickBasis, thickness, visibility); { For VW 2016 and earlier, use the following for Opacity: } { GetOpacity(H, Opasity); } { SetOpacity(H, Opasity); } { For VW 2017 and later, use the following for Opacity: } if GetOpacityN(H, PenOp, FillOp) then B := SetOpacityN(H, PenOp, FillOp); H := NextObj(H); end; { while (H <> Nil) } ResetObject(SymH); end; { if } End; { RemoveSetByClass } BEGIN ForEachObjectInList(RemoveSetByClass, 0, 2, FSymDef); SysBeep; { make noise when done } END; Run(AllSymbolContentsNotByClass); Good night, and good luck, Raymond 2 Quote Link to comment
Andy Broomell Posted March 25, 2021 Share Posted March 25, 2021 The first time I tried it something weird happened (might've been unrelated to script), but then I restarted VW and it worked fine in all subsequent tests. Thanks Raymond!! 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.