Tom W. Posted March 31, 2023 Share Posted March 31, 2023 Does anyone know a way to create a script that would allow me to more easily switch between two different classes I use for my Dimensions? I have one class with a black pen + another with a red pen + it's a bit of a faff going into doc prefs each time to switch between them: Plus I don't know which class I've got it set to until I create a Dimension or check these settings. It would be great to have a 'Dimensions Red' script which sets it to one class + a 'Dimensions Black' script that sets it to the other that I could double-click on in a script palette. Or turn into menu commands. Is this possible? Thanks Quote Link to comment
markdd Posted March 31, 2023 Share Posted March 31, 2023 (edited) Yes, this is very possible. You could make a script using the custom tool/attribute command. Just turn off the automatic assignment of dimensions in doc prefs and take it from there. The only drawback is that you will need to make a separate script for each dimension tool you wish to use. Edited March 31, 2023 by markdd 1 Quote Link to comment
Tom W. Posted March 31, 2023 Author Share Posted March 31, 2023 21 minutes ago, markdd said: Yes, this is very possible. You could make a script using the custom tool/attribute command. Just turn off the automatic assignment of dimensions in doc prefs and take it from there. The only drawback is that you will need to make a separate script for each dimension tool you wish to use. That's a good idea thank you. I would still be interested to know what would be involved in scripting the class change if anyone had time to look at it. Some scripts I use are incredibly useful but also incredibly simple (to the person that wrote them that is - not me 🙂) + I wondered whether this fell into the same category. Preference 545 has been mentioned... Quote Link to comment
Vectorworks, Inc Employee jcogdell Posted March 31, 2023 Vectorworks, Inc Employee Share Posted March 31, 2023 Another option would be to again turn of the automatic classing but instead of a script use saved views to control the active class. These views can then be saved into your template file so they are always available. Quote Link to comment
Tom W. Posted March 31, 2023 Author Share Posted March 31, 2023 10 minutes ago, jcogdell said: Another option would be to again turn of the automatic classing but instead of a script use saved views to control the active class. These views can then be saved into your template file so they are always available. Thank you yes but be better if the active class wasn't changed. @markdd's suggestion works very well, the only disadvantage like he says is that I need a pair of scripts for the Constrained Linear Dimensions Tool + another pair for the Unconstrained Linear Dimensions Tool. 1 Quote Link to comment
Tom W. Posted March 31, 2023 Author Share Posted March 31, 2023 1 hour ago, markdd said: Yes, this is very possible. You could make a script using the custom tool/attribute command. Just turn off the automatic assignment of dimensions in doc prefs and take it from there. The only drawback is that you will need to make a separate script for each dimension tool you wish to use. I also like the fact that I'm clicking on a script that is telling me what colour the dim will be before I draw it which was one of the issues I had before. Cool! Quote Link to comment
markdd Posted March 31, 2023 Share Posted March 31, 2023 .....you could also create a menu command and therefore a keyboard shortcut..... Quote Link to comment
Tom W. Posted March 31, 2023 Author Share Posted March 31, 2023 Just now, markdd said: .....you could also create a menu command and therefore a keyboard shortcut..... Yes absolutely. I think if I had a script to change the default class from the black class + another to change it to the red class I would set them up as menu commands as it would only be two commands but with the Custom Tool/Attribute method I already have four commands + will be more if I add Angular or other dimensions which will end up being too many shortcuts for me to remember... 🙂 Quote Link to comment
zoomer Posted March 31, 2023 Share Posted March 31, 2023 Can't you do that in Datamanager ? Or can't it differentiate between constrained and unconstrained Dimension ? Quote Link to comment
Tom W. Posted March 31, 2023 Author Share Posted March 31, 2023 9 minutes ago, zoomer said: Can't you do that in Datamanager ? Or can't it differentiate between constrained and unconstrained Dimension ? I'm not sure I understand... Quote Link to comment
zoomer Posted March 31, 2023 Share Posted March 31, 2023 I have not yet used Datamanager. But it is very popular in Germany. AFAIR you can make it assigning Classes to any Object or change default Classes of PIOs (?) So as both Dimensions look like separate tools, I think it may be possible to make them draw in customizable Classes. Quote Link to comment
Tom W. Posted March 31, 2023 Author Share Posted March 31, 2023 I have only used it a tiny bit but I think it's more a case that you can set it up to attach Records to objects based on their class. So I have Slab styles that automatically assign to certain classes on creation, and based on those classes they automatically have certain Records attached to them... Quote Link to comment
Pat Stanford Posted March 31, 2023 Share Posted March 31, 2023 I have played with this and the 545 preference does not seem to return what I expected it to return. In the VS Appendix it says: So my impression from that is that the ID for the class the dimensions should be stored into. My hunch was that this would be the value to pass to ClassList(LongInt) to get the class name. But, alas, in my test, then 545 pref always returns a value of 3 regardless of how many items are in the Class List or the value in the highlighted field in the Document Preferences (below). Anyone have any ideas on how to access and set the value of the highlighted field in the document preferences? @MullinRJ Do any of your magic pref tracking bloodhounds hold any hope on this? I have run up to 9999 and no PrefLongInt appears to return the correct value. Any help appreciated. 1 Quote Link to comment
MullinRJ Posted March 31, 2023 Share Posted March 31, 2023 1 hour ago, Pat Stanford said: @MullinRJ Do any of your magic pref tracking bloodhounds hold any hope on this? @Pat Stanford, You are Soooooo close. Pref 546 is the one you want. The Script Reference Appendix is wrong. Message( GetPrefLongint(546), ' ', Index2Name(GetPrefLongint(546)) ); { Show the default dimension class } Raymond 1 Quote Link to comment
Pat Stanford Posted March 31, 2023 Share Posted March 31, 2023 Thank you Raymond. I was off on two counts: 1. I used the wrong PrefNumber. I had actually tried 544 and 546 but since I was off on the second count also it didn't work. 2. I was assuming that the value would be applied to the ClassList function instead of the Index2Name list. Thanks for the help. Pat 1 Quote Link to comment
MullinRJ Posted March 31, 2023 Share Posted March 31, 2023 Additionally, Pref 44 has to be TRUE for that change to take effect. If Pref 44 is FALSE, the dimension objects will be placed it the Active Class. Raymond 1 Quote Link to comment
Pat Stanford Posted March 31, 2023 Share Posted March 31, 2023 I agree on the Pref 44. But I think the Class will change no matter the setting of 44. It just won't auto class the dims. Here is the script to toggle between two different classes for Dimension Auto Classing. Change the names in the Const section at the top of the program to match the two classes you want to use. You could add a Message command in each of the If and Then blocks to tell you which class you set as active. Procedure SwapDimsAutoClass; {©2023 Pat Stanford - pat@coviana.com} {licensed under the Boost Software License 1.0} {https://github.com/boostorg/boost/blob/master/LICENSE_1_0.txt} {TL/DR Use as you want, attribution for source, No warranty} {With great thanks the Raymond Mullin (@MullinRJ) for help in} {identifying the proper Preference code.} CONST C1='Dimension'; C2='None'; VAR H1 :Handle; L1,L2,L3 :LongInt; N1 :Integer; R1 :Real; S1 :String; BEGIN S1:=Index2Name(GetPrefLongInt(546)); If S1=C1 Then BEGIN SetPrefLongInt(546,Name2Index(C2)); End ELSE BEGIN SetPrefLongInt(546,Name2Index(C1)); End; End; Run(SwapDimsAutoClass); 1 Quote Link to comment
MullinRJ Posted March 31, 2023 Share Posted March 31, 2023 7 minutes ago, Pat Stanford said: I agree on the Pref 44. But I think the Class will change no matter the setting of 44. It just won't auto class the dims. I'm not sure we're saying the same thing, but we may be. If Pref 44 is FALSE, dimensions go into the ACTIVE CLASS. Else, when Pref 44 is TRUE, dimensions go into the class defined by Pref 546, i.e. the Default Dimension Class. So, if you want to toggle between the "Dimension" class and the Active Class, you only need to toggle Pref 44. However, if you want to toggle between "ClassA" , and "ClassB" then a script like yours will work, but to be sure it does, you should also check and set Pref 44, because if it is ever FALSE, your script will mysteriously fail to work. I know, that's unlikely, but not impossible. Raymond 2 Quote Link to comment
Pat Stanford Posted April 1, 2023 Share Posted April 1, 2023 Have to leave something for @Tom W. to do and add to the script it we are ever going to make him part of the cult. 😉😂 1 1 Quote Link to comment
Tom W. Posted April 1, 2023 Author Share Posted April 1, 2023 (edited) @Pat Stanford + @MullinRJ thank you so much for this it's great! Ha ha most cults are easier to join than this one: I literally have NO clue about any of what you're doing + unlike other stuff in VW no amount of trial + error is going to help me find out unless I invest some time in coding training (I did NOT study computers at school: my training is in fine art of all things so about as far away from this as you can get!). Anyway I am going to take the plunge + buy some 'coding for dummies' books + see where it leaves me because I can't keep asking you guys for help without being able to bring anything to the table myself... 🙂 In the meantime however (😆), can you explain what you mean about Pref 44? You're saying to make the script bullet-proof an extra line of code should be added that specifies that Pref 44 is True as this will then make it impossible for the Dimension objects to be inadvertently assigned to the active class? Also (😁), when you say... 11 hours ago, Pat Stanford said: You could add a Message command in each of the If and Then blocks to tell you which class you set as active. ...what form exactly would the telling take? Actually I just looked on the developer site + saw this: https://developer.vectorworks.net/index.php/VS:Introduction. So could the script here be adapted + incorporated into the SwapDimsAutoClass script so that it displays 'Dimensions - Red' or 'Dimensions - Black' in the 'message bar' (what's this: the status bar at the bottom of the screen?) depending on the dims-auto-class being toggled? That would be pretty cool. Thanks again I appreciate it. (Another question would be what would happen if you wanted to toggle between more than two classes? I don't, don't worry, but would that make things a lot more complex script-wise or relatively easy to achieve?) Edited April 1, 2023 by Tom W. Quote Link to comment
MullinRJ Posted April 1, 2023 Share Posted April 1, 2023 (edited) Pref 44 is shorthand for VW Application Preference 44. It is a boolean flag, meaning it has a value of True or False. Use Boo := GetPref(44); to read the value into boolean variable "Boo", SetPref(44, True); to set the flag, and SetPref(44, False); to clear the flag. The results of these commands can be seen in the Document Preferences dialog. The checkbox will change states with this Pref 44 value, or vice versa. Pref 546 is in the newer versions of VW and you would use L := GetPrefLongint(546); to read it into variable "L", which you define as a LONGINT. Poof – You are now in the Cult. Drink the KoolAid and Smile 😁 Next Week we'll explore Toggle Scripts. Raymond Edited April 1, 2023 by MullinRJ 1 Quote Link to comment
Tom W. Posted April 1, 2023 Author Share Posted April 1, 2023 Well I think I'm probably stood in the queue for the cult but not through the door yet... 😁 Thank you so adding the Pref 44 section to the script would serve to enable the 'Create dimensions in class' setting should it happen to be unchecked when the script was run? Ok gotcha. That's clever. And makes it fool proof (important). I will need my coding for dummies books before I would know how to insert it into the script though 🙂 Quote Link to comment
Pat Stanford Posted April 1, 2023 Share Posted April 1, 2023 Raymond answered the SetPref(44) part. Mostly. What he didn't say is that one place you could put it is immediately after the first Begin statement. As for the Message part, Message is the Vectorscript command to open a message window and show the user something. You can put pretty much anything you want in the message and it will convert each bit to a String and Concatenate them all together. Separate each part by a comma. I like to include the date and time so I actually know when a window is sitting around if the message is new or old. So I would put something like: Message(Date(2,2),' The Automatic Class for Dims is: ', C1); Adjust the C1 to C2 for the appropriate line. Note the things that you put in as text need to be surrounded by single quotes. I often find myself needing to add spaces between parts of the message command using ' '. And don't worry about asking and not donating back. I know I almost always learn something from every question. As long as you are willing to try things and gets your hands dirty, we are happy to help. 1 Quote Link to comment
Tom W. Posted April 1, 2023 Author Share Posted April 1, 2023 This is great thank you. It gives me two things I can play around with + see if I can get to work which is just what I need. Don't wait up I may be some time... 😁 Quote Link to comment
Pat Stanford Posted April 11, 2023 Share Posted April 11, 2023 Here you go Tom. This one cycles between multiple classes. Edit the value of C1 to list the classes separated by commas (no extra spaces) and the value of Options to be the number of classes you put in C1. Procedure CycleDimsAutoClass; {©2023 Pat Stanford - pat@coviana.com} {licensed under the Boost Software License 1.0} {https://github.com/boostorg/boost/blob/master/LICENSE_1_0.txt} {TL/DR Use as you want, attribution for source, No warranty} {With great thanks the Raymond Mullin (@MullinRJ) for help in} {identifying the proper Preference code.} {April 11, 2023} {This script cycles between a number of different classes for } {the VW AutoDimension Class.} {HOW TO CONFIGURE} {Change the values in Options to the number of different classes} {you want to cycle through. Set C1 to the class names you want} {in the order you want to cycle through them separated by} {commas. Make sure the Options and the number of classes} {you store in C1 match.} {This version offers two different notifications of what Class} {has been activated. these are the Message and AlertInform} {lines at the bottom of the script. delete either or both if} {you don't like or need this information. AlertInform shows} {the class name in the data bar at the bottom of the Screen} {which is nice, but it also beeps. Message opens the message} {box, but scripts have not control over the size or location} {of the message box. Also the message will not clear automatically} {as you perform other functions.} CONST Options=6; C1='Dimension,None,John,Paul,George,Ringo'; VAR H1 :Handle; L1,L2,L3 :LongInt; N1, N2 :Integer; R1 :Real; S1 :String; A1 :DynArray of String; BEGIN Allocate A1[1..Options]; For N1:= 1 to Options DO BEGIN A1[N1]:=SubString(C1,',',N1); End; S1:=Index2Name(GetPrefLongInt(546)); N2:=1; For N1:=1 to Options DO Begin If S1=A1[N1] Then N2:=N1+1; End; If N2>Options then N2:=1; SetPref(44, True); SetPrefLongInt(546,Name2Index(A1[N2])); Message('The Dimension Autoclass has been set to: ',A1[N2]); AlertInform(A1[N2],'The Dimesino Autoclass has been set to:',True); End; Run(CycleDimsAutoClass); 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.