michaelk Posted September 21, 2016 Share Posted September 21, 2016 I'd like a new contextual click / menu command to create a new class with the graphic attributes of the selected object. mk 3 Quote Link to comment
0 michaelk Posted October 20, 2018 Author Share Posted October 20, 2018 It occurs to me that it might have been a good idea to put a logic test in to make sure you don't run this script when the selected object is in the None class. Be careful out there. Quote Link to comment
0 markdd Posted October 20, 2018 Share Posted October 20, 2018 This script is definitely going to join the category of "I don't know what I ever did without it" tools. Thanks Michael. The other command I would love to have is "Edit Class of selected object".Any takers?! Mark 1 Quote Link to comment
0 michaelk Posted October 21, 2018 Author Share Posted October 21, 2018 Glad you like it. I use that first script all the time. So you'd like a script that opens the Edit Class dialog for the class of the currently selected object? I'm not aware of a VS function that has access to that dialog box. @Pat Stanford? Quote Link to comment
0 markdd Posted October 22, 2018 Share Posted October 22, 2018 Yes. It would be a tool to get passed the Organisation Dialogue and the search for the class you want to edit and straight to the specific Edit Class dialogue. It would make my way of working so much more efficient. Quote Link to comment
0 mgries Posted October 22, 2018 Share Posted October 22, 2018 @michaelk thanks for hooking it up! I haven't had a chance to use it, but I really appreciate that both of these tools exist now! Quote Link to comment
0 mgries Posted October 22, 2018 Share Posted October 22, 2018 6 hours ago, markdd said: It would make my way of working so much more efficient. Yes! This 3rd script would kind of complete the right click dream work flow. Good call @markdd Quote Link to comment
0 Boh Posted October 25, 2018 Share Posted October 25, 2018 On 10/20/2018 at 6:37 PM, michaelk said: Try this: So I just used the MakeClassWithObjAttribs script for the first time on an actual project file and it went weird on me. A whole bunch of notes & annotations all 'disappeared' from every sheet layer. They were still selectable but no colour or fill even though the attributes palette say attributes are still 'by-class'. Many, but not all disappeared objects are on the none class. The none class is not listing in the organisation dialogue but is listing in the navigation palette. Couldn't undo so need to recover file from backup. Hmmm...... Quote Link to comment
0 michaelk Posted October 25, 2018 Author Share Posted October 25, 2018 Any chance you can send me the file to take a look at? Feel free to send it in a personal message. Quote Link to comment
0 Boh Posted October 25, 2018 Share Posted October 25, 2018 Ok. Sent you the file. Hopefully you can see where things are going pear shape. 🙂 Cheers Quote Link to comment
0 michaelk Posted October 25, 2018 Author Share Posted October 25, 2018 Thanks for sending the file. I was able to replicate the problem immediately. The problem - and I don't know why this is a problem yet - occurs when the selected object is in the annotation space or inside a group. If you put the object directly on a design or sheet layer it works fine. In the example in your file when you run the script on an object inside the annotation space it is setting the pen opacity of the None class to 0! (Not working as designed:-) It also behaves strangely when selecting one of the rectangles in a group. In my quick test it ignored the change and reset it self to the old attributes. For now: Just duplicate the object and paste it directly on the design or sheet layer - not inside of a group or annotation space. Then run the script and delete the object. We'll have to do a little debugging! 🕷️ Quote Link to comment
0 Boh Posted October 26, 2018 Share Posted October 26, 2018 Oh I didn't notice it was the opacity setting changing. Well spotted! I was looking at lineweight, pen colour etc. When I change the none class opacity back to 100% all seems to go back to normal. Will make sure I use this script only outside groups/viewports for the meantime. Cheers Quote Link to comment
0 michaelk Posted October 30, 2018 Author Share Posted October 30, 2018 OK. With a lot of help from @Pat Stanford & @JBenghiat here is a working version that doesn't get freaked out by an object inside a group. Let me know if there are any more surprises! Procedure EditClassOfSelectedObject; {************************************************* October 29, 2018. Ok. The previous version of the script was horribly done. Even by my standards. This version uses the Waldo technique (thanks Josh and Patrick!) to get the actual handle of the selected object. Even if that object is in a group.} {************************************************* This is a fork of the original script described in the comments below. *************************************************} {Unceremoniously an inelegantly forked by Michael Klaers October 19, 2018} {This script will update the class of the selected object to have the attributes that the object currently has. It will force that class to be Use at Creation and the object will be forced to have all attribues by class} {*********************************************************} {© 2016, Pat Stanford pat@coviana.com} {Licensed under the GNU Lesser General Public License} {No warranty or guarantee, expressed or implied. Use at your own risk.} {Test for suitability for your use before using on live data.} {Immediately discontinue use if hair loss occurs.} {December 2, 2016} {This script creates a new class and sets the class attributes to those of the selected} {object. The only parameter that is not set is TextStyle} {Based on a request on the tech board by michaelk, September 21, 2016.} {Updated by Michael Klaers May 8 2017.} {Changes: 1) Newly created class will have "Use At Creation" checked.} { 2) Active class will not change to newly created class.} {Updated by Michael Klaers October 2 2018} {Changes: 3) Selected object will be in the new class, not the active class} {Updated by Michael Klaers October 4 2018} {Changes: 4) Selected object attributes will all be by class} VAR FPat: LONGINT; FillBackR,FillBackG,FillBackB: LONGINT; FillForeR,FillForeG,FillForeB: LONGINT; LineS: LONGINT; LineW: INTEGER; ObjBMarkStyl: LONGINT; ObjBMarkAngle: INTEGER; ObjBMarkSize: REAL; ObjBMarkWidth: REAL; ObjBMarkThickB: INTEGER; ObjBMarkThick: REAL; ObjBMarkVis: BOOLEAN; ObjEMarkStyl: LONGINT; ObjEMarkAngle: INTEGER; ObjEMarkSize: REAL; ObjEMarkWidth: REAL; ObjEMarkThickB: INTEGER; ObjEMarkThick: REAL; ObjEMarkVis: BOOLEAN; POpacity: INTEGER; FOpacity: INTEGER; PenBackR,PenBackG,PenBackB: LONGINT; PenForeR,PenForeG,PenForeB: LONGINT; DSEnabled: BOOLEAN; DSnUnits: INTEGER; DSdOffset: REAL; DSdBlurRadius: REAL; DSdAngle: REAL; DSOpacity: INTEGER; DSRed: INTEGER; DSGreen: INTEGER; DSBlue: INTEGER; ThisObject: HANDLE; SelectedCount: LONGINT; ReturnBool: BOOLEAN; Class2Edit: STRING; SetExistingClass: BOOLEAN; ActiveClassName: STRING; Waldo: HANDLE; BEGIN {*************************** Make sure only one object selected ***************************} ThisObject:=Nil; If NumSObj(ActLayer) =1 then Begin {*************************** Get handle to selected object ***************************} Locus(0,0); Waldo := LNewObj; ThisObject := PrevSObj(Waldo); IF (Waldo <> nil) THEN DelObject(waldo); {*************************** Get all graphic attributes of selected object ***************************} FPat := GetFPat(ThisObject); GetFillBack(ThisObject,FillBackR,FillBackG,FillBackB); GetFillFore(ThisObject,FillForeR,FillForeG,FillForeB); LineS:=GetLSN(ThisObject); LineW:=GetLW(ThisObject); ReturnBool:=GetObjBeginningMarker(ThisObject,ObjBMarkStyl,ObjBMarkAngle,ObjBMarkSize, ObjBMarkWidth,ObjBMarkThickB,ObjBMarkThick, ObjBMarkVis); ReturnBool:=GetObjEndMarker(ThisObject,ObjEMarkStyl,ObjEMarkAngle,ObjEMarksize,ObjEMarkWidth, ObjEMarkThickB,ObjEMarkThick,ObjEMarkVis); ReturnBool:=GetOpacityN(ThisObject,POpacity,FOpacity); GetPenBack(ThisObject,PenBackR,PenBackG,PenBackB); GetPenFore(ThisObject,PenForeR,PenForeG,PenForeB); DSEnabled:=IsDropShadowEnabled(ThisObject); ReturnBool:=GetDropShadowData(ThisObject,DSnUnits,DSdOffset, DSdBlurRadius,DSdAngle,DSOpacity, DSRed,DSGreen,DSBlue); {*************************** Write those attributes to class of selected object ***************************} Class2Edit:=GetClass(ThisObject); SetClFPat(Class2Edit,FPat); SetClFillBack(Class2Edit,FillBackR,FillBackG,FillBackB); SetClFillFore(Class2Edit,FillForeR,FillForeG,FillForeB); SetClLSN(Class2Edit,LineS); SetClLW(Class2Edit,LineW); ReturnBool:=SetClassBeginningMarker(Class2Edit, ObjBMarkStyl,ObjBMarkAngle,ObjBMarkSize, ObjBMarkWidth,ObjBMarkThickB,ObjBMarkThick); ReturnBool:=SetClassEndMarker(Class2Edit, ObjEMarkStyl,ObjEMarkAngle,ObjEMarksize, ObjEMarkWidth,ObjEMarkThickB,ObjEMarkThick); SetClOpacityN(Class2Edit,FOpacity,POpacity); SetClPenBack(Class2Edit,PenBackR,PenBackG,PenBackB); SetClPenFore(Class2Edit,PenForeR,PenForeG,PenForeB); EnableCLDropShadow(Class2Edit,DSEnabled); SetCLDrpShadowData(Class2Edit,DSnUnits,DSdOffset, DSdBlurRadius,DSdAngle,DSOpacity, DSRed,DSGreen,DSBlue); {*************************** Set all attributes of selected object back to By Class ***************************} SetClass(ThisObject,Class2Edit); SetFPatByClass(ThisObject); SetFillColorByClass(ThisObject); SetLSByClass(ThisObject); SetLWByClass(ThisObject); SetMarkerByClass(ThisObject); SetOpacityByClass(ThisObject); SetPenColorByClass(ThisObject); SetTextStyleByClass(ThisObject); End END; Run(EditClassOfSelectedObject); Edit Class Fix.vwx 2 Quote Link to comment
0 Boh Posted October 31, 2018 Share Posted October 31, 2018 Liking that Waldo technique! Thanks Michael. All seems to be working well! Quote Link to comment
0 michaelk Posted October 31, 2018 Author Share Posted October 31, 2018 I started writing scripts 6 or 7 years ago. In all that time I never realized one of the most common functions for getting a handle to the selected object actually returns the group (if any) that contains the object. Hence the Where's Waldo technique. I wonder what other revelations I'm in for… 1 Quote Link to comment
0 TD-Ben Posted January 16, 2020 Share Posted January 16, 2020 Thanks for this script. I am very new to Vectorworks, but did manage to add the script. However, I created a class from an object with a 20% fill opacity, and full pen opacity, and the class that was created switched those two values. Also, I noticed the object from which I created the class did not get added to the class. Any suggestions, or additional ideas? Quote Link to comment
0 Pat Stanford Posted January 18, 2020 Share Posted January 18, 2020 @michaelk This is your script. You want to take a look. It looks like you followed the function descriptions in the manual directly, but I think either GetClOpacityN or SetClOpacityN are wrong in that the Fill and Pen are reversed between the two in the Function Reference. @TD-Ben Since the object had to be in the Class originally, I don't understand what you mean about the object not getting added to the class? Quote Link to comment
0 michaelk Posted January 19, 2020 Author Share Posted January 19, 2020 Nice catch, @TD-Ben. I'll see if I can figure this out. I took a quick look at it and I agree with @Pat Stanford. It looks like it should be correct. But scripts always look to me like they should be correct, even when they don't work. 🤓 Quote Link to comment
0 michaelk Posted January 19, 2020 Author Share Posted January 19, 2020 @Pat Stanford, I think you're right. It looks like the arguments on SetCLOpacityN are actually backwards to the documentation. It's also not taking effect until the object is forced to redraw. hmmmmmmmmmm Quote Link to comment
0 Pat Stanford Posted January 19, 2020 Share Posted January 19, 2020 Redraw required? Or can you use a ResetObject at the end of the script? When you confirm which call the docs are backwards on, let me know and I will file a documentation bug on it. Quote Link to comment
0 michaelk Posted January 19, 2020 Author Share Posted January 19, 2020 It works in the original script without a redraw. It falls down in my test script. Another mystery 🙂 Quote Link to comment
0 collins Posted October 25, 2020 Share Posted October 25, 2020 This sounds brilliant and just what I've been looking for. However, can somebody please break down exactly what is necessary to install this from downloading the 'New Class From Object Script II.vwx' file @michaelk posted as I've used scripts etc. Quote Link to comment
0 Boh Posted October 25, 2020 Share Posted October 25, 2020 Scripts are just another resource that you can import from other files. If you download the file you can import the script into one of your own files, perhaps a library and/or template file? You need to place scripts into script palettes. Vw will ask you which palette to place the script or you can create a new one. Once imported go to the bottom of the windows menu, select the file and check next to the palette to display it. 2 Quote Link to comment
0 collins Posted October 27, 2020 Share Posted October 27, 2020 This place saves my life. Thank you 2 Quote Link to comment
0 trashcan Posted April 28, 2022 Share Posted April 28, 2022 You guys are absolute legends ✅ 1 Quote Link to comment
0 trashcan Posted April 28, 2022 Share Posted April 28, 2022 (edited) Quick question - how would one modify the script so that the items in the group do not switch to the None class? Using "New Class From Object Script II" jk Edited April 28, 2022 by trashcan Quote Link to comment
Question
michaelk
I'd like a new contextual click / menu command to create a new class with the graphic attributes of the selected object.
mk
Link to comment
Top Posters For This Question
23
10
9
4
Popular Days
Oct 4
13
Apr 29
7
Oct 25
4
Jan 19
4
Top Posters For This Question
michaelk 23 posts
Boh 10 posts
Pat Stanford 9 posts
markdd 4 posts
Popular Days
Oct 4 2018
13 posts
Apr 29 2022
7 posts
Oct 25 2018
4 posts
Jan 19 2020
4 posts
Popular Posts
michaelk
This has been really helpful, Pat. I'm posting a slight update to it. This script is the exactly the same as the above except: 1. The newly created script will hav
Pat Stanford
About time some of our script got Sherlocked. They are good ideas!! 😉
michaelk
I'd like a new contextual click / menu command to create a new class with the graphic attributes of the selected object. mk
Posted Images
61 answers to this question
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.