Jump to content

michaelk

Moderator
  • Posts

    6,389
  • Joined

  • Last visited

Posts posted by michaelk

  1. The kobj… lines are constant definitions.  Later on in the code the coder will want to use the integer value for OnWigetPrep and rather than look it up or remember a hundred of these numbers they are defined at the beginning of the code in the CONSTANT section. 

     

    The functions that require those values are used when the plug-in object is "event aware".  Event aware plug-ins can do things like have Styles that are recalled from a stored symbol in the resource manager.

     

    They don't show up in the reference because they aren't functions.  They are a common practice.  Not part of the language.  It's entirely possible that we are all copying that from @Julian Carr and @JBenghiat.

     

    Don't worry about that for a while.  

     

    You will have a few years of joyfully improving your productivity by making useful tools and menu commands before it seems like a good idea to subject yourself to that torment.  Maybe by then ChatGPT will be able to write plug-ins for us :-).

    • Love 1
  2. My experiments with ChatGPT and Vectorscript always return VERY verbose code at the very best.  Often ChatGPT hallucinates functions.  And it can't handle plug-in objects very well - if at all.

     

    The good news is you need MUCH less code than you think.  That's the beauty of writing plug-in objects.

     

    It can't handle the plug-in definition at all.  And I'm not sure from your example that you are defining the plug in. 

     

     

    If you want to make a plug-in object that draws a square of parametric values using a point plug in:

    In Vectorworks, go to Tools>Plug-ins,>Plug-in Manager…

    Chose New.  

    Give it a name and select Point Object.

    In the parameters tab do this:

    image.thumb.png.83d5334fe032fa34c5b8a140ed73f59b.png

    The name in the Name column is what you use in the script (with a p prefix).  The Alternate Name is what appears in the OIP and in a worksheet.

     

    Believe it or not, this is the entire script you will need:

     

    PROCEDURE ParametricRectangle;
    
    BEGIN
    	RectangleN(	0,0,
    			1,0,
    			pRectWidth,pRectHeight);
    END;
    
    RUN(ParametricRectangle);

     

     

    pRectWidth and pRectHeight will be the values in the OIP for Rectangle Width and Rectangle Height!  Changing the values in the OIP (or in a worksheet) will change the size of the rectangle.

     

    RectangleN is a standard way of drawing a rectangle.  The first two numbers are the starting point.  With plug in objects the insertion point of the object is 0,0.  The next two numbers define the direction of the base of the width of the rectangle.  1,0 means it goes to the right and not up or down.  -1,0 goes to the left.  1,1 goes at a 45º angle up and to the right.  The actual values don't matter.  Just if they are negative, zero, or positive.  The last numbers are the opposite corner of the rectangle.

     

    You don't have to write them as 3 lines.  I just find that easier to read.

     

     

     

    If you want to make a plug-in object that draws a square with handles at the corners:

    In Vectorworks, go to Tools>Plug-ins,>Plug-in Manager…

    Chose New.  

    Give it a name and select Rectangle Object.

    For a Rectangle Plug-in Object it will automatically add the width and height parameters!

    So, without even lifting a finger the parameters will look like this:

    image.thumb.png.eff2ae73fc8d8bd7f800c364213b7e19.png

    The script will be something like this (I added diagonal lines just to give it something to do :-):

    PROCEDURE RectRect;
    
    BEGIN
    
    	RectangleN(
    		0,(0-(pBoxWidth/2)),
    		1,0,
    		pLineLength,pBoxWidth);
    
    	MoveTo(0,-pBoxWidth/2);
    	LineTo(pLineLength,pBoxWidth/2);
    
    	MoveTo(0,pBoxWidth/2);
    	LineTo(pLineLength,-pBoxWidth/2);
    
    END;
    
    RUN(RectRect);

     

    With this plug-in you can either drag the handles of the rectangle or type in values in the OIP.

     

    Note that this plug-in will have two insertion modes.  The second one is the one that makes sense.  But I don't know any way to make that the default  :-).

     

    In the second insertion mode the linelength is the first line you draw and the boxwidth is what a human would think of as the height.

     

    For reasons someone may soon tell us, but unknown to me for many years, the boxwidth (height) is measured from the middle of the rectangle.  So you have to do the division by 2 business.

     

    I'll attach these two plug-in objects so you can take them apart and see how they work.  Let me know if you need help installing them.

     

    Post back with any questions.

     

    Welcome to a lifetime of madness.

     

     

     

    EDIT:  Should have mention in directions above.  After you create the plug-in object you still need to add it to a workspace so it will show up in a tool palette or menu.

     

     

    Rect Rect Example.vso Rect Point Example.vso

    • Like 3
    • Love 1
  3. That's not what I'm seeing in 2024.  When the Move By Points tool is active and the first mode is either Move and Duplicate Mode or Distribute Mode, then hitting the P key will highlight the current entry in the Number of Duplicates field so that typing any number will replace the current entry.

    • Like 1
  4. Yes.  The criteria is LOCATION.  When you use Location the choices are "is within" and "is not within" and then you will see a list of possibilities.

     

    By default the space objects will have a UUID # that is I think 16 hexadecimals inside curly brackets.  If you click on a space object that same UUID will be in the Name field at the very very bottom of the OIP.  You can change that to something more human readable and that new name will appear in the criteria list.

     

    If you want to go the other way and your space objects have names in the Space Name field, then you can use the call =GetSpaceNameforObj in the database header row and it will return the room name for all the spaces that object is contained within, separated by a comma.

    • Like 3
  5. 16 minutes ago, Pat Stanford said:

    I believe that the original MiniCAD code was all written in Pascal and only much later converted to C.

     

    It was.  I met Richard Diehl once and he told me about writing the original MiniCad in a version of Pascal (Turbo Pascal??) that would compile on his (I think…) Mac 512.

    • Like 1
    1. VW>Preferences>User Folders>Reveal in Finder
    2. Find the Plug-ins folder.  Put the .vsm file in that folder.  (I find it very useful to make the user folder a favorites in Finder)
    3. Restart VW.
    4. Tools>Workspace>Edit Current Workspace  (or choose Workspaces… and create a new workspace based on a copy of the current one)
    5. in the Workspace Editor > Menus Tab
    6. On the left will be groups of menu commands.  Jesse's are usually in a group called JNC. Find the menu command you want
    7. On the right are a list of all the menu commands in that workspace in VW.  Open up the target menu group and
    8. Drag the new menu command on the left to the desired location on the right.
    9. Hit OK.

     

    As a bonus, you could just grab the JNC heading on the left and drag it to the right.  You will now have a JNC menu.  I'm currently using 9 JNC menu commands!

     

    • Like 1
  6. 2 hours ago, Marc Davies said:

    Francisco. Sorry no immediate answer for you. However, my experimenting with chatGPT means you can get it to write most of a Vectorworks script for you to do what you want.

     

    Be very careful w/ chatGPT writing VS.  I have tried it and found that chatGPT often hallucinates functions that don't exist.  If you want it to do something super simple - like draw a rectangle of a given size - it can do it, but often in a bizarre, verbose way.  

     

    I'm sure it will get better in a year or two and we will all be writing fabulous scripts 🙂.

    • Like 1
  7. You might find this helpful.  

     

    I made a couple scripts when 3D Web views first came out to open all the doors in a drawing so the client wouldn't have to crash through closed doors.  One opens all the doors that have "On Schedule" checked.  The other one returns them to their original state.  It uses User Field 9 and 10 to store the original state of the door.

     

    I'll attach a file with the scripts and a couple doors to swing open and closed.

     

    Here is the script to open the doors in 3D:

    PROCEDURE OpenTheDoor;
    
    {14 April 2017}
    {Badly scripted by Michael Klaers}
    
    {This script preps the doors in a drawing to be ready to 'Export Web View'
    It preserves the 3D Open boolean and the open angle of each door in User Field 9 and 10
    and then sets the 3DOpen to TRUE and the Open Angle to 90°}
    
    {There is a companion script that restores the doors to their original state}
    
    VAR
    	
    	ShouldILeaveThisOpen	: STRING;
    	OriginalOpenAngle  		: STRING;	
    	
    {------------------------------------------------------------Record & Open Procedure}	
    	
    PROCEDURE RecordAndOpen(h : HANDLE);
    	BEGIN
    
    
    		ShouldILeaveThisOpen := GetRField(h,'Door','3DOpen');
    		OriginalOpenAngle := GetRField(h,'Door','OpenAngle');
    		SetRField(h,'Door','UserFld9',OriginalOpenAngle);	
    		SetRField(h,'Door','UserFld10',ShouldILeaveThisOpen);
    		SetRField(h,'Door','OpenAngle','90');
    		SetRField(h,'Door','3DOpen','TRUE');
    		ResetObject(h);
    
    	END;
    
    {-----------------------------------------------------------------------Main Program}	
    
    BEGIN
    
    ForEachObject(RecordAndOpen,(((R IN ['Door']) & ('Door'.'OnSched'=TRUE))));
    
    END;
    
    
    RUN(OpenTheDoor);

    Change the number in SetRField(h,'Door','OpenAngle','______'); to be whatever angle you want.

     

     

     

    This is the script to restore the doors to closed:

    PROCEDURE CloseTheDangDoor;
    
    {14 April 2017}
    {Badly scripted by Michael Klaers}
    
    {This script restores the doors in a drawing after 'Export Web View'
    It recalls the 3D Open boolean and the open angle of each door from User Field 9 and 10
    and then restores the 3DOpen Boolean and the Open Angle to their original values}
    
    {There is a companion script that records original state of the doors.  Run that one first.}
    
    VAR
    	OriginalOpenAngle  		: STRING;	
    	ShouldILeaveThisOpen	: STRING;
    
    
    {------------------------------------------------------------Read & Restore Procedure}	
    
    PROCEDURE WereYouBornInABarn(h : HANDLE);
    
    	BEGIN
    
    		OriginalOpenAngle := GetRField(h,'Door','UserFld9');	
    		ShouldILeaveThisOpen := GetRField(h,'Door','UserFld10');
    		SetRField(h,'Door','OpenAngle',OriginalOpenAngle);
    		SetRField(h,'Door','3DOpen',ShouldILeaveThisOpen);
    		ResetObject(h);
    	
    	END;
    
    {----------------------------------------------------------------------Main Program}	
    
    BEGIN
    
    ForEachObject(WereYouBornInABarn,(((R IN ['Door']) & ('Door'.'OnSched'=TRUE))));
    
    END;
    
    
    RUN(CloseTheDangDoor);

     

     

    Much faster than doing it manually 🙂 

    Open the Doors.vwx

    • Like 3
×
×
  • Create New...