Jump to content
Developer Wiki and Function Reference Links ×

Need help with a script, for creating symbols from groups


Recommended Posts

PROCEDURE GetFrontCenter(groupHandle : HANDLE; groupCenter : VECTOR);
VAR groupHandle : HANDLE;
VAR groupCenter : VECTOR;
BEGIN
    groupCenter := GetGroupCenter(groupHandle);
END;
PROCEDURE IsTextInGroup(groupHandle : HANDLE) : BOOLEAN;
VAR
    groupObjects : DYNARRAY[] OF HANDLE;
    numObjects, i : INTEGER;
BEGIN
    groupObjects := GetGroupObjects(groupHandle);
    numObjects := GetArrayCount(groupObjects);
    IsTextInGroup := FALSE;
    FOR i := 1 TO numObjects DO
    BEGIN
        IF GetType(groupObjects[i]) = 9 THEN
        BEGIN
            IsTextInGroup := TRUE;
            EXIT;
        END;
    END;
END;
PROCEDURE CreateTextSymbolFromSelectedGroups(groupNamePrefix : STRING);
VAR
    h : HANDLE;
    numSelected, i : INTEGER;
    groupName : STRING;
    groupCenter : VECTOR;
BEGIN
    numSelected := NumSelectedObjects;
    FOR i := 1 TO numSelected DO
    BEGIN
        h := FSActLayer;
        FOR i := 1 TO numSelected DO
        BEGIN
            h := NextObj(h);
            groupName := GetName(h);
            IF (Pos(groupNamePrefix, groupName) = 1) AND IsTextInGroup(h) THEN
            BEGIN
                GetFrontCenter(h, groupCenter);
                CreateSymbol(h, groupName, groupCenter);
            END;
        END;
    END;
END;
 

 

I am trying to create a script that will use the currently selected groups, each group will have a 2d and 3d item in each group and a piece of text and I need each item to go into the relevant 2d part and 3d part of the symbol (so the 2d goes into top/plan and the 3d goes into the 3d in the symbol). The text inside each group should be used for the symbol name and be shown in the 2D. Is it possible to do this? I understand some things about scripting but not much about the way vectorscripting works. is this possible, I have shown a quick stab in the dark go at trying to create a script but I know that I have made mistakes in this. Any help would be greatly appreciated because we use this every single day on thousands of symbols, currency manually creating them. Thank you, Sim

Link to comment

Can you post a small sample file with one of your Groups and information about what objects should be in the Top/Plan view and which should be in the 3D view. It will make it much easier to help you.

 

And did you use ChatGPT or similar to write the script? Because most of the functions you have used don't exist in Vectorscript.

  • Like 1
Link to comment

Hi Pat, thanks for getting back to me, that is from chatGPT, I started writing my own script but then I couldn't get it to work, so I put it into chatgpt to see if it could help me fix, I stupidly deleted the conversation in chatgpt once I knew that it wasn't doing what I wanted but forgot to copy my code back from it, I should have probably just come on here instead. I understand about constants and variables, while and for loops but putting the basics together and into practice is a little more difficult. Is there any useful ways to start working with vectorscript?

 

Attached is the extract of a few groups and a already manually completed symbol. I hope I made sense in what I am trying to ask for and any help would be greatly appreciated.

 

Thank you, 

Sim

test file.vwx

Link to comment

Hello @TSG-Sim,

   I took a stab at doing what you described in your post. I opened your file and added a script (Groups to Symbols) that converts your groups to symbols. After the conversion, it places the new symbols at the same locations as the original groups.

 

   One thing I noted is that your chair CP101, which is already a symbol, has the 2D and 3D parts overlapping, while the groups to be converted have the 2D and 3D parts separated by 1m. This script does not move the 2D/3D pieces together. That is doable but would require a bit more code.

 

   Check out the script and see if this does what you want, then write back – BUT PLEASE – check it out on a copy of your data first.

 

