Jump to content
Developer Wiki and Function Reference Links Read more... ×
Sign in to follow this  
GioPet

Copy/Paste Objects and Reassign Incoming Classes to Existing Classes

Recommended Posts

Hi Everyone.

In the office where i work, we have experienced a big disruption in the workflow of big projects/drawings, caused by the AUTOMATIC of CLASSES (most of the time undesired) when using COPY/PASTE.

I thought this could interest many people so I have started working on a script to implement the functionality of the PASTE COMMAND.

The script develpod so far executes the command PASTE and prompts a Dialog Window that allows to Assign ONE of the incoming classes to one of the existing, then deletes it.

Here is a Link to the FIRST VERSIOn of the script.

I was trying to create a loop that would prompt the Dialog Window until ALL the incoming classes have been assigned to existing classes.. though I am experiencing some problems with the RE-Allocation of DYNARRAY of STRINGS.. (I imagine there's a first time for everyone..)

I am posting the script as it is so far, in case anyone can feed in some help and suggestions

You can find the Script here:

http://pastebin.com/m7f8d4982

NOTE THAT THE SCRIPT WORKS FINE UNTIL THE FINAL LOOP AT LINE 228.

TO TEST THE DIALOG WITHOUT LOOP, DELETE LINES 228, 235 until 244

Edited by Gio Pet

Share this post


Link to post

Hello G,

I reworked it a bit and it's working. While I didn't examine the entire script, I simplified parts of it. Part of the simplifying was to not use a popup for the class to reassign. At this point, the script requires the user to reassign all of the new classes anyway, so now they just have to do them in order. So the dialog now shows the new (offending) class as static text. This makes it easy to simply cycle through the new classes without dealing with reallocating the array. There were a couple of other fixes. If you have a text editor that can compare this with yours, you'll see what was changed.

http://pastebin.com/m4e746acd

HTH,

Share this post


Link to post
Guest benrudgers

I did not get deep into the code and I don't know much Vectorscript but...

It looks like REALLOCATE_ARRAY tries to allocate ExtraClassNames from (1..-1) via the variable "diff" at lines 198-203.

Share this post


Link to post

Yay!Thanks a lot guys!

Mat, that's great, a much easier way to work it out!

..indeed, there was also the mistake that Ben pointed at..

I will implement the Dialog Window to give the possibility of eventually add a new incoming class. I still think it would be good to preview in window all the incoming classes..

I will keep posted further improvements!

THanks again for the great help!

G

Share this post


Link to post
Guest benrudgers

If you are a glutton for punishment, a list browser which allows the user to select the status of "non-standard" classes would be the way to go. see Orso's three part write up:

http://www.vectorlab.info/index.php?title=Category:VectorScript

You could even add an administrative tool which allowed deletion, addition, and other manipulation to the list of standard classes.

BTW, I'm not sure why you are reallocating the array without a test to see if it is at capacity. See http://www.vectorlab.info/index.php?title=VectorScript_Performance

Edited by benrudgers

Share this post


Link to post

My pleasure to help!

Another issue I found was that it appeared you were erroneously changing the NewcountClasses, countClasses in the dialog handler. In your original script, changing:

GetSelChoice(4, 0, NewcountClasses, NewClass);

GetSelChoice(6, 0, countClasses, OldClass);

to this (the "i" variable being a dummy variable):

GetSelChoice(4, 0, i, NewClass);

GetSelChoice(6, 0, i, OldClass);

should fix some things.

Ben, you're correct. a list browser would be ideal (and a lot of work) for this. I think two listboxes could suffice. A left listbox would be the classes to reassign (allowing only single item selection) and the right listbox would show the existing document classes (allowing multiple item selection). When a new class is selected on the left, the ones to reassign could be highlighted on the right. This could allow multiple classes to be reassigned to one class, and would also allow all reassignments to be done in one dialog. Also, the reassignments could be saved/updated so that the next time those new classes are present the dialog will default to reassigning them to match the previous setting. So G, will we have this by the end of the week? :-P

Share this post


Link to post

yep yep,

Mat you just described exactly what i was thinking of doing..

Ben, thanks for the great links..

go for List Browser punishment!

would be nice to get this done by the end of the week, i'll do my best, but we always have to deal with several things at the same time... so i can't promise!

Will Keep you posted anyway!!

Edited by Gio Pet

Share this post


Link to post
Guest benrudgers

Maybe the list browser will take a bit too much time.

But I would recommend having the option to generate the list of "existing classes" from a fixed source such as a text file or worksheet rather than the existing drawing if your goal is standardization of classes.

There should be a "standards enforcement mode" not just a "don't add more junk mode."

Edited by benrudgers

Share this post


Link to post

..yeh, it will probably take me quite a while to get the LIst Browser working..

Though it would be really the most efficient way of handling the 'Smart Paste'.

i will think about a way to tackle this in a couple of steps, to come up with 1 or 2 working scripts before I manage to get the one that is spot on.

well, let's see, in the end it comes down to an issue of time.. so I am trying to equip myself with a good amount of patience.

Share this post


Link to post

Cheers for sharing this, I always learn from reading structures of others scripts...

I thought I had read that it was not best practice to set VAR for each sub procedure. Yet in this script all the subs seem to repeat the same VAR w,x,y as Integers.

Is there a reason why you do it this way?.

Pastebin is new to me, how did you get it to auto colour the text?.

Share this post


Link to post

Hi Justin,

I am also learning a lot from other scripts and suggestions.

..and thanks for the observation, I didn't know it was best not to set VAR for each sub.

I have been writing those sub procedures individually, and that's why the same VAR are re-called all the time.

I will revise a ''clean' version later.

BY the way,

Does someone have any idea about how to resolve the behaviour of the script when Copy/pasting TEXT inside a textfield??

G

Edited by Gio Pet

Share this post


Link to post

Yikes! Good question.

As far as I know, there's no way to deal with pasting inside a text field, text block or worksheet. If any ideas come to mind, I'll let you know.

Share this post


Link to post
I thought I had read that it was not best practice to set VAR for each sub procedure.

???It is neither good, nor bad. Using VARs in each procedure keeps them local to that procedure. Declaring VARs once at the top of your program makes them global to all procedures.

???If you are only using a value within a procedure, then it is neater to make it a local variable, even if it has the same variable name in several procedures. If several procedures need to access the current value, then you can make it a global value, but bear in mind if one procedure changes the value another procedure cannot get the old value back.

???Another way to share values is to pass the variables into and out of a procedure using a parameter list. This is the best way to make your code readable to other users and to yourself later, as when you revisit it several years down the road.

???If your script is small, then it probably doesn't matter how you get it to work, but as it grows to the point where it spans several pages, then using a well structured approach pays off in spades.

Raymond

Share this post


Link to post

Yes. Raymond has a good point. I use the same var names in many subprocedures. It makes understanding and working with them much easier. What I typically do is prefix a lowercase "g" to all of my global vars to help differentiate them from local vars in subprocedures. And, as Raymond states, passing vars to procedures own parameter list makes things much cleaner.

Share this post


Link to post

Thank you for a clear explanation.

I agree including VAR for each sub makes the script much clearer.

I have some large scripts with way to many global VAR declared.

Share this post


Link to post

The Vectorscript compiler is smart enough (for the tasks it has to do) to separate our local versus global scope variable names.

The question is are you smart enough (for the tasks you have to do) to keep them straight?

Personally, I am not. If it is a one off script I will use different names for everything. But I also tend to write very short (1 or 2 pages at most) scripts. But I usually don't use descriptive variable names either. I usually start the H1 for Handles, N1 for Integers, L1 for Longs, B1 for Boolean, S1 for Strings and R1 for reals and then work up from there. I got bit a long time ago trying to us L as a variable name and the compiler interpreting it as a criteria. So now everything is either long or has a number.

Share this post


Link to post

I use long names always.

Early scripts used short hand, a nightmare to return to a year latter.

I used to have trouble with spelling and syntax errors in my long names until I started using BBEdit. BBEdit has predictive word where it will prompt the spelling of a variable already included in a document.

Share this post


Link to post

Hello Everyone!

I had some time to carry on the Smart Paste Script. Here is a snapshot of the Dialog as it looks like now.

[img:center]http://techboard.nemetschek.net/ubbthreads/ubbthreads.php?ubb=download&Number=3640&filename=Smart%20Paste.png[/img]

At this stage i have to define what the ASSIGN, PASTE IN, and UNDO buttons actually do inside the script..

I was thinking of proceeding this way:

When the User assigns one or more classes to one of the exisiting, the ASSIGN, PASTE IN and UNDO Buttons record the user's selection and update the information in the List Browser accordingly.

Classes are NOT being assigned and deleted at this moment, but the dialog only Records the associations done by the user, which will be processed once OK button is pressed.

with this approach, the Cancel button can easily Quit the whole Smart PAste Procedure, leaving the Drawing unmodified.

How does this idea sound?

You can find the script at

http://pastebin.com/m31e55e0b

(the script is still a bit messy..)

Thanks

G

Edited by Gio Pet

Share this post


Link to post

Looks like it's coming along well! The link to the script doesn't work though...

The behaviors of the buttons sound fine. I'm assuming when you highlight an item in the existing class list, all incoming classes assigned to it will be highlighted and the user can select/deselect from them. Conversely, if an incoming class is selected, then the existing class it's assigned to will highlight. The interface might make things a bit cumbersome for the user to tell what he still needs to assign.

Here's another idea that still avoids list browsers:

What about three lists: Existing, Merged, Incoming? The user could select an existing class and only it's assigned classes show in the Merged list. All incoming classes that have not yet been assigned will show in the Incoming list. Classes in the Incoming list can be selected and moved to the Merged list of the select existing class. This three column interface would immediately show the user what classes still need to be assigned and any left in the Incoming list will simply be pasted into the drawing. Also, the existing classes could be clicked through allowing the user to easily see only the classes to be merged into them.

I hope this makes sense. I'm a little under the weather (and blizzard).

Share this post


Link to post

Hi Matt, i hope the weather is getting better over there! (or at least not worse).

I found some difficulties on how to create a record of user's selections, therefore i defined the Assign Button in a way that it immediately processes the changes to the drawing when pressed.(though i might go back to that idea of the selections record)

I uploaded here the .vsm file Uncrypted and the .txt file needed for the Dialog.

(for some reason Vectorworks gives an I/O error when I try to Encrypt the script, saying it cannot include the .txt file..)

I am now trying to go around the problem when Pasting Text inside textfields..

and will start cleaning the whole script and making it more Accessible to others.

looking forward to Feedbacks.

Cheers

G

Edited by Gio Pet

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
Sign in to follow this  

 

7150 Riverwood Drive, Columbia, Maryland 21046, USA   |   Contact Us:   410-290-5114

 

© 2018 Vectorworks, Inc. All Rights Reserved. Vectorworks, Inc. is part of the Nemetschek Group.

×