Jump to content

Help with executing the tool command


Recommended Posts

Hello everybody, I have created a tool command and call it up via an icon button. I have the problem that I first have to click in the drawing area before I can work with the actual command. What did I do wrong?

 

Choose_Standard='Freudig_2'
c= 'Bemaßung'
tsize=10

import vs;
def CustTool():
    Result = vs.SetDefaultBeginningMarker(0, 15, 0.118103, 0.000000, 34, 0.050000, False); 
    Result = vs.SetDefaultEndMarker(0, 15, 0.118103, 0.000000, 34, 0.050000, False);
    vs.PenSize(14);
    vs.PenBack(256);
    vs.PenFore(1271);
    Name = '';
    if vs.Name2Index(Name) > 0:
        vs.PenPatN(-vs.Name2Index(Name));

CustTool();

Dim_Std = {} #Dictionary of  Name and Index Number
i=0;v=''

while v !=1:
    try:
        vs.SetDimStd(i)
    except:
        pass
    vs.LinearDim((0,0), (0,0), 0, 0, 0, 0, 0)
    h=vs.LNewObj()
    v=vs.GetObjectVariableInt(h,0) #if 1 the function switched to 1 because of an error
    n=vs.GetObjectVariableString(h,27)
    vs.DelObject(h)
    i=i-1
    if v !=1:
        Dim_Std[n] = v

vs.NameClass(c);
vs.SetDimStd (Dim_Std.get(Choose_Standard));
vs.SetPref(44,True);
vs.SetTool(-211);
vs.TextSize(tsize)
 

Link to comment

Your script calls SetTool(), so when you click in the drawing, then the script runs and sets the tool. The second click is the first click of the actual tool.

 

Your options are either to run your command from a menu or tool palette, or rely on GetPt() etc and create the dimension via code rather than with it's tool. This is a limitation of VS-based tools.

Link to comment

 

Thanks for the brief analysis of my script, now I understand the matter a little better. I apologize for my questions, but I'm new to scripting and want to learn how to do it. So it would be better to program things properly right from the start. Can I solve this more easily with Python? What would such a program look like?

Link to comment

No apologies necessary.

 

Vectorscript and Python are going to be the same in terms of functionality, though if you are new to scripting, using Python has the advantage of being a modern language with a lot of learning resources of anything outside the Vectorworks API, as opposed to Vectorcript, which is a proprietary version of PASCAL. Both, however, are run-time languages, so they depend on a singular trigger to run, in this case, clicking in the drawing.

 

The solution depends on what you are trying to make easier and who your audience is. If these are just to automate your workflow, just move your code form a tool to a menu, and you're basically done.

 

If you want something a little more user-oriented, you have to build your own tool. Your end result might be to run this command:

https://developer.vectorworks.net/index.php/VS:LinearDim

You can gather the end points with this:

https://developer.vectorworks.net/index.php/VS:GetLine

or this:

https://developer.vectorworks.net/index.php/VS:GetPtL

Find an example of collecting points in Python here: https://developer.vectorworks.net/index.php/VS:GetPt

If you also want to set the distance from the object, you need to get a third point.

 

You can associate objects with a dimension with this command: https://developer.vectorworks.net/index.php/VS:AssociateLinearDimension

 

I can't recall if the tools will count the first click as the first point. You may need to use a TempTool to retrieve the first click:

https://developer.vectorworks.net/index.php/VS:RunTempTool

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