Grp2Sym test file.vwx

 

 

HTH,

Raymond

 

  • Like 1
Link to comment

thank you I appreciate it a lot you creating that so quickly it helps considerably  @MullinRJ , I am going to have to make some time to get my head around scripting in Vectorworks because it would save a lot of time for some of our repetitive tasks. viewport creation and symbol creation are two of the longest tasks that are the most repetitive in our work.

 

With regards to the items I don't need to move the items together I would do that when creating them they would be normally together, the 1m from top to bottom gap was me just showing it like that so it was easier to see the 2d item and 3d item for scripting it.

 

If I wanted the insertion point for each symbol to be always at the front centre of the chair so 0,0 would always be front centre of the chair, created from each group and never be any different, how would I change the code you provided for that. I am guessing that would be part of the hMove or is it when it is defining the hCenter?

 

truly thank you I owe you a drink 🙂

  • Like 1
Link to comment

Hello @TSG-Sim,

 

6 hours ago, TSG-Sim said:

With regards to the items I don't need to move the items together I would do that when creating them they would be normally together, the 1m from top to bottom gap was me just showing it like that so it was easier to see the 2d item and 3d item for scripting it.

 

I was hoping that was the case. It would not be pretty trying to put them together if the separation was arbitrary.

 

 

6 hours ago, TSG-Sim said:

If I wanted the insertion point for each symbol to be always at the front centre of the chair so 0,0 would always be front centre of the chair, created from each group and never be any different, how would I change the code you provided for that?

 

Now you're getting picky. 😉    The true answer to your question is "with a good bit more code, and lots of trial and error." I had 99% of the script written and still spent several hours figuring how to move the 2D and 3D parts in unison. It seems easier than it really is. Still, patience prevails, or maybe it's pig-headedness.

 

OK, the script in this file is a bit more complicated, as it uses many 3D commands to manipulate both the view, and the objects, to get what you asked for. I commented somewhat heavily, but it may still seem cryptic. Please don't hesitate to ask what's going on.

 

Grp2Sym test file 2.vwx

 

 

Raymond

 

PS - One of the oddities I ran into with this file is the User Origin is shifted away from (0, 0). This typically makes simple tasks much harder. If you are going to try improving your scripting skills, may I suggest you start with an unmoved User Origin. After you get comfortable in the VectorScript or Python languages, then you can see how moving the User Origin affects your code. Hint – some commands understand the shift and others don't, and it's not documented anywhere, which makes some people run for the hills. As always, use this Forum often. The help is excellent.

 

  • Like 1
Link to comment

Raymond you are a legend, thank you, I tested that and that works perfectly for what we need, I definitely owe you a drink for sorting that. I did not know that the user origin was shifted away from 0,0 on that file so the template at some point must have been moved and I have not checked the origin since then. I will make sure my templates are an unmoved user origins going forward, I thought I had used the base metric template from Vectorworks as my starter for all my templates and just put things like title blocks and things like that in so at some point it must have been changed, when I get home tonight I will look through the whole script because it will be helpful to me learning that as well. I didn't even realise functions were the same, I thought you had to use procedures so that is very useful information throughout your code for both learning scripting and doing the work we need. you just saved me a lot of time doing symbols. Thank you,

Link to comment

Hello @TSG-Sim,

   You are quite welcome. The script I wrote doesn't care about a moved origin, so you can use it either way. When you start digging into scripting, it is best if you start with an unmoved origin. Later you can move it, but proceed with caution. Most seasoned scripters avoid making things harder than they need to be. Call it lazy, or wise. Take your pick.

 

   Though I can't tell how your origin was moved, it might have happened during a DXF/DWG Import. I believe some options will move the origin and some won't. You might look to see if that caused your shift. Or as you suggest, it may have already been in your template. There are many ways to move it, but no perfect way to isolate how it moved after the fact. If you find it, great. If not, just be aware.

 

Raymond

 

   

  • Like 1
Link to comment

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...