Jump to content
markdd

Next Object in Selection

Recommended Posts

Is there a script available that would would move to the next or last object in a selection. I would like to be able to enter some known position data to a selection of over 200 identical symbols and constantly moving my mouse cursor to the arrows in the OIP is not particularly productive. If I could map a script to a keyboard shortcut then that would be great.

 

I know little about scripting but have the time to learn at the moment, so I'm not necessarily asking someone to write a script for me but maybe point me to the best place to start. This seems like it might be a simple enough script to start with!

Share this post


Link to post

Go to developer.vectorworks.net for documentation of the API. 

 

You probably want to look at the ForEachObject... routines, which can iterate over selected objects. 

 

FYI, a handle is a unique address for an object that you can use to gain access to a ccess to it. Vectorworks assigns handles per session, so your script always needs to retrieve an object’s handle in order to start manipulating the object. For example, vs.FSActLayer() returns a handle to the first selected object in the active layer. 

Share this post


Link to post

Thanks. I'll get back with questions!

Share this post


Link to post

I think you should:

0: move your objects to an empty layer and  Deselect all.

1: Run your first script: setselect(factlayer);

2: Do your thing

3: Run the second script: setselect(nextobj(fsactlayer)); setdselect(fsactlayer);

4: Do your thing

5: repeat steps 3 and 4 until you reach the last object.

6: Bring every thing back to the original layer

 

Explanation:

setselect(factlayer); Selects the First Object on the active layer;

