Jump to content

MullinRJ

Member
  • Posts

    1,992
  • Joined

  • Last visited

Posts posted by MullinRJ

  1. @bsalee,

       If you only want assign a static class name, the script is easy. But if you want to be able to redefine a new Class Name often, the script will need to be more complicated. You can edit this script, or have multiple copies of it in your file, each with a different class name to set commonly used class names. If the class name in this script does not exist in your file, it will be created so you won't have to create it ahead of time.

     

       For starters, place the following script in one of your files by adding it to a Script Palette (new or existing). Duplicate it if you want a choice of class names. If you like how it works, you can add this script(s) to your template files so it(they) will always be there when you start new work; or make a Menu Command plug-in, where you can assign a HotKey to it; or make a Tool plug-in, which can also have an assigned HotKey. More on the second and third options when you get that far.

     

    Here's the simple script:

     

    PROCEDURE ChangeDimClassName;
    { Click on Dimension objects to change their class to the class name defined in "kNewClass". }
    { Change constant "kNewClass" to suit your needs. }
    { If the object you select is not a Dimension object, nothing happens and program continues. }
    { To STOP, click in empty drawing space, or press any key on keyboard. }
    { 9 Apr 2023 - Raymond Mullin }
    CONST
    	kNewClass = 'New Dim Class';
    	kDimType = 63;
    VAR
    	H :Handle;
    	X, Y :Real;
    BEGIN
    	H := FObject;	{ dummy handle }
    	while (H <> nil) do begin
    		GetPt(X, Y);
    		H := PickObject(X, Y);
    		if (GetTypeN(H) = kDimType) then
    			SetClass(H, kNewClass);
    	end;		{ while }
    END;
    Run(ChangeDimClassName);

     

    HTH,

    Raymond

     

  2. @bsalee, Could you please explain in a little more detail what you want to happen?

     

    Are you referring to this setting in the Document Preferences, as the dimension class name you want to assign?

    677273251_DocPrefDimClass.jpg.e0325d33890a0eac4039e6ebc01477e4.jpg

     

    Or, are you wanting to assign another class to dimensions that you click on?

     

    Or, do you want to toggle that Document Preference ON and OFF? 

     

    It is possible to set it up as either a TOOL, or a SCRIPT, but there are some nuances in the way each functions. More detail will help. If you could clarify your request a bit, I or someone else might be able to help. 

     

    Thank you,

    Raymond

  3. 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.

     

    1665175958_DocPrefs.png.7a3aa288e0fbee93a16cd00e5b9142b2.png

     

    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

    • Like 1
  4. @Jiajing,

       I can confirm that @Pat Stanford is correct, in that the options for all of the FEOIL commands can be added together to give you combined attributes. In this case your Layer Options = 3 does in fact mean All Layers AND Visible Layers, which reduces to All Layers. Often, I'll use 3 in the Object Options to get me Visible AND Selected objects.

     

       It is possible to make ForEachObjectInLayer() act like FSActLayer if you return True from your "todo" function. When True is returned, processing stops. Returning nothing defaults to False, and all objects within the scope of the command get processed.

     

       Here's a variation of your script that shows all of the pertinent information in one Alert Dialog, including the object type number. I would recommend changing the last option to a 4, to only work on Editable layers. This avoids grabbing objects on Gray or Hidden layers.

    import vs
    CR = chr(13)	# Carriage Return char
    
    def todo(h):
    	p = vs.GetBBox(h)
    	vs.AlrtDialog('BBox for Obj Type: ', vs.GetTypeN(h), CR, 'TL: ', p[0][0], ',  ', p[0][1], CR, 'BR: ', p[1][0], ',  ', p[1][1])
    	return True
    	
    vs.ForEachObjectInLayer(todo,2,0,3) # Selected, Shallow, All & Visible layers

     

       And here's a simpler version of the same script, using vs.FSActLayer() (as Pat recommended.) This style of script is primarily used when you are working only on the Active Layer.

    import vs
    CR = chr(13)	# Carriage Return char
    
    h = vs.FSActLayer()
    p = vs.GetBBox(h)
    vs.AlrtDialog('BBox for Obj Type: ', vs.GetTypeN(h), CR, 'TL: ', p[0][0], ',  ', p[0][1], CR, 'BR: ', p[1][0], ',  ', p[1][1])

     

    Note: I always place a comment after the FEOIL commands to spell out the numeric meanings of the options. Unless your memory is perfect, this will save you tons of time in the future when you revisit your scripts so you don't have to relook up the command to find out what the numbers mean — again.

     

    HTH,

    Raymond

    • Like 1
  5. 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 

    • Like 2
  6. Hi Sam,

       You have the 1st five correct.

     

    Short is an integer, so use Get/SetObjectVariableInt.

    Sint32 is a Longint, so use Get/SetObjectVariableLongInt.

    The "RefNumber" shown above are type Sint32 (Longint) - see previous line.

    I'm guess on the "void write" entries, but judging from their ovNames, they may be BOOLEAN, but you can only write to then, and not read them. 

    Not sure how to read or write a transform matrix from VS.

    • Like 1
  7. Oh, Pat, you are crazy ...rational AND crazy... but you know what they say, it takes one to know one. 😉 

     

    Here ya' go. Here's my Secret Sauce recipe. Cut and Paste to your heart's delight.

     

    Procedure ListHiddenRecordFormats;
    CONST	CR = chr(13);
    VAR	S1 :DynArray of Char;
    
    	Procedure HiddenRecordNames(var S1 :Dynarray of Char);
    	{ Append the names of all Hidden Records to text block S1. }
    	{ 25 Mar 2023 - Raymond J Mullin }
    	Const
    		RecordType = 47;
    		DummyRec = 'DummyRec';
    		DummyFld = 'DummyFld';
    	Var
    		hndDummyRec, RecHnd :Handle;
    	Begin
    		NewField(DummyRec, DummyFld, '1', 3, 0);		{ create dummy record }
    		hndDummyRec := GetObject(DummyRec);			{ get handle to new record }
    		SetObjectVariableBoolean(hndDummyRec, 900, False);	{ hide it }
    		RecHnd := NextObj(hndDummyRec);				{ get handle to next object on list }
    		DelObject(hndDummyRec);					{ not needed any more }
    		while (RecHnd <> nil) do begin				{ traverse the Hidden Record list }
    			if (GetType(RecHnd) = RecordType) then
    				S1 := concat(S1, GetName(RecHnd), CR);
    			RecHnd := NextObj(RecHnd);			{ Next Object on list }
    		end;		{ while }
    	End;		{ HiddenRecordNames }
    
    BEGIN
    	S1:='The file contains the following hidden record formats:';
    	S1:=Concat(S1, CR, CR);
    
    	HiddenRecordNames(S1);		{ append Hidden Record Names to text block }
    	
    	S1:=Concat(S1,'*****');	
    	AlrtDialog(S1);
    END;
    Run(ListHiddenRecordFormats);

     

    Raymond

    • Like 1
  8. 2 hours ago, Pat Stanford said:

    What am I missing?

    Hey Pat,

       Hmmmmm, the secret sauce?

     

       I don't know why BuildResourceList() does not see Hidden Records, but judging from your example, it obviously doesn't. That said, I vaguely remember (meaning some old code I wrote shows) that Hidden Records are kept in a different list from the other records. The only way I can think of right now is to search that other list and use AddResourceToList() to place the Hidden Records into your list.

     

       Are you wanting your Resource List to contain only Hidden Records, All Records, or a mixture (Visible, PIO, Hidden)? I don't have a code sample to cut and paste right now because I wasn't using Resource Lists at the time, but I can mock one up shortly.

     

    Raymond

     

  9. @WhoCanDo,

       I just placed your script into a Menu Command, placed that command in my Custom Menu, and assigned Cmd-Shift-9 to it. It works without the extra overhead of having to click in the drawing. I think that initial click is a built in penalty required when using tools vs. menu commands. You have to click in the drawing for the script to run. If using a hotkey for a menu command instead of a tool does not rail against the tenets of your core beliefs, may I recommend giving it a try to see if it will work for you?

     

    HTH,

    Raymond

  10. SP3 or SP4? I just remembered there was a bug in SP3 where the ALT keys for tools did not work. It seems to be fixed in SP4. If you're still on SP3, I recommend you upgrade to SP4.

     

    I'm using SP4 with OPT-9 set to your New Round Wall tool. When I press OPT-9 it almost sets the tool up, as the name shows in the Tool Bar, but none of the button icons appear. After I click once in the drawing, then the tool's mode buttons appear. When I click the second time I can draw with the New Round Wall tool. 

     

    I'm on a Mac, so the behavior may be different on your PC, but it's still not working the way I expected to. Can you describe in more detail what's happening your end?

     

    Raymond

  11. @WhoCanDo, I just found out the cutoff for the tool numbers is VW 2022 and older use -318 for the Round Wall, while VW 2023 uses -208 for the Wall tool, but the second mode is now the Round Wall tool.

     

    Now my question is, what version of VW are you running? The same command SetToolWithMode() can be used in any version of VW from 2016 onward, but the tool number and the mode buttons you set will change in VW 2023 and beyond, compared to the ones you would use before VW 2023.

     

    If your signature is correct, then you will want to use:

    SetTool(-318);    { Round Wall Tool }

    SetToolWithMode(-318, 1, 1);   { Group 1, Selection 1; ie Left Control Line Mode }

     

    In VW 2023, and presumably newer, use:

    SetToolWithMode(-208, 1, 2);    { Group 1, Selection 2; ie Round Wall Mode }

    SetToolWithMode(-208, 2, 1);    { Group 2, Selection 1; ie Left Control Line Mode }

     

    Raymond

  12. I got them from the VS Func Reference Appendix -> SetTool - CallTool Selectors. I used the HTML version that ships with the software, but it is also online in the Developers Wiki.

     

    Raymond

  13. In older versions of VW use :  SetTool(-318);   { Round Wall }

     

    In newer versions use :  SetToolWithMode(-208, 1, 2);    { Round Wall mode of the Wall Tool }


    I believe you can set other mode buttons of the Wall Tool by changing the middle number to select the button group, and the last number to select the button within that group.

     

    I don't know what VW version is the cutoff version. One of these should work for you.

     

    Raymond

  14. Follow up. I just figured out you don't need the Layer Plane node if you don't use Enable Legacy 2D features (starting VW 2022), or you use Working plane only. If you mix Screen and Working Plane objects in the most recent VW versions, then the Layer Plane node makes sure the line draws on the Layer Plane. If there's an easier way to force Layer Plane drawing, please let me know.

     

    Raymond

     

  15. @Alex Talbot,

       I think @Marissa Farrell's way is the way to go, but if you want to see how to draw a 2D Line on a vertical plane (YZ plane in this case), I cobbled together a few Marionette nodes to draw a Planar 2D Line that runs from the Origin (0, 0, 0) down along the Z_axis. This is not guaranteed to be the smallest node, but it works. Suggestions for improvement are welcome.

     

        You can change the Line's length by editing the Y_value of the 2D point (pEnd) on the Create Line node. You can also change the Start Point by adding a 3D Point to the vOffset input of the Set Entity Matrix node and giving it any 3D XYZ value.

     

       NOTE: All unassigned input nodes use the value (0, 0) or (0, 0, 0). The attached VW file is v2018, so more people can read it.

     

    1155904616_2DLineon3DPlane.png.be49ea6fed5f90a73fe447e0c7d4d394.png

     

    Vectorworks file:  2D Line on 3D Plane v2018.vwx

     

    Raymond

  16. @Jiajing,

       To get a handle to objects inside a Symbol Instance, you have to take a more circuitous route. First, symbol instances are not container objects. The real container is the Symbol Definition. To get a handle to a Symbol Definition when you start with a handle to a Symbol Instance try this:

     

    # return a handle to the first object inside a symbol definition where H points to a symbol instance
    if (vs.GetTypeN(H) == 15):
    	SymDefName = vs.GetSymName(H)
    	SDefHnd = vs.GetObject(SymDefName)
    	InsideH = vs.FIn3D(SDefHnd)
    	
    
    vs.Message(InsideH, '  ', vs.GetTypeN(InsideH))

     

    or you can express it in one line:

     

    # return a handle to the first object inside a symbol definition where H points to a symbol instance
    InsideH = vs.FIn3D(vs.GetObject(vs.GetSymName(H)))

    Raymond

  17. 1 hour ago, Pat Stanford said:

    I think you mixed up threads Raymond.  This was the select similar fixtures not the split text thread.

     

    Yep, too many stars in the left hand column, and they keep changing positions. I obviously clicked on the wrong thread. I'll correct the previous script in a moment.

     

    Thanks, Pat.

     

    Raymond

     

    PS - My second script posted above is now corrected to reflect the topic in this thread.

×
×
  • Create New...