setselect(nextobj(fsactlayer));  Selects the next object from the First Selected Object {Don't miss the "S" here}

setdselect(fsactlayer); Deselects the First Selected Object, there for, in the next run, the object that was the next object will now be First Selected Object.

Share this post


Link to post

Gerard. This works well. Thanks.

 

Question: is there not a way to select the first object of the current selection ?

 

Thanks.

 

Mark

Share this post


Link to post

Look at the Document List Handling section of the Function Reference for information on how to move around a selection.

 

--Poorly written basic idea of how VW works--

Internally, VW keeps a number of "Lists" of objects that can be accessed using the commands documented in the Document List Handling section of the Function Reference. Basically, there is a list of all objects in the file, a list of selected objects plus ways to get lists of what is inside container objects. Once you get the handle to the first object (or last object) in any of the lists, you can use the NextObj/PrevObj and NextSObj/PrevSObj (for only the selected objects) to move up/down the "list". Anything that deletes objects needs to start at the bottom of the list and go up or else the link to the next object will be wrong at some point.

--End poorly written basic idea--

 

So if you only have a few values you need to change you could use a standard dialog box (perhaps PtDialog for 2 real values, or PtDialog3D for 3 real values) and then just step through the selected objects. But the harder part might be trying to determine what object is selected.

 

Could you use a worksheet to accomplish this? If you are changing a bunch of values to be the same, you could copy it once and then select the range to past into and change them all at once.

 

If not here is some sudo code

 

Begin
	H1:=FSActLayer;
	While H1 <> Nil do
		Begin
			R1:=GetRfield(H1,MyRec,MyField1);
			GetBBox(H1,X1,Y1,X2,Y2);
			PtDialog('Enter New Value',Num2StrF(R1),Num2StrF(X1), R2, R3);
			SetBBox(H1,R3,Y1,X2+R3,Y2);
			SetRfield(H1,MyRec,MyField1,R2);

			H1:=NextSObj(H1);
		End;

This should step through each selected object in the active layer and show you a dialog box containing the original values of MyField1 and the X position of the Top Left corner of the bounding box of the object.

Share this post


Link to post

There’s no reason to move objects to their own layer. All the list traversal commands have versions for selected objects: FSActLayer, NextSObj, etc. I think the idea here might be if all you wanted from your script is to have a keyboard shortcut to select the next object. 

 

I also recommend using ForEachObjectInLayer as an easy way to work on a list of objects. If you’re new to scripting, I also recommend using python rather than learning native VectorScript. 

 

A simple handler looks something like this:

 

def DoChange( h ):

     # insert code to modify the object h here

     return False

 

vs.ForEachObjectInList( DoChange, 2, 0, 0 )

 

 

Though looking at your original post, if you’re manually entering data as opposed to entering data via the script, Pat’s suggestion of a worksheet might be the way to go. Alternatively, you can use the four buttons at the top-right of object info to affect each object in the selection individually instead of as a group. You can then step through the selection one at a time. Not quite as convenient as a keyboard shortcut but easier than clicking in the drawing. 

Share this post


Link to post

Thanks Pat and Josh. I don't have much time to look at this now until tomorrow but the idea is to have a whole bunch of the same symbols (about 150-200 at last count) and enter the Y value so that the symbols move in an array up the drawing. Ideally I would do it with a worksheet but unless I am very mistaken, you can't change X,Y,Z values from a worksheet. For the rest of the data I will be using a worksheet for. (It's for creating linesets on a theatrical drawing).

 

Pat: Your script ran into an error I'm afraid. (identifier not declared)

 

Josh: It was the arrows in the OIP that made me think of this as using the arrows is what I would normally do... If there was only a way to map the next/last arrows to a key stroke then that would be the answer....

 

As I said earlier, I will look more closely at the scripts you sent tomorrow. 

 

Many thanks

 

 

Share this post


Link to post

My script was not intended to run. It was purely pseudo code intended to give you an idea of how a script might work. I you need  working example, give us a sample of your symbols and what data you want to change.

Share this post


Link to post
Posted (edited)

I don't think you can traverse through a list of selected objects by script AND change the focus of the OIP to the next object.

I had to have only one object selected, having the others deselected would mean the script would then also slect objects that were not of interest so that is why I had him isolate the problem.

14 hours ago, Pat Stanford said:

Could you use a worksheet to accomplish this? If you are changing a bunch of values to be the same, you could copy it once and then select the range to past into and change them all at once.

 

That would be the right answer if Mark was editing Record fields:

- Menubar: Tools: Report: Create Report...

- have it list object with a certain record

- Add the fields of interest

 

The worksheet also uses the stacking order (unless you sort the columns)

You can not paste directly from the clipboard to multiple cells, unless you first copy the value of one cell.

Unfortunately Mark is editing the Y values and you can't change those through the worksheet.

 

Edited by Gerard Jonker

Share this post


Link to post
15 hours ago, markdd said:

 

Question: is there not a way to select the first object of the current selection ?

 

There is no Super-Selected state. An object is either selected or not.

I don't think you can traverse through a list of selected objects by script AND change the focus of the OIP to the next object.

Share this post


Link to post

BTW You do know there is an Align function, don't you?

Menu Bar: Modify: Align: Align/Distribute.

Or you could perhaps use Menu Bar: Edit: Duplicate Along Path...

Share this post


Link to post
5 minutes ago, Gerard Jonker said:

BTW You do know there is an Align function, don't you?

Menu Bar: Modify: Align: Align/Distribute.

Or you could perhaps use Menu Bar: Edit: Duplicate Along Path...

Thanks Gerard. Yes, I'm aware of those commands. Worksheets also won't give me what I need either as you cannot enter X,Y,Z values. The purpose is to select individual symbols and give each on a separate predefined Y value. It doesn't need to be a symbol though, a 2D locus would be just as good.

 

16 hours ago, markdd said:

If there was only a way to map the next/last arrows to a key stroke then that would be the answer...

That would be the ultimate answer to my wish! However your scripts work well for my purposes. Thanks.

 

I've attached a file so you can see what I mean.

 

Linesets.vwx

Share this post


Link to post

Well, you do know ther’s an existing plug-in that will create almost exactly what you want from a worksheet, right? :)

 

You ultimately probably want one of two things — step through the selected objects and have VW present a dialog where you can enter a y value, or read a series of values and have VW modify or even create the symbols based on the values.  The former is fairly simple.  The latter is definitely possible, but then you are starting to reinvent the wheel...

Share this post


Link to post
Posted (edited)
23 minutes ago, JBenghiat said:

 

Well, you do know ther’s an existing plug-in that will create almost exactly what you want from a worksheet, right? :)

 

Ahh!! Yes. I do!! I downloaded the demo a while back. It’s one of the very few ones of yours that is not necessary for me😱!

It’s very good though! I’ve got all the rest!

 

Edited by markdd

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×